OSDN Git Service

add user declared autostart
[instantos/instantOS.git] / autostart.sh
1 #!/usr/bin/env bash
2
3 ###############################################
4 ## script for instantOS autostart            ##
5 ###############################################
6
7 if [ -z "$1" ]; then
8         if uname -m | grep -q '^arm'; then
9                 if [ -e /tmp/osautostart ]; then
10                         echo "already running"
11                         exit
12                 else
13                         touch /tmp/osautostart
14                         export ISRASPI=true
15                 fi
16         else
17                 bashes=$(pgrep bash | wc -l)
18                 if [ "$bashes" -gt 2 ]; then
19                         echo "already running"
20                         exit
21                 fi
22         fi
23 else
24         echo "forced run"
25 fi
26
27 cd
28 if ! iconf -i dotfiles; then
29         echo "installing dotfiles"
30         instantdotfiles &
31         mkdir instantos
32         iconf -i dotfiles 1
33
34         echo "installing ranger plugins"
35         mkdir -p ~/.config/ranger/plugins
36         cp -r /usr/share/rangerplugins/* ~/.config/ranger/plugins/
37
38 fi
39
40 # find out if we're on an installation medium
41 if command -v calamares_polkit &>/dev/null; then
42         ISLIVE="True"
43         echo "live session detected"
44 fi
45
46 # fix small graphical glitch on status bar startup
47 NMON=$(iconf names | wc -l)
48 for i in $(eval "echo {1..$NMON}"); do
49         xdotool key 'super+2' && sleep 0.1
50         xdotool key 'super+0' && sleep 0.1
51         xdotool key 'super+c' && sleep 0.1
52         xdotool key 'super+1' && sleep 0.1
53         xdotool key 'super+comma' && sleep 0.1
54 done &
55
56 if [ -n "$ISRASPI" ]; then
57         # enable double drawing for moving floating windows
58         # greatly increases smoothness
59         xdotool key super+alt+shift+d
60         if ! [ -e ~/.config/instantos/israspi ]; then
61                 echo "marking machine as raspi"
62                 mkdir -p ~/.config/instantos
63                 touch ~/.config/instantos/israspi
64                 # logo does not work on raspi
65                 iconf -i nologo 1
66         fi
67 fi
68
69 if iconf islaptop; then
70         export ISLAPTOP="true"
71         echo "laptop detected"
72 else
73         echo "not a laptop"
74 fi
75
76 if ! [ -e /opt/instantos/potato ]; then
77         picom &
78 else
79         echo "your computer is a potato"
80 fi
81
82 if ! iconf -i instantthemes; then
83         instantthemes a
84         xrdb ~/.Xresources
85         iconf -i instantthemes 1
86 fi
87
88 # dynamically switch between light and dark gtk theme
89 DATEHOUR=$(date +%H)
90 if [ "$DATEHOUR" -gt "20" ]; then
91         instantthemes d &
92 else
93         instantthemes l &
94 fi &
95
96 mkdir -p /tmp/notifications &>/dev/null
97 if ! pgrep dunst; then
98         while :; do
99                 dunst
100                 sleep 10
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
111 if [ -z "$ISLIVE" ]; then
112         cd ~/instantos
113         if ! iconf -i max; then
114                 instantmonitor
115         fi
116
117         if [ -e ~/instantos/monitor.sh ]; then
118                 bash ~/instantos/monitor.sh &
119         elif [ -e ~/.config/autorandr/instantos/config ]; then
120                 autorandr instantos &
121         fi
122
123         if ping google.com -c 2; then
124                 onlinetrigger
125         else
126                 # fall back to already installed wallpapers
127                 instantwallpaper offline
128                 for i in $(seq 10); do
129                         if ping google.com -c 2; then
130                                 onlinetrigger
131                                 break
132                         else
133                                 sleep 10
134                         fi
135                 done
136         fi
137
138         # apply keybpard layout
139         if [ -e ~/instantos/keyboard ]; then
140                 setxkbmap -layout $(cat ~/instantos/keyboard)
141         else
142                 CURLOCALE=$(locale | grep LANG | sed 's/.*=\(.*\)\..*/\1/')
143                 case "$CURLOCALE" in
144                 de_DE)
145                         setxkbmap -layout de
146
147                         ;;
148                 *)
149                         echo "no keyboard layout found for your locale"
150                         ;;
151                 esac
152         fi
153
154         shuf /usr/share/instantwidgets/tooltips.txt | head -1 >~/.cache/tooltip
155         conky -c /usr/share/instantwidgets/tooltips.conf &
156
157         # don't need applet for ethernet
158         if [ -e ~/.cache/haswifi ]; then
159                 echo "wifi enabled"
160                 while :; do
161                         if ! pgrep nm-applet; then
162                                 nm-applet &
163                         fi
164                         sleep 6m
165                 done &
166         fi
167
168 else
169         instantmonitor
170         feh --bg-scale /usr/share/instantwallpaper/defaultphoto.png
171         conky -c /usr/share/instantwidgets/install.conf &
172         sleep 0.3
173         while :; do
174                 if ! pgrep nm-applet; then
175                         installapplet &
176                         nm-applet &
177                 fi
178                 sleep 6m
179         done &
180         sleep 1
181 fi
182
183 # laptop specific background jobs
184 if [ -n "$ISLAPTOP" ]; then
185         echo "libinput gestures"
186         command -v libinput-gestures \
187                 &>/dev/null &&
188                 libinput-gestures &
189 fi
190
191 source /usr/bin/instantstatus &
192 lxpolkit &
193
194 # welcome greeter app
195 if iconf -b welcome; then
196         instantwelcome
197 fi &
198
199 # user declared autostart
200 if [ -e ~/.instantautostart ]; then
201         bash ~/.instantautostart
202 fi