Skip to content

Commit

Permalink
New: all disk names added to new configuration file.
Browse files Browse the repository at this point in the history
  • Loading branch information
petersulyok committed Jan 26, 2025
1 parent 194a76c commit dbf0cf7
Showing 1 changed file with 19 additions and 9 deletions.
28 changes: 19 additions & 9 deletions install.sh
Original file line number Diff line number Diff line change
@@ -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.
#

Expand All @@ -13,43 +13,53 @@ 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"
echo " --keep-config keep the original configuration file"
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
cp "$TARGET_DIR/smfc.conf" "$TARGET_DIR/smfc.conf.$POSTFIX"
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

Expand Down

0 comments on commit dbf0cf7

Please sign in to comment.