-
-
Save icedream/567188afa09551e2bf63a83550406741 to your computer and use it in GitHub Desktop.
Fix up remaining issues fw-fanctrl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --ignore-trailing-space -u fw-fanctrl.old/install.sh fw-fanctrl/install.sh | |
--- fw-fanctrl.old/install.sh 2024-05-22 00:16:37.264611247 +0200 | |
+++ fw-fanctrl/install.sh 2024-05-22 00:36:36.235449298 +0200 | |
@@ -1,4 +1,5 @@ | |
#!/bin/bash | |
+set -e | |
if [ "$EUID" -ne 0 ] | |
then echo "This program requires root permissions" | |
@@ -6,8 +7,8 @@ | |
fi | |
# Argument parsing | |
-SHORT=r,d:,p:,h | |
-LONG=remove,dest-dir:,prefix-dir:,no-ectool,no-post-install,help | |
+SHORT=r,d:,p:,s:,h | |
+LONG=remove,dest-dir:,prefix-dir:,sysconf-dir:,no-ectool,no-post-install,help | |
VALID_ARGS=$(getopt -a -n weather --options $SHORT --longoptions $LONG -- "$@") | |
if [[ $? -ne 0 ]]; then | |
exit 1; | |
@@ -15,6 +16,7 @@ | |
PREFIX_DIR="/usr" | |
DEST_DIR="/usr" | |
+SYSCONF_DIR="" | |
SHOULD_INSTALL_ECTOOL=true | |
SHOULD_POST_INSTALL=true | |
SHOULD_REMOVE=false | |
@@ -33,6 +35,10 @@ | |
DEST_DIR=$2 | |
shift | |
;; | |
+ '--sysconf-dir' | '-s') | |
+ SYSCONF_DIR=$2 | |
+ shift | |
+ ;; | |
'--no-ectool') | |
SHOULD_INSTALL_ECTOOL=false | |
;; | |
@@ -40,7 +46,7 @@ | |
SHOULD_POST_INSTALL=false | |
;; | |
'--help' | '-h') | |
- echo "Usage: $0 [--remove,-r] [--dest-dir,-d <installation destination directory (defaults to $DEST_DIR)>] [--prefix-dir,-p <installation prefix directory (defaults to $PREFIX_DIR)>] [--no-ectool] [--no-post-install]" 1>&2 | |
+ echo "Usage: $0 [--remove,-r] [--dest-dir,-d <installation destination directory (defaults to $DEST_DIR)>] [--prefix-dir,-p <installation prefix directory (defaults to $PREFIX_DIR)>] [--sysconf-dir,-s system configuration destination directory (defaults to \$DEST_DIR/etc)] [--no-ectool] [--no-post-install]" 1>&2 | |
exit 0 | |
;; | |
--) | |
@@ -51,6 +57,8 @@ | |
done | |
# | |
+SYSCONF_DIR="${SYSCONF_DIR:-${DEST_DIR}/etc}" | |
+ | |
SERVICES_DIR="./services" | |
SERVICE_EXTENSION=".service" | |
@@ -85,7 +93,7 @@ | |
echo "disabling [$SERVICE]" | |
systemctl disable "$SERVICE" | |
echo "removing '$PREFIX_DIR/lib/systemd/system/$SERVICE$SERVICE_EXTENSION'" | |
- (cd "$PREFIX_DIR/lib/systemd/system/" && rm -rf "$SERVICE$SERVICE_EXTENSION") | |
+ (cd "$DEST_DIR/lib/systemd/system/" && rm -rf "$SERVICE$SERVICE_EXTENSION") | |
done | |
# remove program services sub-configurations based on the sub-configurations present in the './services' folder | |
@@ -97,7 +105,7 @@ | |
for SUBCONFIG in $SUBCONFIGS ; do | |
SUBCONFIG=$(sanitizePath "$SUBCONFIG") | |
echo "removing '$PREFIX_DIR/lib/systemd/$SERVICE/$SUBCONFIG'" | |
- (cd "$PREFIX_DIR/lib/systemd/" && cd "$SERVICE" && rm -rf "$SUBCONFIG") | |
+ (cd "$DEST_DIR/lib/systemd/" && cd "$SERVICE" && rm -rf "$SUBCONFIG") | |
done | |
done | |
@@ -106,7 +114,7 @@ | |
if [ "$SHOULD_INSTALL_ECTOOL" = true ]; then | |
rm "$DEST_DIR/bin/ectool" | |
fi | |
- rm -rf "/etc/fw-fanctrl" | |
+ rm -rf "$SYSCONF_DIR/fw-fanctrl" | |
rm -rf "/run/fw-fanctrl" | |
uninstall_legacy | |
@@ -120,13 +128,15 @@ | |
cp "./bin/ectool" "$DEST_DIR/bin/ectool" | |
chmod +x "$DEST_DIR/bin/ectool" | |
fi | |
- mkdir -p "/etc/fw-fanctrl" | |
+ mkdir -p "$SYSCONF_DIR/fw-fanctrl" | |
cp "./fanctrl.py" "$DEST_DIR/bin/fw-fanctrl" | |
chmod +x "$DEST_DIR/bin/fw-fanctrl" | |
- cp -n "./config.json" "/etc/fw-fanctrl" 2> "/dev/null" || true | |
+ cp -n "./config.json" "${SYSCONF_DIR}/fw-fanctrl" 2> "/dev/null" || true | |
# create program services based on the services present in the './services' folder | |
+ echo "creating '$DEST_DIR/lib/systemd/system'" | |
+ mkdir -p "$DEST_DIR/lib/systemd/system" | |
echo "creating services" | |
for SERVICE in $SERVICES ; do | |
SERVICE=$(sanitizePath "$SERVICE") | |
@@ -134,8 +144,8 @@ | |
echo "stopping [$SERVICE]" | |
systemctl stop "$SERVICE" | |
fi | |
- echo "creating '$PREFIX_DIR/lib/systemd/system/$SERVICE$SERVICE_EXTENSION'" | |
- cat "$SERVICES_DIR/$SERVICE$SERVICE_EXTENSION" | sed -e "s/%PREFIX_DIRECTORY%/${PREFIX_DIR//\//\\/}/" | tee "$PREFIX_DIR/lib/systemd/system/$SERVICE$SERVICE_EXTENSION" > "/dev/null" | |
+ echo "creating '$DEST_DIR/lib/systemd/system/$SERVICE$SERVICE_EXTENSION'" | |
+ cat "$SERVICES_DIR/$SERVICE$SERVICE_EXTENSION" | sed -e "s/%PREFIX_DIRECTORY%/${PREFIX_DIR//\//\\/}/" | tee "$DEST_DIR/lib/systemd/system/$SERVICE$SERVICE_EXTENSION" > "/dev/null" | |
done | |
# add program services sub-configurations based on the sub-configurations present in the './services' folder | |
@@ -145,18 +155,20 @@ | |
echo "adding sub-configurations for [$SERVICE]" | |
SUBCONFIG_FOLDERS="$(cd "$SERVICES_DIR/$SERVICE" && find . -mindepth 1 -maxdepth 1 -type d -exec basename {} \;)" | |
# ensure folders exists | |
+ echo "creating '$DEST_DIR/lib/systemd/$SERVICE'" | |
+ mkdir -p "$DEST_DIR/lib/systemd/$SERVICE" | |
for SUBCONFIG_FOLDER in $SUBCONFIG_FOLDERS ; do | |
SUBCONFIG_FOLDER=$(sanitizePath "$SUBCONFIG_FOLDER") | |
- echo "creating '$PREFIX_DIR/lib/systemd/$SERVICE/$SUBCONFIG_FOLDER'" | |
- (cd "$PREFIX_DIR/lib/systemd/" && cd "$SERVICE" && mkdir -p "$SUBCONFIG_FOLDER") | |
+ echo "creating '$DEST_DIR/lib/systemd/$SERVICE/$SUBCONFIG_FOLDER'" | |
+ (cd "$DEST_DIR/lib/systemd/" && cd "$SERVICE" && mkdir -p "$SUBCONFIG_FOLDER") | |
done | |
SUBCONFIGS="$(cd "$SERVICES_DIR/$SERVICE" && find . -mindepth 1 -type f)" | |
# add sub-configurations | |
for SUBCONFIG in $SUBCONFIGS ; do | |
SUBCONFIG=$(sanitizePath "$SUBCONFIG") | |
- echo "adding '$PREFIX_DIR/lib/systemd/$SERVICE/$SUBCONFIG'" | |
- cat "$SERVICES_DIR/$SERVICE/$SUBCONFIG" | sed -e "s/%PREFIX_DIRECTORY%/${PREFIX_DIR//\//\\/}/" | tee "$PREFIX_DIR/lib/systemd/$SERVICE/$SUBCONFIG" > "/dev/null" | |
- chmod +x "$PREFIX_DIR/lib/systemd/$SERVICE/$SUBCONFIG" | |
+ echo "adding '$DEST_DIR/lib/systemd/$SERVICE/$SUBCONFIG'" | |
+ cat "$SERVICES_DIR/$SERVICE/$SUBCONFIG" | sed -e "s/%PREFIX_DIRECTORY%/${PREFIX_DIR//\//\\/}/" | tee "$DEST_DIR/lib/systemd/$SERVICE/$SUBCONFIG" > "/dev/null" | |
+ chmod +x "$DEST_DIR/lib/systemd/$SERVICE/$SUBCONFIG" | |
done | |
done | |
if [ "$SHOULD_POST_INSTALL" = true ]; then |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment