Update install.sh
This commit is contained in:
35
install.sh
35
install.sh
@@ -1,33 +1,24 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
|
|
||||||
PREFIX_BIN="/usr/local/bin"
|
BIN_DIR="/usr/local/bin"
|
||||||
SYSTEMD_DIR="/etc/systemd/system"
|
SYSTEMD_DIR="/etc/systemd/system"
|
||||||
|
|
||||||
|
SCRIPT_NAME="killsw"
|
||||||
|
TARGET_NAME="killswitch.target"
|
||||||
|
|
||||||
|
# assume running from repo root
|
||||||
REPO_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
REPO_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||||
|
|
||||||
main_script="$(find "$REPO_DIR" -maxdepth 1 -type f -name "killswitch*" ! -name "*.target" | head -n 1)"
|
# install binary
|
||||||
target_file="$(find "$REPO_DIR" -maxdepth 1 -type f -name "*.target" | head -n 1)"
|
install -m 755 "$REPO_DIR/$SCRIPT_NAME" "$BIN_DIR/$SCRIPT_NAME"
|
||||||
|
|
||||||
if [[ -z "${main_script:-}" ]]; then
|
# install systemd target
|
||||||
echo "main script not found"
|
install -m 644 "$REPO_DIR/$TARGET_NAME" "$SYSTEMD_DIR/$TARGET_NAME"
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [[ -z "${target_file:-}" ]]; then
|
# reload systemd daemon
|
||||||
echo "systemd target not found"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo "installing cli"
|
|
||||||
install -m 755 "$main_script" "$PREFIX_BIN/$(basename "$main_script")"
|
|
||||||
|
|
||||||
echo "installing systemd target"
|
|
||||||
install -m 644 "$target_file" "$SYSTEMD_DIR/$(basename "$target_file")"
|
|
||||||
|
|
||||||
echo "reloading systemd"
|
|
||||||
systemctl daemon-reload
|
systemctl daemon-reload
|
||||||
|
|
||||||
echo "done"
|
echo "Installation complete."
|
||||||
echo "binary: $PREFIX_BIN/$(basename "$main_script")"
|
echo "CLI: $BIN_DIR/$SCRIPT_NAME"
|
||||||
echo "target: $SYSTEMD_DIR/$(basename "$target_file")"
|
echo "Systemd target: $SYSTEMD_DIR/$TARGET_NAME"
|
||||||
Reference in New Issue
Block a user