|
| 1 | +#!/bin/bash |
| 2 | +# Installer by thcrt |
| 3 | +# Licensed under the MIT license |
| 4 | +set -eu |
| 5 | +IFS=$'\n\t' |
| 6 | + |
| 7 | + |
| 8 | + |
| 9 | +# Temporary working directory |
| 10 | +TEMP_DIR="${HOME}/.tmp/microsocks" |
| 11 | +# Path of executable once installed |
| 12 | +BIN_PATH="${HOME}/.local/bin/microsocks" |
| 13 | +# Port to listen on |
| 14 | +PORT=$(comm -23 <(seq 10000 20000 | sort) <(ss -Htan | awk '{print $4}' | cut -d':' -f2 | sort -u) | shuf | head -n 1) |
| 15 | +# Password to connect with |
| 16 | +PASS=$(tr -dc A-Za-z0-9 </dev/urandom | head -c 16) |
| 17 | +# Service file location |
| 18 | +SERVICE_PATH="$HOME/.config/systemd/user/microsocks.service" |
| 19 | + |
| 20 | + |
| 21 | + |
| 22 | +function _install() { |
| 23 | + # Give a warning |
| 24 | + echo "### WARNING ########################################################################################" |
| 25 | + echo "# #" |
| 26 | + echo "# The application you're about to install is unsupported by your hosting provider! Support, #" |
| 27 | + echo "# functionality, and security aren't guaranteed and will be entirely your own responsibility. #" |
| 28 | + echo "# You should only proceed with this installation if you know what you're doing. #" |
| 29 | + echo "# #" |
| 30 | + echo "# #" |
| 31 | + echo "# Type 'yes' and press enter if you understand and wish to continue. #" |
| 32 | + echo "# #" |
| 33 | + echo "####################################################################################################" |
| 34 | + read -r -p "=> " |
| 35 | + echo "" |
| 36 | + if ! [[ $REPLY =~ "yes" ]]; then |
| 37 | + echo "Exiting installation!" |
| 38 | + exit 1 |
| 39 | + else |
| 40 | + echo "Proceeding with installation!" |
| 41 | + fi |
| 42 | + |
| 43 | + # Ensure all standard directories exist |
| 44 | + mkdir -p "${TEMP_DIR}" |
| 45 | + mkdir -p "${HOME}/.local/bin" |
| 46 | + mkdir -p "${HOME}/.config/systemd/user" |
| 47 | + |
| 48 | + # Download and install binary |
| 49 | + echo -ne "[1/7] Downloading microsocks...\r" |
| 50 | + curl -sL "https://github.com/rofl0r/microsocks/archive/refs/tags/v1.0.4.tar.gz" -o "${TEMP_DIR}/microsocks.tar.gz" |
| 51 | + echo -ne "[2/7] Extracting...\r" |
| 52 | + tar xf "${TEMP_DIR}/microsocks.tar.gz" --directory "${TEMP_DIR}" --strip-components=1 |
| 53 | + echo -ne "[3/7] Compiling from source...\r" |
| 54 | + make --directory "${TEMP_DIR}" >/dev/null 2>&1 |
| 55 | + echo -ne "[4/7] Moving into place... \r" |
| 56 | + mv "${TEMP_DIR}/microsocks" "${BIN_PATH}" |
| 57 | + echo -ne "[5/7] Cleaning up...\r" |
| 58 | + rm -rf "${TEMP_DIR}" |
| 59 | + |
| 60 | + # Set up the service |
| 61 | + echo -ne "[6/7] Creating service file...\r" |
| 62 | + cat > "${SERVICE_PATH}" << EOF |
| 63 | +[Unit] |
| 64 | +Description=A tiny SOCKS5 server |
| 65 | +After=syslog.target network.target auditd.service |
| 66 | +
|
| 67 | +[Service] |
| 68 | +Type=exec |
| 69 | +ExecStart=$BIN_PATH -p $PORT -u $USER -P $PASS |
| 70 | +
|
| 71 | +[Install] |
| 72 | +WantedBy=default.target |
| 73 | +EOF |
| 74 | + echo -ne "[7/7] Starting microsocks...\r" |
| 75 | + systemctl --user enable --now microsocks.service >/dev/null 2>&1 |
| 76 | + |
| 77 | + echo "### All done! ######################################################################################" |
| 78 | + echo "# #" |
| 79 | + echo "# microsocks has been installed successfully! #" |
| 80 | + echo "# #" |
| 81 | + echo "# You can connect with the credentials: #" |
| 82 | + echo "# Host $(hostname -f) #" |
| 83 | + echo "# Port ${PORT} #" |
| 84 | + echo "# User (your seedbox username) #" |
| 85 | + echo "# Password ${PASS} #" |
| 86 | + echo "# #" |
| 87 | + echo "# You can configure microsocks further by editing the service file at: #" |
| 88 | + echo "# ~/.config/systemd/user/microsocks.service #" |
| 89 | + echo "# and running: #" |
| 90 | + echo "# systemctl --user restart microsocks.service #" |
| 91 | + echo "# #" |
| 92 | + echo "# For more information, see https://github.com/rofl0r/microsocks. #" |
| 93 | + echo "# #" |
| 94 | + echo "####################################################################################################" |
| 95 | +} |
| 96 | + |
| 97 | + |
| 98 | + |
| 99 | +function _uninstall() { |
| 100 | + echo -ne "[1/3] Stopping the service...\r" |
| 101 | + systemctl --user disable --now microsocks.service >/dev/null 2>&1 |
| 102 | + echo -ne "[2/3] Removing the service file...\r" |
| 103 | + rm "${SERVICE_PATH}" |
| 104 | + echo -ne "[3/3] Deleting the binary...\r" |
| 105 | + rm "${BIN_PATH}" |
| 106 | + |
| 107 | + echo "### All done! ######################################################################################" |
| 108 | + echo "# #" |
| 109 | + echo "# microsocks has been uninstalled successfully! #" |
| 110 | + echo "# #" |
| 111 | + echo "####################################################################################################" |
| 112 | +} |
| 113 | + |
| 114 | + |
| 115 | + |
| 116 | +echo "### Welcome ########################################################################################" |
| 117 | +echo "# #" |
| 118 | +echo "# This script lets you install or uninstall microsocks in a hosted app server environment. #" |
| 119 | +echo "# #" |
| 120 | +echo "# What would you like to do? #" |
| 121 | +echo "# install Install microsocks #" |
| 122 | +echo "# uninstall Uninstall microsocks #" |
| 123 | +echo "# exit Exit this script #" |
| 124 | +echo "# #" |
| 125 | +echo "####################################################################################################" |
| 126 | +while true; do |
| 127 | + read -r -p "=> " |
| 128 | + echo "" |
| 129 | + case $REPLY in |
| 130 | + "install") |
| 131 | + _install |
| 132 | + break |
| 133 | + ;; |
| 134 | + "uninstall") |
| 135 | + _uninstall |
| 136 | + break |
| 137 | + ;; |
| 138 | + *) |
| 139 | + echo "Exiting!" |
| 140 | + ;; |
| 141 | + esac |
| 142 | + exit |
| 143 | +done |
0 commit comments