OSDN Git Service

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