forked from petersulyok/smfc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.sh
executable file
·37 lines (30 loc) · 1.05 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
#!/bin/bash
TARGET_DIR=/opt/smfc
POSTFIX=$(date +%4Y%m%d_%H%M%S)
# Must be executed with root privileges.
if [[ $EUID -ne 0 ]]; then
echo "$0: Error - must be executed with superuser privileges!"
exit 1
fi
# Backup original files
if [ -f "$TARGET_DIR/smfc.py" ]; then
cp "$TARGET_DIR/smfc.py" "$TARGET_DIR/smfc.py.$POSTFIX"
cp "$TARGET_DIR/smfc.conf" "$TARGET_DIR/smfc.conf.$POSTFIX"
fi
# Create the target folder if does not exist
if [ ! -d "$TARGET_DIR" ]; then
mkdir $TARGET_DIR
fi
# Copy new files to the target folders
cp ./src/smfc.py "$TARGET_DIR/"
cp ./src/smfc.conf "$TARGET_DIR/"
cp ./src/smfc /etc/default/
cp ./src/smfc.service /etc/systemd/system/
chown root.root "$TARGET_DIR/smfc.py" "$TARGET_DIR/smfc.conf" /etc/default/smfc /etc/systemd/system/smfc.service
# Generate a real hd_names= entry in the new 'smfc.conf'.
hd_name=$(ls -l /dev/disk/by-id/|grep .*ata-.*sda$|tr -s ' '|cut -d' ' -f 9)
if [ -n $hd_name ];
then
sed -i "s|hd_names=|hd_names=/dev/disk/by-id/$hd_name|g" "$TARGET_DIR/smfc.conf"
fi
echo "Installation finished successfully."