OSDN Git Service

ipicom
[instantos/instantOS.git] / autostart.sh
1 #!/usr/bin/env bash
2
3 ###############################################
4 ## script for instantOS autostart            ##
5 ###############################################
6
7 # run userinstall to determine device properties
8 if ! iconf -i userinstall; then
9         /usr/share/instantutils/userinstall.sh
10 fi
11
12 # architecture detection
13 if [ -z "$1" ]; then
14         if uname -m | grep -q '^arm'; then
15                 export ISRASPI=true
16         fi
17
18         if [ "$(ps aux | grep bash | grep instantautostart | wc -l)" -gt 2 ]; then
19                 echo "already running"
20                 exit
21         fi
22 else
23         echo "forced run"
24 fi
25
26 cd
27 instantdotfiles
28
29 if ! iconf -i rangerplugins; then
30         mkdir instantos
31         echo "installing ranger plugins"
32         mkdir -p ~/.config/ranger/plugins
33         cp -r /usr/share/rangerplugins/* ~/.config/ranger/plugins/
34
35 fi
36
37 # find out if it's a live session
38 if [ -e /usr/share/liveutils ] &>/dev/null; then
39         ISLIVE="True"
40         echo "live session detected"
41 fi
42
43 # fix small graphical glitch on status bar startup
44 NMON=$(iconf names | wc -l)
45 for i in $(eval "echo {1..$NMON}"); do
46         echo "found monitor $i"
47         xdotool key super+comma
48         if iconf -i nobar; then
49                 xdotool key super+b
50         fi
51 done &
52
53 if [ -n "$ISRASPI" ]; then
54         # enable double drawing for moving floating windows
55         # greatly increases smoothness
56         iconf -i highfps 1
57         if ! [ -e ~/.config/instantos/israspi ]; then
58                 echo "marking machine as raspi"
59                 mkdir -p ~/.config/instantos
60                 touch ~/.config/instantos/israspi
61                 # logo does not work on raspi
62                 iconf -i nologo 1
63         fi
64 fi
65
66 if iconf -i islaptop; then
67         export ISLAPTOP="true"
68         echo "laptop detected"
69 else
70         echo "not a laptop"
71 fi
72
73 ipicom
74
75 if ! iconf -i notheming; then
76         instantthemes a
77         xrdb ~/.Xresources
78         iconf -i instantthemes 1
79 fi
80
81 # dynamically switch between light and dark gtk theme
82 DATEHOUR=$(date +%H)
83 if [ "$DATEHOUR" -gt "20" ] || [ "$DATEHOUR" -lt "7" ]; then
84         instantthemes d &
85         touch /tmp/instantdarkmode
86         [ -e /tmp/instantlightmode ] && rm /tmp/instantlightmode
87 else
88         instantthemes l &
89         touch /tmp/instantlightmode
90         [ -e /tmp/instantdarkmode ] && rm /tmp/instantdarkmode
91 fi &
92
93 mkdir -p /tmp/notifications &>/dev/null
94 if ! pgrep dunst; then
95         while :; do
96                 # wait for theming before starting dunst
97                 if [ -e /tmp/instantdarkmode ] || [ -e /tmp/instantlightmode ]; then
98                         dunst
99                 fi
100                 sleep 2
101         done &
102 fi
103
104 onlinetrigger() {
105         instantwallpaper &
106 }
107
108 # set up oh-my-zsh config if not existing already
109 instantshell &
110 if ! [ iconf -i userinstall ]; then
111         bash /usr/share/instantutils/userinstall.sh
112 fi
113
114 # fix resolution on virtual machine
115 if ! iconf -i novmfix && cat /proc/cpuinfo | grep -q hypervisor; then
116         if echo "virtual machine detected.
117 Would you like to switch to a 1080p resolution?" | imenu -C; then
118                 echo "applying virtualbox workaround"
119                 /opt/instantos/menus/dm/tv.sh
120         else
121                 if ! imenu -c "ask again next session"; then
122                         iconf -i novmfix 1
123                 fi
124         fi
125 fi
126
127 if [ -z "$ISLIVE" ]; then
128         echo "not a live session"
129         if [ -e /opt/instantos/installtrigger ]; then
130                 zenity --info --text "finishing installation in background" &
131                 sudo instantpostinstall
132                 pkill zenity
133         fi
134
135         cd ~/instantos
136         if ! iconf -i max; then
137                 instantmonitor
138         fi
139
140         if [ -e ~/instantos/monitor.sh ]; then
141                 bash ~/instantos/monitor.sh &
142         elif [ -e ~/.config/autorandr/instantos/config ]; then
143                 autorandr instantos &
144         fi
145
146         if ping archlinux.org -c 2; then
147                 onlinetrigger
148         else
149                 # fall back to already installed wallpapers
150                 instantwallpaper offline
151                 for i in $(seq 10); do
152                         if ping archlinux.org -c 2; then
153                                 onlinetrigger
154                                 break
155                         else
156                                 sleep 10
157                         fi
158                 done
159         fi &
160
161         # apply keybpard layout
162         if [ -e ~/instantos/keyboard ]; then
163                 setxkbmap -layout $(cat ~/instantos/keyboard)
164         else
165                 CURLOCALE=$(locale | grep LANG | sed 's/.*=\(.*\)\..*/\1/')
166                 case "$CURLOCALE" in
167                 de_DE)
168                         setxkbmap -layout de
169                         ;;
170                 *)
171                         echo "no keyboard layout found for your locale"
172                         ;;
173                 esac
174         fi
175
176         # read cursor speed
177         if iconf mousespeed; then
178                 echo "setting mousespeed"
179                 instantmouse s "$(iconf mousespeed)"
180         fi
181
182         if ! iconf -i noconky; then
183                 shuf /usr/share/instantwidgets/tooltips.txt | head -1 >~/.cache/tooltip
184                 conky -c /usr/share/instantwidgets/tooltips.conf &
185         fi
186
187 else
188         echo "live session detected"
189         instantmonitor
190         iconf -b welcome 1
191         iconf -i wifiapplet 1
192         instantwallpaper set /usr/share/instantwallpaper/defaultphoto.png
193         conky -c /usr/share/instantwidgets/install.conf &
194         sleep 0.3
195         while :; do
196                 if ! pgrep python; then
197                         installapplet
198                 fi &
199                 sleep 6m
200         done &
201         sleep 1
202 fi
203
204 if iconf -i highfps; then
205         xdotool key super+alt+shift+d
206 fi
207
208 # make built in status optional
209 if ! iconf -i nostatus; then
210         source /usr/bin/instantstatus &
211 fi
212
213 lxpolkit &
214 xfce4-power-manager &
215
216 while iconf -i wifiapplet:; do
217         if ! pgrep nm-applet; then
218                 nm-applet &
219         fi
220         sleep 6m
221 done &
222
223 # welcome greeter app
224 if iconf -b welcome; then
225         instantwelcome
226 fi &
227
228 # prompt to fix configuration if installed from the AUR
229 if ! iconf -i norootinstall && [ -z "$ISLIVE" ]; then
230         if ! command -v imenu || ! command -v instantmenu; then
231                 notify-send "please install instantmenu and imenu"
232         else
233                 if ! [ -e /opt/instantos/rootinstall ]; then
234                         imenu -m "instantOS is missing some configuration"
235                         while ! [ -e /tmp/rootskip ]; do
236                                 if imenu -c "would you like to fix that?"; then
237                                         touch /tmp/topinstall
238                                         instantsudo bash -c "instantutils root"
239                                         touch /tmp/rootskip
240                                 else
241                                         if imenu -c "Are you sure? this will prevent parts of instantOS from functioning correctly"; then
242                                                 touch /tmp/rootskip
243                                         fi
244                                 fi
245
246                         done
247                 fi
248         fi
249 fi
250
251 # desktop icons
252 if iconf -i desktopicons; then
253         rox --pinboard Default
254 fi &
255
256 # user declared autostart
257 if [ -e ~/.instantautostart ]; then
258         bash ~/.instantautostart
259 fi