add files
This commit is contained in:
@@ -0,0 +1,87 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -e
|
||||
|
||||
echo "===> Starting CLIProxyAPI setup..."
|
||||
|
||||
# ===== CONFIG =====
|
||||
REPO_API="https://api.github.com/repos/router-for-me/CLIProxyAPI/releases/latest"
|
||||
TMP_DIR=$(mktemp -d)
|
||||
CURRENT_DIR=$(pwd)
|
||||
SERVICE_NAME="cliproxyapi.service"
|
||||
SYSTEMD_USER_DIR="$HOME/.config/systemd/user"
|
||||
BINARY_NAME="cli-proxy-api"
|
||||
|
||||
# ===== STEP 1: DOWNLOAD & EXTRACT =====
|
||||
echo "===> Fetching latest release info..."
|
||||
DOWNLOAD_URL=$(curl -s $REPO_API | grep "browser_download_url" | grep "linux_aarch64.tar.gz" | cut -d '"' -f 4)
|
||||
|
||||
if [ -z "$DOWNLOAD_URL" ]; then
|
||||
echo "❌ Cannot find linux_aarch64.tar.gz in release"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "===> Downloading: $DOWNLOAD_URL"
|
||||
wget -qO "$TMP_DIR/package.tar.gz" "$DOWNLOAD_URL"
|
||||
|
||||
echo "===> Extracting..."
|
||||
tar -xzf "$TMP_DIR/package.tar.gz" -C "$TMP_DIR"
|
||||
|
||||
# Find binary
|
||||
BIN_PATH=$(find "$TMP_DIR" -type f -name "$BINARY_NAME" | head -n 1)
|
||||
|
||||
if [ ! -f "$BIN_PATH" ]; then
|
||||
echo "❌ cli-proxy-api binary not found after extract"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "===> Copying binary to current directory..."
|
||||
cp "$BIN_PATH" "$CURRENT_DIR/"
|
||||
chmod +x "$CURRENT_DIR/$BINARY_NAME"
|
||||
|
||||
echo "===> Cleaning up..."
|
||||
rm -rf "$TMP_DIR"
|
||||
|
||||
# ===== STEP 2: SETUP SYSTEMD USER SERVICE =====
|
||||
|
||||
mkdir -p "$SYSTEMD_USER_DIR"
|
||||
|
||||
SERVICE_PATH="$SYSTEMD_USER_DIR/$SERVICE_NAME"
|
||||
|
||||
if [ -f "$SERVICE_PATH" ]; then
|
||||
echo "===> Service already exists, restarting..."
|
||||
|
||||
systemctl --user daemon-reload
|
||||
systemctl --user restart "$SERVICE_NAME"
|
||||
|
||||
else
|
||||
echo "===> Creating new systemd user service..."
|
||||
|
||||
cat > "$SERVICE_PATH" <<EOF
|
||||
[Unit]
|
||||
Description=CLIProxyAPI Service
|
||||
After=network.target
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
WorkingDirectory=$CURRENT_DIR
|
||||
ExecStart=$CURRENT_DIR/$BINARY_NAME
|
||||
Restart=always
|
||||
RestartSec=10
|
||||
Environment=HOME=$HOME
|
||||
|
||||
[Install]
|
||||
WantedBy=default.target
|
||||
EOF
|
||||
|
||||
echo "===> Reloading systemd..."
|
||||
systemctl --user daemon-reload
|
||||
|
||||
echo "===> Enabling service..."
|
||||
systemctl --user enable "$SERVICE_NAME"
|
||||
|
||||
echo "===> Starting service..."
|
||||
systemctl --user start "$SERVICE_NAME"
|
||||
fi
|
||||
|
||||
echo "===> Done!"
|
||||
Reference in New Issue
Block a user