Created
April 10, 2023 16:23
-
-
Save carlhannes/0e26d5af20d7b19dd1e2831a7fd98f16 to your computer and use it in GitHub Desktop.
Install boringproxy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Check if the user is root | |
if [[ $EUID -ne 0 ]]; then | |
echo "This script must be run as root" | |
exit 1 | |
fi | |
# Create user and usergroup | |
groupadd -f boringproxy | |
useradd -m -s /bin/bash -g boringproxy boringproxy | |
# Set up home directory and permissions | |
home_dir="/home/boringproxy" | |
ssh_dir="${home_dir}/.ssh" | |
chown boringproxy:boringproxy ${home_dir} | |
chmod 700 ${home_dir} | |
# Set up SSH directory and permissions | |
mkdir -p ${ssh_dir} | |
chown boringproxy:boringproxy ${ssh_dir} | |
chmod 700 ${ssh_dir} | |
# Determine the architecture | |
case "$(uname -s)-$(uname -m)" in | |
"Linux-x86_64") arch="linux-x86_64" ;; | |
"Linux-armv7l") arch="linux-arm" ;; | |
"Linux-aarch64") arch="linux-arm64" ;; | |
"Darwin-x86_64") arch="darwin-x86_64" ;; | |
"Darwin-arm64") arch="darwin-arm64" ;; | |
"FreeBSD-i386") arch="freebsd-386" ;; | |
"FreeBSD-amd64") arch="freebsd-x86_64" ;; | |
"OpenBSD-i386") arch="openbsd-386" ;; | |
"OpenBSD-amd64") arch="openbsd-x86_64" ;; | |
*) echo "Unsupported platform"; exit 1 ;; | |
esac | |
# Download the executable | |
executable_url="https://github.com/boringproxy/boringproxy/releases/download/v0.10.0/boringproxy-${arch}" | |
executable_path="${home_dir}/boringproxy" | |
curl -L -o ${executable_path} ${executable_url} | |
chown boringproxy:boringproxy ${executable_path} | |
chmod 700 ${executable_path} | |
# Allow binding to privileged ports | |
setcap cap_net_bind_service=+ep ${executable_path} | |
# Get user input | |
read -p "Enter Server: " server | |
read -p "Enter User: " user | |
read -p "Enter Token: " token | |
read -p "Enter Client-name: " client_name | |
# Write start-boringproxy.sh | |
start_script="${home_dir}/start-boringproxy.sh" | |
cat > ${start_script} << EOL | |
#!/bin/bash | |
${executable_path} client \\ | |
-server ${server} -user ${user} -token ${token} -client-name ${client_name} | |
EOL | |
chown boringproxy:boringproxy ${start_script} | |
chmod 700 ${start_script} | |
# Create systemd service | |
systemd_service="/etc/systemd/system/boringproxy.service" | |
cat > ${systemd_service} << EOL | |
[Unit] | |
Description=Boringproxy | |
After=network.target | |
[Service] | |
User=boringproxy | |
Group=boringproxy | |
WorkingDirectory=${home_dir} | |
ExecStart=${start_script} | |
Restart=always | |
[Install] | |
WantedBy=multi-user.target | |
EOL | |
# Enable and start the systemd service | |
systemctl enable boringproxy | |
systemctl start boringproxy | |
echo "Boringproxy setup complete!" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment