Updated the installer to setup the service as qu, added some improvements to the installation
This commit is contained in:
+33
-21
@@ -1,4 +1,5 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
# Helper function which echo's all commands before executing them in grayscale prefixed with >
|
# Helper function which echo's all commands before executing them in grayscale prefixed with >
|
||||||
echo_cmd() {
|
echo_cmd() {
|
||||||
@@ -6,6 +7,11 @@ echo_cmd() {
|
|||||||
eval "$1"
|
eval "$1"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
INSTALL_BIN="/usr/local/bin/qu"
|
||||||
|
SERVICE_FILE="/etc/systemd/system/qu.service"
|
||||||
|
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
|
# Check if jq and curl are installed, if not, error out and ask the user to install them
|
||||||
if ! command -v jq > /dev/null; then
|
if ! command -v jq > /dev/null; then
|
||||||
echo "Error: jq is not installed. Please install jq and try again."
|
echo "Error: jq is not installed. Please install jq and try again."
|
||||||
@@ -17,7 +23,7 @@ if ! command -v curl > /dev/null; then
|
|||||||
fi
|
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
|
# 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 "/usr/local/bin" ]; then
|
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')
|
# 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')
|
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
|
# Download the latest release binary from the Git repository and save it to /usr/local/bin/qu
|
||||||
@@ -29,20 +35,24 @@ if [ -w "/usr/local/bin" ]; then
|
|||||||
# Drop completions into the directories each shell already scans.
|
# Drop completions into the directories each shell already scans.
|
||||||
# No rc-file edits, and uninstall is just `rm`. Silently skips
|
# No rc-file edits, and uninstall is just `rm`. Silently skips
|
||||||
# shells whose completion dir is absent.
|
# shells whose completion dir is absent.
|
||||||
write_completion() {
|
if "$INSTALL_BIN" --help 2>/dev/null | grep -q "completion"; then
|
||||||
local shell=$1 path=$2
|
write_completion() {
|
||||||
[ -d "$(dirname "$path")" ] || return 1
|
local shell=$1 path=$2
|
||||||
if /usr/local/bin/qu completion "$shell" > "$path" 2>/dev/null; then
|
[ -d "$(dirname "$path")" ] || return 1
|
||||||
echo "> installed $shell completion -> $path"
|
if "$INSTALL_BIN" completion "$shell" > "$path" 2>/dev/null; then
|
||||||
return 0
|
echo "> installed $shell completion -> $path"
|
||||||
fi
|
return 0
|
||||||
rm -f "$path"
|
fi
|
||||||
return 1
|
rm -f "$path"
|
||||||
}
|
return 1
|
||||||
write_completion bash /usr/share/bash-completion/completions/qu \
|
}
|
||||||
|| write_completion bash /etc/bash_completion.d/qu
|
write_completion bash /usr/share/bash-completion/completions/qu \
|
||||||
write_completion zsh /usr/share/zsh/site-functions/_qu
|
|| write_completion bash /etc/bash_completion.d/qu
|
||||||
write_completion fish /usr/share/fish/vendor_completions.d/qu.fish
|
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
|
||||||
else
|
else
|
||||||
echo "Error: curl is not installed. Please install curl and try again."
|
echo "Error: curl is not installed. Please install curl and try again."
|
||||||
exit 1
|
exit 1
|
||||||
@@ -55,24 +65,26 @@ fi
|
|||||||
# Check if the user has systemd, if so create a systemd service file for qu serve
|
# Check if the user has systemd, if so create a systemd service file for qu serve
|
||||||
if command -v systemctl > /dev/null; then
|
if command -v systemctl > /dev/null; then
|
||||||
echo "> Creating systemd service file for qu serve..."
|
echo "> Creating systemd service file for qu serve..."
|
||||||
cat <<EOL > /etc/systemd/system/qu-serve.service
|
|
||||||
|
cat <<EOL > "$SERVICE_FILE"
|
||||||
[Unit]
|
[Unit]
|
||||||
Description=QUptime Serve
|
Description=QUptime Serve
|
||||||
After=network.target
|
After=network.target
|
||||||
|
|
||||||
[Service]
|
[Service]
|
||||||
ExecStart=/usr/local/bin/qu serve
|
ExecStart=$INSTALL_BIN serve
|
||||||
Restart=always
|
Restart=always
|
||||||
User=$(whoami)
|
User=$SERVICE_USER
|
||||||
|
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 qu-serve.service"
|
echo_cmd "systemctl enable $(basename "$SERVICE_FILE")"
|
||||||
echo "> qu serve service has been created and enabled. You can start it with 'systemctl start qu-serve.service'"
|
echo "> qu serve service has been created and enabled. You can start it with 'systemctl start $(basename "$SERVICE_FILE")'"
|
||||||
else
|
else
|
||||||
echo "> Warning: systemd is not available on this system. qu serve will not be automatically started on boot. You can start it manually with '/usr/local/bin/qu serve'"
|
echo "> Warning: systemd is not available on this system. qu serve will not be automatically started on boot. You can start it manually with '$INSTALL_BIN serve'"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
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