OSDN Git Service

enable turning off theming and conky
[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 notheming; 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         if ! iconf -i noconky; then
155                 shuf /usr/share/instantwidgets/tooltips.txt | head -1 >~/.cache/tooltip
156                 conky -c /usr/share/instantwidgets/tooltips.conf &
157         fi
158
159         # don't need applet for ethernet
160         if [ -e ~/.cache/haswifi ] || iconf -i wifiapplet; then
161                 echo "wifi enabled"
162                 while iconf -i wifiapplet:; do
163                         if ! pgrep nm-applet; then
164                                 nm-applet &
165                         fi
166                         sleep 6m
167                 done &
168         fi
169
170 else
171         instantmonitor
172         feh --bg-scale /usr/share/instantwallpaper/defaultphoto.png
173         conky -c /usr/share/instantwidgets/install.conf &
174         sleep 0.3
175         while :; do
176                 if ! pgrep nm-applet; then
177                         installapplet &
178                         nm-applet &
179                 fi
180                 sleep 6m
181         done &
182         sleep 1
183 fi
184
185 # laptop specific background jobs
186 if [ -n "$ISLAPTOP" ]; then
187         echo "libinput gestures"
188         command -v libinput-gestures \
189                 &>/dev/null &&
190                 libinput-gestures &
191 fi
192
193 source /usr/bin/instantstatus &
194 lxpolkit &
195 xfce4-power-manager &
196
197 # welcome greeter app
198 if iconf -b welcome; then
199         instantwelcome
200 fi &
201
202 # user declared autostart
203 if [ -e ~/.instantautostart ]; then
204         bash ~/.instantautostart
205 fi