OSDN Git Service

add appmenu to defaultapps
[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         iconf -i userinstall 1
11 fi
12
13 # architecture detection
14 if [ -z "$1" ]; then
15         if uname -m | grep -q '^arm'; then
16                 export ISRASPI=true
17         fi
18
19         if iconf -i noautostart; then
20                 echo "autostart disabled"
21                 exit
22         fi
23
24         if [ "$(ps aux | grep bash | grep instantautostart | wc -l)" -gt 3 ]; then
25                 echo "already running"
26                 exit
27         fi
28 else
29         echo "forced run"
30 fi
31
32 cd
33 command -v instantdotfiles && instantdotfiles
34
35 if ! iconf -i rangerplugins && command -v rangerplugins; then
36         mkdir instantos
37         echo "installing ranger plugins"
38         mkdir -p ~/.config/ranger/plugins
39         cp -r /usr/share/rangerplugins/* ~/.config/ranger/plugins/
40         iconf -i rangerplugins 1
41 fi
42
43 # find out if it's a live session
44 if [ -e /usr/share/liveutils ] &>/dev/null; then
45         ISLIVE="True"
46         echo "live session detected"
47 fi
48
49 if iconf -i islaptop; then
50         export ISLAPTOP="true"
51         echo "laptop detected"
52 else
53         echo "not a laptop"
54 fi
55
56 islive() {
57         if [ -n "$ISLIVE" ]; then
58                 return 0
59         else
60                 return 1
61         fi
62 }
63
64 # optionally disable status bar
65 if iconf -i nobar; then
66         NMON=$(iconf names | wc -l)
67         for i in $(eval "echo {1..$NMON}"); do
68                 echo "found monitor $i"
69                 xdotool key super+comma
70                 xdotool key super+b
71         done &
72 fi
73
74 if [ -n "$ISRASPI" ]; then
75         # enable double drawing for moving floating windows
76         # greatly increases smoothness
77         iconf -i highfps 1
78         if ! [ -e ~/.config/instantos/israspi ]; then
79                 echo "marking machine as raspi"
80                 mkdir -p ~/.config/instantos
81                 touch ~/.config/instantos/israspi
82                 # logo does not work on raspi
83                 iconf -i nologo 1
84         fi
85 fi
86
87 if ! iconf -i notheming; then
88         instantthemes a
89         xrdb ~/.Xresources
90         iconf -i instantthemes 1
91
92         # dynamically switch between light and dark gtk theme
93         DATEHOUR=$(date +%H)
94         if [ "$DATEHOUR" -gt "20" ] || [ "$DATEHOUR" -lt "7" ]; then
95                 instantthemes d &
96                 touch /tmp/instantdarkmode
97                 [ -e /tmp/instantlightmode ] && rm /tmp/instantlightmode
98         else
99                 instantthemes l &
100                 touch /tmp/instantlightmode
101                 [ -e /tmp/instantdarkmode ] && rm /tmp/instantdarkmode
102         fi &
103 else
104         touch /tmp/instantlightmode
105 fi
106
107 mkdir -p /tmp/notifications &>/dev/null
108 if ! pgrep dunst; then
109         while :; do
110                 # wait for theming before starting dunst
111                 if [ -e /tmp/instantdarkmode ] || [ -e /tmp/instantlightmode ]; then
112                         dunst
113                 fi
114                 sleep 2
115         done &
116 fi
117
118 onlinetrigger() {
119         instantwallpaper &
120 }
121
122 # set up oh-my-zsh config if not existing already
123 iconf -i nozsh || instantshell &
124
125 # fix resolution on virtual machine
126 if ! iconf -i novmfix && grep -q 'hypervisor' /proc/cpuinfo; then
127         # indicator file only exists on kvm/QEMU on amd
128         if [ -e /opt/instantos/kvm ]; then
129                 iconf -i highfps 1
130                 if lshw -c video | grep -i 'qxl' || xrandr | grep -i '^qxl'; then
131                         iconf -i qxl 1
132                         # iconf -i noanimations 1
133                         if ! iconf -i potato && ! iconf -i nopotato; then
134                                 if echo "please set your video card to virtio or passthrough
135 QXL on AMD on QEMU/kvm has been known to cause a severe Xorg memory leak. 
136 Disabling compositing makes this somewhat bearable,
137 but switching really is recommended.
138 (or switch to virtualbox, no issues there...)
139 Disable compositing for this VM?" | imenu -C; then
140                                         iconf -i potato 1
141                                         pkill picom
142                                 else
143                                         if ! imenu -c "ask again next time?"; then
144                                                 iconf -i nopotato 1
145                                         fi
146                                 fi
147                         fi
148                 else
149                         iconf -i qxl 1
150                 fi
151         fi
152
153         if ! [ -e /opt/instantos/guestadditions ]; then
154                 if echo "virtual machine detected.
155 Would you like to switch to a 1080p resolution?" | imenu -C; then
156                         echo "applying virtual machine workaround"
157                         /usr/share/instantassist/assists/t/v.sh
158                 else
159                         if ! imenu -c "ask again next session"; then
160                                 iconf -i novmfix 1
161                         fi
162                 fi
163         fi
164 fi
165
166 if ! islive; then
167         echo "not a live session"
168         if [ -e /opt/instantos/installtrigger ]; then
169                 zenity --info --text "finishing installation in background" &
170
171                 # ask for password if postinstall already ran
172                 if ! timeout 2 sudo echo test; then
173                         instantsudo instantpostinstall
174                         sudo rm /opt/instantos/installtrigger
175                 else
176                         sudo instantpostinstall
177                 fi
178
179                 pkill zenity
180         fi
181
182         cd ~/instantos || exit 1
183         if ! iconf -i max; then
184                 instantmonitor
185         fi
186
187         if [ -e ~/instantos/monitor.sh ]; then
188                 bash ~/instantos/monitor.sh &
189         elif [ -e ~/.config/autorandr/instantos/config ]; then
190                 autorandr instantos &
191         fi
192
193         if checkinternet; then
194                 onlinetrigger
195         else
196                 # fall back to already installed wallpapers
197                 instantwallpaper offline
198                 for i in $(seq 10); do
199                         if checkinternet; then
200                                 onlinetrigger
201                                 break
202                         else
203                                 sleep 10
204                         fi
205                 done
206         fi &
207
208         # apply keybpard layout
209         if iconf layout; then
210                 setxkbmap -layout "$(iconf keyboard)"
211         else
212                 CURLOCALE=$(locale | grep LANG | sed 's/.*=\(.*\)\..*/\1/')
213                 case "$CURLOCALE" in
214                 de_DE)
215                         setxkbmap -layout de
216                         ;;
217                 *)
218                         echo "no keyboard layout found for your locale"
219                         ;;
220                 esac
221         fi
222
223         # read cursor speed
224         if iconf mousespeed; then
225                 echo "setting mousespeed"
226                 instantmouse s "$(iconf mousespeed)"
227         fi
228
229         if iconf -i reversemouse; then
230                 instantmouse r 1
231         else
232                 instantmouse r 0
233         fi
234
235         if ! iconf -i noconky; then
236                 shuf /usr/share/instantwidgets/tooltips.txt | head -1 >~/.cache/tooltip
237                 conky -c /usr/share/instantwidgets/tooltips.conf &
238         fi
239
240 else
241         echo "live session detected"
242         instantmonitor
243
244         echo "disabling compositing for qxl graphics"
245         if lshw -c video | grep -i 'qxl' || xrandr | grep -i '^qxl'; then
246                 iconf -i potato 1
247         fi
248
249         sudo systemctl start NetworkManager
250
251         iconf -b welcome 1
252         iconf -i wifiapplet 1
253         instantwallpaper set /usr/share/instantwallpaper/defaultphoto.png
254         conky -c /usr/share/instantwidgets/install.conf &
255         sleep 0.3
256         while :; do
257                 if ! pgrep python; then
258                         installapplet
259                 fi &
260                 sleep 6m
261         done &
262         sleep 1
263 fi
264
265 # make built in status optional
266 if ! iconf -i nostatus; then
267         source /usr/bin/instantstatus &
268 fi
269
270 iconf -i potato || ipicom &
271
272 while :; do
273         lxpolkit
274 done &
275
276 xfce4-power-manager &
277
278 while iconf -i wifiapplet:; do
279         echo "auto starting wifi applet"
280         if ! pgrep nm-applet; then
281                 nm-applet &
282         fi
283         sleep 6m
284 done &
285
286 while iconf -i bluetoothapplet:; do
287         echo "auto starting bluetooth applet"
288         if ! pgrep blueman-applet; then
289                 blueman-applet &
290         fi
291         sleep 6m
292 done &
293
294 # welcome greeter app
295 if iconf -b welcome; then
296         instantwelcome
297 fi &
298
299 # prompt to fix configuration if installed from the AUR
300 if ! iconf -i norootinstall && ! islive; then
301         if ! command -v imenu || ! command -v instantmenu; then
302                 notify-send "please install instantmenu and imenu"
303         else
304                 if ! [ -e /opt/instantos/rootinstall ]; then
305                         imenu -m "instantOS is missing some configuration"
306                         while ! [ -e /tmp/rootskip ]; do
307                                 if imenu -c "would you like to fix that?"; then
308                                         touch /tmp/topinstall
309                                         instantsudo bash -c "instantutils root"
310                                         touch /tmp/rootskip
311                                 else
312                                         if imenu -c "Are you sure? this will prevent parts of instantOS from functioning correctly"; then
313                                                 touch /tmp/rootskip
314                                         fi
315                                 fi
316
317                         done
318                 fi
319         fi
320 fi
321
322 # displays message user opens the terminal for the first time
323 if ! iconf -i nohelp; then
324         if ! grep -q 'instantterminalhelp' ~/.zshrc; then
325                 echo '[[ $- == *i* ]] && instantterminalhelp' >>~/.zshrc
326         fi
327 fi
328
329 if iconf -i highfps; then
330         xdotool key super+alt+shift+d
331 fi
332
333 if iconf -i noanimations; then
334         xdotool key super+alt+shift+s
335 fi
336
337 # desktop icons
338 if iconf -i desktopicons; then
339         rox --pinboard Default
340 fi &
341
342 # optional udiskie
343 if iconf -i udiskie; then
344         command -v udiskie && udiskie -t &
345 fi
346
347 # user declared autostart
348 if [ -e ~/.instantautostart ]; then
349         bash ~/.instantautostart &
350 fi
351
352 # symlink default applications
353 if ! iconf terminal; then
354         echo "setting up default applications"
355         instantutils default
356 fi