mirror of
https://github.com/kiddin9/op-packages.git
synced 2026-10-31 22:25:13 +08:00
80 lines
2.3 KiB
Bash
Executable File
80 lines
2.3 KiB
Bash
Executable File
#!/bin/sh
|
|
# Tailscale update helper script
|
|
|
|
ARCH=$(uname -m)
|
|
case "$ARCH" in
|
|
x86_64|amd64) TS_ARCH="amd64" ;;
|
|
aarch64|arm64) TS_ARCH="arm64" ;;
|
|
armv7l) TS_ARCH="arm" ;;
|
|
*) echo '{"error":"unsupported architecture: '$ARCH'"}'; exit 1 ;;
|
|
esac
|
|
|
|
get_current_version() {
|
|
if [ -x /usr/sbin/tailscale ]; then
|
|
/usr/sbin/tailscale version 2>/dev/null | head -1 | tr -d '\n'
|
|
else
|
|
echo "not installed"
|
|
fi
|
|
}
|
|
|
|
check_update() {
|
|
CURRENT=$( get_current_version )
|
|
LATEST=$( wget -qO- "https://api.github.com/repos/tailscale/tailscale/releases/latest" 2>/dev/null | \
|
|
grep '"tag_name"' | sed 's/.*"v\([^"]*\)".*/\1/' )
|
|
if [ -z "$LATEST" ]; then
|
|
echo "{\"current\":\"$CURRENT\",\"latest\":\"unknown\",\"error\":\"failed to fetch latest version\"}"
|
|
else
|
|
echo "{\"current\":\"$CURRENT\",\"latest\":\"$LATEST\"}"
|
|
fi
|
|
}
|
|
|
|
do_update() {
|
|
LATEST=$( wget -qO- "https://api.github.com/repos/tailscale/tailscale/releases/latest" 2>/dev/null | \
|
|
grep '"tag_name"' | sed 's/.*"v\([^"]*\)".*/\1/' )
|
|
if [ -z "$LATEST" ]; then
|
|
echo '{"error":"failed to fetch latest version"}'
|
|
exit 1
|
|
fi
|
|
|
|
URL="https://pkgs.tailscale.com/stable/tailscale_${LATEST}_${TS_ARCH}.tgz"
|
|
TMP_DIR="/tmp/tailscale_update"
|
|
rm -rf "$TMP_DIR"
|
|
mkdir -p "$TMP_DIR"
|
|
|
|
wget -qO "$TMP_DIR/tailscale.tgz" "$URL" 2>/dev/null
|
|
if [ ! -s "$TMP_DIR/tailscale.tgz" ]; then
|
|
echo "{\"error\":\"download failed: $URL\"}"
|
|
rm -rf "$TMP_DIR"
|
|
exit 1
|
|
fi
|
|
|
|
tar -xzf "$TMP_DIR/tailscale.tgz" -C "$TMP_DIR" 2>/dev/null
|
|
EXTRACT_DIR="$TMP_DIR/tailscale_${LATEST}_${TS_ARCH}"
|
|
|
|
if [ ! -f "$EXTRACT_DIR/tailscale" ] || [ ! -f "$EXTRACT_DIR/tailscaled" ]; then
|
|
echo '{"error":"extracted files not found"}'
|
|
rm -rf "$TMP_DIR"
|
|
exit 1
|
|
fi
|
|
|
|
/etc/init.d/tailscale stop 2>/dev/null
|
|
sleep 1
|
|
|
|
cp "$EXTRACT_DIR/tailscale" /usr/sbin/tailscale
|
|
cp "$EXTRACT_DIR/tailscaled" /usr/sbin/tailscaled
|
|
chmod +x /usr/sbin/tailscale /usr/sbin/tailscaled
|
|
|
|
/etc/init.d/tailscale start 2>/dev/null
|
|
|
|
rm -rf "$TMP_DIR"
|
|
|
|
NEW_VER=$( get_current_version )
|
|
echo "{\"success\":true,\"version\":\"$NEW_VER\"}"
|
|
}
|
|
|
|
case "$1" in
|
|
check_update) check_update ;;
|
|
do_update) do_update ;;
|
|
*) echo '{"error":"usage: tailscale_helper check_update|do_update"}' ;;
|
|
esac
|