-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.sh
executable file
·146 lines (115 loc) · 4.41 KB
/
setup.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
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
#!/bin/bash
# Determine toolpath if not set already
relativepath="./" # Define relative path to go from this script to the root level of the tool
if [[ ! -v toolpath ]]; then scriptpath=$(cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ); toolpath=$(realpath --canonicalize-missing ${scriptpath}/${relativepath}); fi
# Load functions
source ${toolpath}/functions.sh
# Define Paths
SUPERMICRO_FAN_CONTROL_CONFIG_PATH="/etc/supermicro-fan-control"
# Create Folders
mkdir -p "${SUPERMICRO_FAN_CONTROL_CONFIG_PATH}"
mkdir -p /opt/supermicro-fan-control
# Create TMP Folder (only needed for Binary Files built using Nuitka --onefile)
mkdir -p /opt/supermicro-fan-control/tmp
if [ ! -f "/etc/modules-load.d/beep.conf" ]
then
# Rebuild initramfs
REBUILD_INITRD="yes"
else
# Do NOT rebuild initramfs
REBUILD_INITRD="no"
fi
# Update old Folder Structure (if any)
if [[ -d "/opt/supermicro-fan-control/bin" ]]
then
mv /opt/supermicro-fan-control/bin /opt/supermicro-fan-control/app
fi
# Upgrade existing Files if Any
# !! The new Extension used is .yml instead of .yaml !!
mapfile -t oldconfigfiles < <( find "${SUPERMICRO_FAN_CONTROL_CONFIG_PATH}" -iname *.yaml* )
for oldconfigfile in "${oldconfigfiles[@]}"
do
# Rename Extension using BASH
#newconfigfile=${oldconfigfile/".yaml"/".yml"}
# Rename Extension using SED
# At the end of the File
newconfigfile=$(echo "${oldconfigfile}" | sed -E "s|(.*?)\.yaml$|\1.yml|g")
# In the middle of the File
newconfigfile=$(echo "${newconfigfile}" | sed -E "s|(.*?)\.yaml\.(.*?)$|\1.yml.\2|g")
# Echo
echo "Renaming ${oldconfigfile} to ${newconfigfile}"
# Perform Operation
mv "${oldconfigfile}" "${newconfigfile}"
done
if [[ "${ENABLE_DEVEL}" != "yes" ]]
then
# Setup Kernel Module loading for BEEP
echo "pcspkr" > "/etc/modules-load.d/beep.conf"
# Revert "ugly and loud noise, getting on everyone's nerves; this should be done by a nice pulseaudio bing (Ubuntu: #77010)"
# This was apparently introduced by Ubuntu, but I believe it's better to know than NOT to know, when we have a critical issue !
if [[ -f /etc/modprobe.d/blacklist.conf ]]
then
sed -Ei "s|^blacklist pcspkr|#blacklist pcspkr|" /etc/modprobe.d/blacklist.conf
fi
# Echo
#echo "IMPORTANT: Remember to Update / Regenerate your initramfs/initrd in case this is the first Time you execute this Script"
#echo "IMPORTANT: This is/might be required to properly load the pcspkr / BEEP Kernel Module"
if [[ "REBUILD_INITRD" == "yes" ]]
then
# Rebuild initramfs
if [[ -n $(command -v update-initramfs) ]]
then
# Debian/Ubuntu/etc
echo "Rebuild INITRD using update-initramfs"
update-initramfs -k all -u
elif [[ -n $(command -v dracut) ]]
then
# Fedora/RHEL/Archlinux/etc
echo "Rebuild INITRD using dracut"
dracut --regenerate-all --force
else
# Other
echo "!! YOU MUST MANUALLY REBUILD INITRD. NEITHER update-initramfs NEITHER dracut have been detected !!"
fi
fi
fi
# Create venv
python3 -m venv "/opt/supermicro-fan-control/venv"
# Activate venv
source "/opt/supermicro-fan-control/venv/bin/activate"
# Enable Development Tools
if [[ "${ENABLE_DEVEL}" == "yes" ]]
then
pip install -r requirements.devel.txt
fi
# If NOT in Manual Debug Mode
if [[ "${DEBUG_MODE}" == "yes" ]]
then
# Install Requirements (Suppress Echo)
pip install -q -r requirements.prod.txt
else
# Install Requirements (Echo)
pip install -r requirements.prod.txt
fi
# Install App
cp -r opt/supermicro-fan-control/* /opt/supermicro-fan-control/
# Ensure Proper Permissions
chmod 755 /opt/supermicro-fan-control/app/supermicro-fan-control.py
# Install Example Settings
cp -r etc/supermicro-fan-control/* "${SUPERMICRO_FAN_CONTROL_CONFIG_PATH}/"
# Install Systemd Service
cp etc/systemd/system/supermicro-fan-control.service /etc/systemd/system/supermicro-fan-control.service
# Reload Systemd Daemon (at least to suppress warnings)
systemctl daemon-reload
# If NOT in Manual Debug Mode
if [[ "${DEBUG_MODE}" != "yes" ]]
then
# Enable Service
systemctl enable supermicro-fan-control.service
# Restart Service
systemctl restart supermicro-fan-control.service
# Show Status of Service in case the are any Errors
systemctl status --no-pager supermicro-fan-control.service
# Show and Follow Logs
journalctl -f --all -xeu supermicro-fan-control.service
fi