OSDN Git Service

new wallpaper changer
[instantos/instantOS.git] / autostart.sh
1 #!/usr/bin/env bash
2
3 ####################################################
4 ## script for instantOS autostart            ##
5 ####################################################
6
7 bashes=$(pgrep bash | wc -l)
8 if [ "$bashes" -gt 2 ]; then
9         echo "already running"
10         exit
11 fi
12
13 # fix small graphical glitch on status bar startup
14 xdotool key 'super+2'
15 sleep 0.1
16 xdotool key 'super+1'
17
18 if acpi | grep -q '%' &>/dev/null; then
19         export ISLAPTOP="true"
20         echo "laptop detected"
21 else
22         echo "not a laptop"
23 fi
24
25 if command -v picom &>/dev/null; then
26         picom &
27 else
28         compton &
29 fi
30
31 sleep 1
32
33 mkdir -p /tmp/notifications &>/dev/null
34 if ! pgrep dunst; then
35         while :; do
36                 dunst
37                 sleep 10
38         done &
39 fi
40
41 cd ~/instantos
42
43 if ! grep -q '....' ~/instantos/monitor/max.txt; then
44         bash /opt/instantos/scripts/monitor.sh
45 fi
46
47 [ -e ~/instantos/monitor.sh ] &&
48         bash ~/instantos/monitor.sh &
49
50 if ping google.com -c 2; then
51         onlinetrigger
52 else
53         instantwallpaper offline
54         for i in $(seq 10); do
55                 if ping google.com -c 2; then
56                         onlinetrigger
57                         break
58                 else
59                         sleep 10
60                 fi
61         done
62 fi
63
64 # apply german keybpard layout
65 if locale | grep -q 'de_DE'; then
66         setxkbmap -layout de
67 fi
68
69 # laptop specific background jobs
70 if [ -n "$ISLAPTOP" ]; then
71         command -v libinput-gestures \
72                 &>/dev/null &&
73                 libinput-gestures &
74         nm-applet &
75 fi
76
77 INTERNET="X"
78
79 REPETITIONS="xxxxxx"
80
81 command -v conky &>/dev/null && conky &
82
83 date=""
84
85 addstatus() {
86         date="$date[$@] "
87 }
88
89 # status bar loop
90 while :; do
91         if [ -e ~/.instantsilent ]; then
92                 sleep 1m
93                 continue
94         fi
95
96         # run every 60 seconds
97         if [ "$REPETITIONS" = "xxxxxx" ]; then
98                 REPETITIONS="x"
99                 if ping -q -c 1 -W 1 8.8.8.8; then
100                         INTERNET="i"
101                 else
102                         INTERNET="^c#ff0000^X^d^"
103                 fi
104
105                 # battery indicator on laptop
106                 if [ -n "$ISLAPTOP" ]; then
107                         TMPBAT=$(acpi)
108                         if [[ $TMPBAT =~ "Charging" ]]; then
109                                 BATTERY="^c#00ff00^B"$(egrep -o '[0-9]*%' <<<"$TMPBAT")"^d^"
110                         else
111                                 BATTERY="B"$(egrep -o '[0-9]*%' <<<"$TMPBAT")
112                                 # make indicator red on low battery
113                                 if [ $(grep '[0-9]*' <<<$BATTERY) -lt 10 ]; then
114                                         BATTERY="^c#ff0000^$BATTERY^d^"
115                                 fi
116                         fi
117                 fi
118
119         else
120                 # increase counter
121                 REPETITIONS="$REPETITIONS"x
122         fi
123
124         addstatus "$(date +'%d-%m|%H:%M')"
125         addstatus "A$(amixer get Master | egrep -o '[0-9]{1,3}%' | head -1)"
126         [ -n "$ISLAPTOP" ] && addstatus "$BATTERY"
127         addstatus "$INTERNET"
128
129         xsetroot -name "^f11^$date"
130         date=""
131
132         sleep 10
133 done