-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.sh
executable file
·86 lines (62 loc) · 1.52 KB
/
install.sh
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
#!/bin/bash
ecohome=`readlink -f $0 | xargs dirname`
servicehome=/lib/systemd/system
co2country=
co2policy=
cfgfile=ecofreq.cfg
os_detect()
{
if [ `uname -a | grep -c Darwin` -eq 1 ]; then
os=osx
echo "macOS is not supported yet, sorry!"
exit 1
elif [ `uname -a | grep -c Ubuntu` -eq 1 ]; then
os=ubuntu
elif [ `uname -a | grep -c CentOS` -eq 1 ]; then
os=redhat
else
os=unknown
fi
}
create_config()
{
if [ -z "$co2country" ];
then
read -p "Please enter your country/grid zone code (e.g., DE, GB or US-CAL-CISO): " co2country
echo ""
fi
if [ -z "$co2policy" ];
then
read -p "Do you wish to enable power scaling by default? [Y/n]: " yn
echo ""
if [[ $yn =~ ^[Nn]$ ]]
then
co2policy=none
else
co2policy=default
fi
fi
sed -e "s/<CO2POLICY>/$co2policy/" -e "s/<CO2COUNTRY>/$co2country/" ecofreq.cfg.templ > $cfgfile
}
echo -e "EcoFreq installer\n"
if [ `whoami` != root ]; then
echo -e "Please run this script as root or using sudo!\n"
exit 1
fi
os_detect
echo -e "Step 1: Installing dependencies...\n"
pip3 install -r requirements.txt
echo -e "Step 2: Prepare config file...\n"
if [ -f "$1" ]; then
cp $1 $cfgfile
else
create_config
fi
echo -e "Configuration saved to: $cfgfile\n"
echo -e "Step 3: Register systemd service...\n"
sed -e "s#<ECOFREQ_HOME>#$ecohome#" ecofreq.service > $servicehome/ecofreq.service
addgroup ecofreq
systemctl daemon-reload
systemctl enable ecofreq
systemctl start ecofreq
echo -e "\nInstallation complete!\n"