-
Notifications
You must be signed in to change notification settings - Fork 15
/
install.sh
executable file
·56 lines (48 loc) · 1.54 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
#!/bin/bash
#
# install.sh (C) 2021-2024, Peter Sulyok
# Installation script for smfc service.
#
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
# Display help text
if [ "$1" == "--help" ] || [ "$1" == "-h" ]; then
echo "usage: $(basename $0) -h --help --keep-config"
echo " -h, --help help text"
echo " --keep-config keep the original configuration file"
exit 0
fi
# Backup original files
if [ -f "$TARGET_DIR/smfc.py" ]; then
cp "$TARGET_DIR/smfc.py" "$TARGET_DIR/smfc.py.$POSTFIX"
if [ "$1" != "--keep-config" ]; then
cp "$TARGET_DIR/smfc.conf" "$TARGET_DIR/smfc.conf.$POSTFIX"
fi
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/"
if [ "$1" != "--keep-config" ]; then
cp ./src/smfc.conf "$TARGET_DIR/"
chown root:root "$TARGET_DIR/smfc.py"
fi
cp ./src/smfc /etc/default/
cp ./src/smfc.service /etc/systemd/system/
chown root:root "$TARGET_DIR/smfc.py" /etc/default/smfc /etc/systemd/system/smfc.service
# Generate a real hd_names= entry in the new 'smfc.conf'.
if [ "$1" != "--keep-config" ]; then
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
fi
echo "Installation finished successfully."