Skip to content

Instantly share code, notes, and snippets.

@sarkrui
Last active November 1, 2023 02:41
Show Gist options
  • Save sarkrui/7eaf1d363dedd47aa555a4d3420b8e81 to your computer and use it in GitHub Desktop.
Save sarkrui/7eaf1d363dedd47aa555a4d3420b8e81 to your computer and use it in GitHub Desktop.
#!/bin/bash
# Function to fetch a specific or latest release from GitHub
fetch_release() {
if [ -z "$1" ]; then
echo "Fetching the latest release..."
echo $(curl -s https://api.github.com/repos/rapiz1/rathole/releases/latest | grep "browser_download_url.*$FILE_NAME" | cut -d '"' -f 4)
else
echo "Fetching the release for tag $1..."
echo $(curl -s https://api.github.com/repos/rapiz1/rathole/releases/tags/$1 | grep "browser_download_url.*$FILE_NAME" | cut -d '"' -f 4)
fi
}
# Identify architecture
ARCH=$(uname -m)
# Map architecture to rathole's naming convention
case $ARCH in
x86_64)
FILE_NAME="rathole-x86_64-unknown-linux-gnu.zip"
;;
aarch64)
FILE_NAME="rathole-aarch64-unknown-linux-musl.zip"
;;
arm)
FILE_NAME="rathole-arm-unknown-linux-musleabi.zip"
;;
armhf)
FILE_NAME="rathole-arm-unknown-linux-musleabihf.zip"
;;
armv7l)
FILE_NAME="rathole-armv7-unknown-linux-musleabihf.zip"
;;
mips)
FILE_NAME="rathole-mips-unknown-linux-gnu.zip"
;;
mips64)
FILE_NAME="rathole-mips64-unknown-linux-gnuabi64.zip"
;;
mipsel)
FILE_NAME="rathole-mipsel-unknown-linux-gnu.zip"
;;
*)
echo "Unsupported architecture."
exit 1
;;
esac
# Fetch the release
if [ -z "$1" ]; then
URL=$(fetch_release)
else
URL=$(fetch_release $1)
fi
# Check if URL is empty (which means release not found)
if [ -z "$URL" ]; then
echo "Release not found."
exit 1
fi
# Download the version
curl -L $URL -o /tmp/$FILE_NAME
# Unzip the downloaded file
unzip /tmp/$FILE_NAME -d /tmp/rathole-latest/
# Move the unzipped files to /usr/bin
mv /tmp/rathole-latest/* /usr/bin/
# Check if /etc/rathole/server.toml exists
if [ ! -d "/etc/rathole" ]; then
mkdir /etc/rathole
fi
if [ ! -f "/etc/rathole/server.toml" ]; then
touch /etc/rathole/server.toml
fi
# Clean up
rm -r /tmp/rathole-latest/ /tmp/$FILE_NAME
echo "Installation completed."
@sarkrui
Copy link
Author

sarkrui commented Oct 31, 2023

One-click Installation

bash -c "$(curl -fsSL https://gist.githubusercontent.com/sarkrui/7eaf1d363dedd47aa555a4d3420b8e81/raw/0f0bcea7037c95078f04946dd257fd3a90161d76/install-rathole.sh)"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment