OSDN Git Service

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