Skip to content

Commit

Permalink
Add install and unistall script
Browse files Browse the repository at this point in the history
  • Loading branch information
K-cermak committed Feb 2, 2025
1 parent 08ea3fb commit b69458f
Show file tree
Hide file tree
Showing 4 changed files with 111 additions and 2 deletions.
75 changes: 73 additions & 2 deletions scripts/installer.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,3 +1,74 @@
#!/bin/bash

# TODO
## Tip: If you cannot run this script, try running `chmod +x installer.sh`

set -e

INSTALL_DIR="/opt/kprobe"
CLI_BINARY="../bin/cli"
API_SERVER_BINARY="../bin/api-server"
WEB_EDITOR_FILE="../web-editor/editor.html"
SERVICE_FILE="/etc/systemd/system/kprobe.service"
CURRENT_USER=$(logname)


if [[ $EUID -ne 0 ]]; then
echo "This script must be run as root" >&2
exit 1
fi

echo "Are you sure you want to install Uptime Kuma Probe Extension? [y/N]"
read -r CONFIRMATION
if [[ "$CONFIRMATION" != "y" ]]; then
echo "Installation cancelled"
exit 1
fi


echo "Installing Uptime Kuma Probe Extension"
if [[ -d "$INSTALL_DIR" ]]; then
echo "ERROR: Uptime Kuma Probe Extension is already installed. If you want to reinstall, please ruzn uninstaller.sh first"
exit 1
fi


mkdir -p "$INSTALL_DIR"
chown "$CURRENT_USER":"$CURRENT_USER" "$INSTALL_DIR"
chmod 755 "$INSTALL_DIR"

cp "$CLI_BINARY" "$INSTALL_DIR/cli"
cp "$API_SERVER_BINARY" "$INSTALL_DIR/api-server"
cp "$WEB_EDITOR_FILE" "$INSTALL_DIR/editor.html"

chown "$CURRENT_USER":"$CURRENT_USER" "$INSTALL_DIR/cli"
chmod 755 "$INSTALL_DIR/cli"
chown root:root "$INSTALL_DIR/api-server"
chmod 755 "$INSTALL_DIR/api-server"
chown "$CURRENT_USER":"$CURRENT_USER" "$INSTALL_DIR/editor.html"
chmod 644 "$INSTALL_DIR/editor.html"


echo "Creating symlink for kprobe CLI"
ln -s "$INSTALL_DIR/cli" "/usr/local/bin/kprobe"


echo "Setting up API Server as a service"
cat <<EOF > "$SERVICE_FILE"
[Unit]
Description=KProbe API Server
After=network.target
[Service]
ExecStart=$INSTALL_DIR/api-server
Restart=always
User=root
WorkingDirectory=$INSTALL_DIR
[Install]
WantedBy=multi-user.target
EOF

systemctl daemon-reload
systemctl enable kprobe.service
systemctl start kprobe.service

echo "[SUCCESS] Uptime Kuma Probe Extension has been installed successfully, you can now run 'kprobe' command to start the CLI"
Empty file modified scripts/linux-compiler.sh
100644 → 100755
Empty file.
38 changes: 38 additions & 0 deletions scripts/unistaller.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/bin/bash
## If you cannot run, try running `chmod +x uninstaller.sh`

set -e

INSTALL_DIR="/opt/kprobe"
CLI_BINARY="$INSTALL_DIR/cli"
API_SERVER_BINARY="$INSTALL_DIR/api-server"
WEB_EDITOR_FILE="$INSTALL_DIR/editor.html"
SERVICE_FILE="/etc/systemd/system/kprobe.service"
SYMLINK="/usr/local/bin/kprobe"
CURRENT_USER=$(logname)


if [[ $EUID -ne 0 ]]; then
echo "This script must be run as root" >&2
exit 1
fi

echo "Are you sure you want to uninstall Uptime Kuma Probe Extension? [y/N]"
read -r CONFIRMATION
if [[ "$CONFIRMATION" != "y" ]]; then
echo "Uninstallation cancelled"
exit 1
fi

echo "Uninstalling Uptime Kuma Probe Extension"

systemctl stop kprobe.service
systemctl disable kprobe.service

rm -f "$SERVICE_FILE"

rm -f "$SYMLINK"

rm -rf "$INSTALL_DIR"

echo "[SUCCESS] Uptime Kuma Probe Extension has been uninstalled successfully"
Empty file modified scripts/windows-compiler.bat
100644 → 100755
Empty file.

0 comments on commit b69458f

Please sign in to comment.