-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathemh
executable file
·151 lines (133 loc) · 4.03 KB
/
emh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#!/bin/bash
order=$1
emhDir=$(dirname "$(readlink -f "$0")")
if [[ $order = 'start' ]]
then
echo "Optimizing system:"
sudo "$emhDir"/Tools/disablePowerOptimizations.perl
emh bright
echo deep | sudo tee /sys/power/mem_sleep #enable deep sleep for suspend
echo balance_power | sudo tee /sys/devices/system/cpu/cpufreq/policy*/energy_performance_preference # set preference for cpu performance
# TODO Add daemon that watches for unlocks to reset birightness https://unix.stackexchange.com/a/28183/151284
# TODO Add to transient daemon using https://unix.stackexchange.com/a/367237/151284
dbus-monitor --session "type='signal',interface='org.gnome.ScreenSaver'" |
while read -r x; do
case "$x" in
*"boolean true"*) echo SCREEN_LOCKED;;
*"boolean false"*) echo SCREEN_UNLOCKED && gdbus call --session --dest org.gnome.SettingsDaemon.Power --object-path /org/gnome/SettingsDaemon/Power --method org.gnome.SettingsDaemon.Power.Screen.StepUp && gdbus call --session --dest org.gnome.SettingsDaemon.Power --object-path /org/gnome/SettingsDaemon/Power --method org.gnome.SettingsDaemon.Power.Screen.StepDown;;
esac
done
fi
if [[ $order = 'update' ]]
then
echo "Updating System, please enter sudo password:"
sudo apt update
if [ "$(apt-get -s upgrade | awk '/^Inst/ { print $2 }' | wc -l)" -gt 0 ]
then
sudo apt upgrade
fi
# also update flatpak packages
flatpak update
fi
if [[ $order = 'run' ]]
then
echo "Running config"
python3 "$emhDir"/Tools/runProject.py "${@:2}"
fi
if [[ $order = 'crawl' ]]
then
echo "Crawling Website"
test=$(python3 "$emhDir"/Tools/crawl.py "$2")
echo $test
fi
if [[ $order = 'bright' ]]
then
defaultBrightness=$(python3 "$emhDir"/Tools/getConfig.py "defaultBrightness" 0.2)
echo "Changing Brightness"
if [ $# -gt 1 ]
then
brightness=$2
else
brightness=$defaultBrightness
fi
brightness=$(awk -v bright="${brightness}" -v hundred="100" 'BEGIN{out_bright=(bright*hundred); print out_bright}')
# set brightness property of org.gnome.SettingsDaemon.Power.Screen to requested brightness, normal output is sent to /dev/null
gdbus call --session --dest org.gnome.SettingsDaemon.Power --object-path /org/gnome/SettingsDaemon/Power \
--method org.freedesktop.DBus.Properties.Set \
org.gnome.SettingsDaemon.Power.Screen Brightness "<$brightness>" > /dev/null
fi
if [[ $order = 'mount' ]]
then
mkdir -p ~/OSUengr
sshfs [email protected]:/nfs/stak/users/hamptone ~/OSUengr
fi
if [[ $order = 'unmount' ]]
then
fusermount -u ~/OSUengr
rmdir ~/OSUengr
fi
if [[ $order = 'connect' ]]
then
#TODO move get config to function
location=$(python3 "$emhDir"/Tools/getConfig.py "connect.$2")
if [ $? -eq 0 ]
then
ssh "$location" ${@:3}
else
echo "Couldn't find a config location for that server ($2)"
fi
fi
if [[ $order = 'work' ]]
then
slack -s & disown
xdg-open https://osu-prod.wta-us8.wfs.cloud/workforce/WebClock.do
thunderbird & disown
#terminator -l 'General_Work' #Not working for some reason and causing problems
#hexchat & disown
fi
if [[ $order = 'unwork' ]]
then
xdg-open https://osu-prod.wta-us8.wfs.cloud/workforce/WebClock.do
pkill slack --signal SIGTERM
#pkill hexchat --signal SIGTERM
fi
if [[ $order = 'backup' ]]
then
location=$(python3 "$emhDir"/Tools/getConfig.py "backup.destination.$2")
if [ $? -eq 0 ]
then
backupScript=$(python3 "$emhDir"/Tools/backup.py "$2")
echo "$backupScript"
read -r -p "Are you sure? [y/N] " response
if [[ "$response" =~ ^([yY][eE][sS]|[yY])$ ]]
then
echo "Running backup..."
eval "$backupScript"
else
echo "Okay, exiting"
fi
else
echo "Couldn't find a config for that backup location ($2)"
fi
fi
if [[ $order = 'journal' ]]
then
if [[ $2 = 'view' ]]
then
jrnl -to today | less +G -R
else
echo "Adding journal entry"
jrnl
fi
fi
if [[ $order = 'unused' ]]
then
python3 "$emhDir"/Tools/unused/unused.py "$(pwd)" "${@:2}"
fi
#aliases should always be last in this file
#TODO only run if another command didn't already
alias=$(python3 "$emhDir"/Tools/getConfig.py "aliases.$order")
if [ $? -eq 0 ]
then
emh "$alias" "${@:2}"
fi