I have spent more time on the installation script than I would've wanted to
This commit is contained in:
+51
-47
@@ -1,63 +1,66 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
|
|
||||||
# Helper function which echo's all commands before executing them in grayscale prefixed with >
|
INSTALL_BIN="/usr/local/bin/qu"
|
||||||
|
SERVICE_FILE="/etc/systemd/system/qu-serve.service"
|
||||||
|
SERVICE_USER="${SUDO_USER:-$(whoami)}"
|
||||||
|
SERVICE_GROUP="$(id -gn "$SERVICE_USER" 2>/dev/null || echo root)"
|
||||||
|
|
||||||
|
fail() {
|
||||||
|
echo "Error: $*" >&2
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
echo_cmd() {
|
echo_cmd() {
|
||||||
echo -e "\033[90m> $1\033[0m"
|
echo -e "\033[90m> $1\033[0m"
|
||||||
eval "$1"
|
eval "$1"
|
||||||
}
|
}
|
||||||
|
|
||||||
INSTALL_BIN="/usr/local/bin/qu"
|
require_command() {
|
||||||
SERVICE_FILE="/etc/systemd/system/qu.service"
|
command -v "$1" > /dev/null 2>&1 || fail "$1 is not installed. Please install $1 and try again."
|
||||||
SERVICE_USER="${SUDO_USER:-$(whoami)}"
|
}
|
||||||
SERVICE_GROUP="$(id -gn "$SERVICE_USER" 2>/dev/null || echo root)"
|
|
||||||
|
|
||||||
# Check if jq and curl are installed, if not, error out and ask the user to install them
|
write_completion() {
|
||||||
if ! command -v jq > /dev/null; then
|
local shell=$1 path=$2
|
||||||
echo "Error: jq is not installed. Please install jq and try again."
|
[ -d "$(dirname "$path")" ] || return 1
|
||||||
exit 1
|
if "$INSTALL_BIN" completion "$shell" > "$path" 2>/dev/null; then
|
||||||
fi
|
echo "> installed $shell completion -> $path"
|
||||||
if ! command -v curl > /dev/null; then
|
return 0
|
||||||
echo "Error: curl is not installed. Please install curl and try again."
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Check if the user is allowed to write to /usr/local/bin, if so, install qu there, else error out and ask the user to install qu manually
|
|
||||||
if [ -w "$(dirname "$INSTALL_BIN")" ]; then
|
|
||||||
# Get release tag by $(curl -s https://git.cer.sh/api/v1/repos/axodouble/quptime/releases/latest | jq -r '.tag_name')
|
|
||||||
RELEASE=$(curl -s https://git.cer.sh/api/v1/repos/axodouble/quptime/releases/latest | jq -r '.tag_name')
|
|
||||||
# Download the latest release binary from the Git repository and save it to /usr/local/bin/qu
|
|
||||||
|
|
||||||
echo_cmd "curl -L -o \"/usr/local/bin/qu\" \"https://git.cer.sh/axodouble/quptime/releases/download/${RELEASE}/qu-${RELEASE}-linux-amd64\""
|
|
||||||
echo_cmd "chmod +x \"/usr/local/bin/qu\""
|
|
||||||
echo "> qu has been installed to /usr/local/bin/qu"
|
|
||||||
|
|
||||||
if "$INSTALL_BIN" --help 2>/dev/null | grep -q "completion"; then
|
|
||||||
write_completion() {
|
|
||||||
local shell=$1 path=$2
|
|
||||||
[ -d "$(dirname "$path")" ] || return 1
|
|
||||||
if "$INSTALL_BIN" completion "$shell" > "$path" 2>/dev/null; then
|
|
||||||
echo "> installed $shell completion -> $path"
|
|
||||||
return 0
|
|
||||||
fi
|
|
||||||
rm -f "$path"
|
|
||||||
return 1
|
|
||||||
}
|
|
||||||
write_completion bash /usr/share/bash-completion/completions/qu \
|
|
||||||
|| write_completion bash /etc/bash_completion.d/qu
|
|
||||||
write_completion zsh /usr/share/zsh/site-functions/_qu
|
|
||||||
write_completion fish /usr/share/fish/vendor_completions.d/qu.fish
|
|
||||||
else
|
|
||||||
echo "> qu does not expose completion support; skipping shell completion installation."
|
|
||||||
fi
|
fi
|
||||||
|
rm -f "$path"
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
|
require_command jq
|
||||||
|
require_command curl
|
||||||
|
|
||||||
|
if [ ! -w "$(dirname "$INSTALL_BIN")" ]; then
|
||||||
|
fail "You are not allowed to write to $(dirname "$INSTALL_BIN"). Run this script with sudo or install qu manually."
|
||||||
|
fi
|
||||||
|
|
||||||
|
RELEASE=$(curl -s https://git.cer.sh/api/v1/repos/axodouble/quptime/releases/latest | jq -r '.tag_name')
|
||||||
|
|
||||||
|
echo_cmd "curl -L -o '$INSTALL_BIN' 'https://git.cer.sh/axodouble/quptime/releases/download/${RELEASE}/qu-${RELEASE}-linux-amd64'"
|
||||||
|
echo_cmd "chmod +x '$INSTALL_BIN'"
|
||||||
|
echo "> qu has been installed to $INSTALL_BIN"
|
||||||
|
|
||||||
|
if "$INSTALL_BIN" --help 2>/dev/null | grep -q "completion"; then
|
||||||
|
write_completion bash /usr/share/bash-completion/completions/qu \
|
||||||
|
|| write_completion bash /etc/bash_completion.d/qu
|
||||||
|
write_completion zsh /usr/share/zsh/site-functions/_qu
|
||||||
|
write_completion fish /usr/share/fish/vendor_completions.d/qu.fish
|
||||||
else
|
else
|
||||||
echo "Error: You are not allowed to write to /usr/local/bin. Please install qu manually, or run this script with sudo."
|
echo "> qu does not expose completion support; skipping shell completion installation."
|
||||||
exit 1
|
fi
|
||||||
|
|
||||||
|
if ! command -v systemctl > /dev/null 2>&1; then
|
||||||
|
echo "> Warning: systemd is not available on this system. qu serve will not be automatically started on boot."
|
||||||
|
echo "Installation complete, before starting qu serve, make sure to run qu init and read the documentation."
|
||||||
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "> Creating systemd service file for qu serve..."
|
echo "> Creating systemd service file for qu serve..."
|
||||||
|
cat > "$SERVICE_FILE" <<EOL
|
||||||
cat <<EOL > "$SERVICE_FILE"
|
|
||||||
[Unit]
|
[Unit]
|
||||||
Description=QUptime Serve
|
Description=QUptime Serve
|
||||||
After=network.target
|
After=network.target
|
||||||
@@ -71,8 +74,9 @@ Group=$SERVICE_GROUP
|
|||||||
[Install]
|
[Install]
|
||||||
WantedBy=multi-user.target
|
WantedBy=multi-user.target
|
||||||
EOL
|
EOL
|
||||||
|
|
||||||
echo_cmd "systemctl daemon-reload"
|
echo_cmd "systemctl daemon-reload"
|
||||||
echo_cmd "systemctl enable $(basename "$SERVICE_FILE")"
|
echo_cmd "systemctl enable $(basename "$SERVICE_FILE")"
|
||||||
echo "> qu serve service has been created and enabled. You can start it with 'systemctl start $(basename "$SERVICE_FILE")'"
|
echo "> qu serve service has been created and enabled. You can start it with 'systemctl start $(basename "$SERVICE_FILE")'"
|
||||||
|
|
||||||
echo "Installation complete, before starting `qu serve`, make sure to run `qu init` and read the documentation."
|
echo "Installation complete, before starting qu serve, make sure to run qu init and read the documentation."
|
||||||
|
|||||||
Reference in New Issue
Block a user