diff --git a/install.sh b/install.sh index 41c1649..9d31e67 100755 --- a/install.sh +++ b/install.sh @@ -1,6 +1,6 @@ #!/bin/bash # -# install.sh (C) 2021-2024, Peter Sulyok +# install.sh (C) 2021-2025, Peter Sulyok # Installation script for smfc service. # @@ -13,7 +13,7 @@ if [[ $EUID -ne 0 ]]; then exit 1 fi -# Display help text +# Display help text. if [ "$1" == "--help" ] || [ "$1" == "-h" ]; then echo "usage: $(basename $0) -h --help --keep-config" echo " -h, --help help text" @@ -21,7 +21,7 @@ if [ "$1" == "--help" ] || [ "$1" == "-h" ]; then exit 0 fi -# Backup original files +# 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 @@ -29,27 +29,37 @@ if [ -f "$TARGET_DIR/smfc.py" ]; then fi fi -# Create the target folder if does not exist +# Create the target folder if does not exist. if [ ! -d "$TARGET_DIR" ]; then mkdir $TARGET_DIR fi +# Check if the source files are downloaded to the current folder. +if [ ! -f "./src/smfc.py" ]; then + echo "Installation error: smfc files are missing (try to download/clone smfc first)." + exit 1 +fi # Copy new files to the target folders cp ./src/smfc.py "$TARGET_DIR/" +cp ./bin/hddtemp_emu.sh "$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 +chown root:root "$TARGET_DIR/smfc.py" "$TARGET_DIR/hddtemp_emu.sh" /etc/default/smfc /etc/systemd/system/smfc.service -# Generate a real hd_names= entry in the new 'smfc.conf'. +# Collect all disk names to 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" ]; + hd_list=$(ls /dev/disk/by-id/|grep -v -E ".*-part.$"|grep -v -E ".*_1$") + if [ -n "$hd_list" ]; then - sed -i "s|hd_names=|hd_names=/dev/disk/by-id/$hd_name|g" "$TARGET_DIR/smfc.conf" + hd_names="" + for hl in $hd_list; do + hd_names+="/dev/disk/by-id/$hl\n\t" + done + sed -i "s|hd_names=|hd_names=$hd_names|g" "$TARGET_DIR/smfc.conf" fi fi