OSDN Git Service

disable compositing on qxl live sessions
[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 3 ]; 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 if ! iconf -i notheming; then
74         instantthemes a
75         xrdb ~/.Xresources
76         iconf -i instantthemes 1
77
78         # dynamically switch between light and dark gtk theme
79         DATEHOUR=$(date +%H)
80         if [ "$DATEHOUR" -gt "20" ] || [ "$DATEHOUR" -lt "7" ]; then
81                 instantthemes d &
82                 touch /tmp/instantdarkmode
83                 [ -e /tmp/instantlightmode ] && rm /tmp/instantlightmode
84         else
85                 instantthemes l &
86                 touch /tmp/instantlightmode
87                 [ -e /tmp/instantdarkmode ] && rm /tmp/instantdarkmode
88         fi &
89 else
90         touch /tmp/instantlightmode
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         # indicator file only exists on kvm/QEMU on amd
117         if [ -e /opt/instantos/kvm ]; then
118                 iconf -i highfps 1
119                 if lshw -c video | grep -i 'qxl' || xrandr | grep -i '^qxl'; then
120                         iconf -i qxl 1
121                         # iconf -i noanimations 1
122                         if ! iconf -i potato && ! iconf -i nopotato; then
123                                 if echo "please set your video card to virtio or passthrough
124 QXL on AMD on QEMU/kvm has been known to cause a severe Xorg memory leak. 
125 Disabling compositing makes this somewhat bearable,
126 but switching really is recommended.
127 (or switch to virtualbox, no issues there...)
128 Disable compositing for this VM?" | imenu -C; then
129                                         iconf -i potato 1
130                                         pkill picom
131                                 else
132                                         if ! imenu -c "ask again next time?"; then
133                                                 iconf -i nopotato 1
134                                         fi
135                                 fi
136                         fi
137                 else
138                         iconf -i qxl 1
139                 fi
140         fi
141         if echo "virtual machine detected.
142 Would you like to switch to a 1080p resolution?" | imenu -C; then
143                 echo "applying virtual machine workaround"
144                 /opt/instantos/menus/dm/tv.sh
145         else
146                 if ! imenu -c "ask again next session"; then
147                         iconf -i novmfix 1
148                 fi
149         fi
150 fi
151
152 if [ -z "$ISLIVE" ]; then
153         echo "not a live session"
154         if [ -e /opt/instantos/installtrigger ]; then
155                 zenity --info --text "finishing installation in background" &
156
157                 # ask for password if postinstall already ran
158                 if ! timeout 2 sudo echo test; then
159                         instantsudo instantpostinstall
160                         sudo rm /opt/instantos/installtrigger
161                 else
162                         sudo instantpostinstall
163                 fi
164
165                 pkill zenity
166         fi
167
168         cd ~/instantos
169         if ! iconf -i max; then
170                 instantmonitor
171         fi
172
173         if [ -e ~/instantos/monitor.sh ]; then
174                 bash ~/instantos/monitor.sh &
175         elif [ -e ~/.config/autorandr/instantos/config ]; then
176                 autorandr instantos &
177         fi
178
179         if checkinternet; then
180                 onlinetrigger
181         else
182                 # fall back to already installed wallpapers
183                 instantwallpaper offline
184                 for i in $(seq 10); do
185                         if checkinternet; then
186                                 onlinetrigger
187                                 break
188                         else
189                                 sleep 10
190                         fi
191                 done
192         fi &
193
194         # apply keybpard layout
195         if [ -e ~/instantos/keyboard ]; then
196                 setxkbmap -layout $(cat ~/instantos/keyboard)
197         else
198                 CURLOCALE=$(locale | grep LANG | sed 's/.*=\(.*\)\..*/\1/')
199                 case "$CURLOCALE" in
200                 de_DE)
201                         setxkbmap -layout de
202                         ;;
203                 *)
204                         echo "no keyboard layout found for your locale"
205                         ;;
206                 esac
207         fi
208
209         # read cursor speed
210         if iconf mousespeed; then
211                 echo "setting mousespeed"
212                 instantmouse s "$(iconf mousespeed)"
213         fi
214
215         if ! iconf -i noconky; then
216                 shuf /usr/share/instantwidgets/tooltips.txt | head -1 >~/.cache/tooltip
217                 conky -c /usr/share/instantwidgets/tooltips.conf &
218         fi
219
220 else
221         echo "live session detected"
222         instantmonitor
223
224         echo "disabling compositing for qxl graphics"
225         if lshw -c video | grep -i 'qxl' || xrandr | grep -i '^qxl'; then
226                 iconf -i potato 1
227         fi
228
229         iconf -b welcome 1
230         iconf -i wifiapplet 1
231         instantwallpaper set /usr/share/instantwallpaper/defaultphoto.png
232         conky -c /usr/share/instantwidgets/install.conf &
233         sleep 0.3
234         while :; do
235                 if ! pgrep python; then
236                         installapplet
237                 fi &
238                 sleep 6m
239         done &
240         sleep 1
241 fi
242
243 # make built in status optional
244 if ! iconf -i nostatus; then
245         source /usr/bin/instantstatus &
246 fi
247
248 iconf -i potato || ipicom &
249
250 lxpolkit &
251 xfce4-power-manager &
252
253 while iconf -i wifiapplet:; do
254         if ! pgrep nm-applet; then
255                 nm-applet &
256         fi
257         sleep 6m
258 done &
259
260 # welcome greeter app
261 if iconf -b welcome; then
262         instantwelcome
263 fi &
264
265 # prompt to fix configuration if installed from the AUR
266 if ! iconf -i norootinstall && [ -z "$ISLIVE" ]; then
267         if ! command -v imenu || ! command -v instantmenu; then
268                 notify-send "please install instantmenu and imenu"
269         else
270                 if ! [ -e /opt/instantos/rootinstall ]; then
271                         imenu -m "instantOS is missing some configuration"
272                         while ! [ -e /tmp/rootskip ]; do
273                                 if imenu -c "would you like to fix that?"; then
274                                         touch /tmp/topinstall
275                                         instantsudo bash -c "instantutils root"
276                                         touch /tmp/rootskip
277                                 else
278                                         if imenu -c "Are you sure? this will prevent parts of instantOS from functioning correctly"; then
279                                                 touch /tmp/rootskip
280                                         fi
281                                 fi
282
283                         done
284                 fi
285         fi
286 fi
287
288 # displays message user opens the terminal for the first time
289 if ! iconf -i nohelp; then
290         if ! grep -q 'instantterminalhelp' ~/.zshrc; then
291                 echo '[[ $- == *i* ]] && instantterminalhelp' >>~/.zshrc
292         fi
293 fi
294
295 if iconf -i highfps; then
296         xdotool key super+alt+shift+d
297 fi
298
299 if iconf -i noanimations; then
300         xdotool key super+alt+shift+s
301 fi
302
303 # desktop icons
304 if iconf -i desktopicons; then
305         rox --pinboard Default
306 fi &
307
308 # user declared autostart
309 if [ -e ~/.instantautostart ]; then
310         bash ~/.instantautostart
311 fi