OSDN Git Service

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