├── readme.md └── install.sh /readme.md: -------------------------------------------------------------------------------- 1 | # MarzNode Script 2 | 3 | The `marznode` script helps manage the installation, updates and maintenance of MarzNode and its Xray core dependencies. This tool includes commands for installing and controlling the MarzNode service (with `custom xray version`), as well as a built-in system for checking and installing required dependencies. 4 | 5 | why is archive? because rate of adding Marzneshin cores was faster than my update speed. 6 | 7 | ## Features 8 | 9 | - **Install/Uninstall MarzNode**: Easily install or remove MarzNode. 10 | - **Start/Stop/Restart**: Manage the MarzNode service (start, stop, or restart). 11 | - **Logs**: View recent MarzNode logs. 12 | - **Docker Integration**: MarzNode runs as a Docker service. 13 | - **Custom Port Configuration**: Specify the service port during installation. 14 | 15 | ## Installation 16 | 17 | To install the script itself and be able to run it from anywhere, follow these steps: 18 | 19 | 1. Download and Install the script: 20 | ```bash 21 | sudo bash -c "$(curl -sL https://raw.githubusercontent.com/erfjab/marznode/main/install.sh)" @ install-script 22 | ``` 23 | 24 | 2. You can now run the script using the `marznode` command. 25 | 26 | ## Usage 27 | 28 | After installation, the script provides multiple commands to manage MarzNode. Here are the basic commands you can use: 29 | 30 | ### Install MarzNode 31 | 32 | To install MarzNode along with the required dependencies, run: 33 | ```bash 34 | marznode install 35 | ``` 36 | You will be asked to provide a service port and the MarzNode certificate from the Marzneshin panel. 37 | 38 | ### Start/Stop/Restart MarzNode 39 | 40 | - Start the MarzNode service: 41 | ```bash 42 | marznode start 43 | ``` 44 | - Stop the MarzNode service: 45 | ```bash 46 | marznode stop 47 | ``` 48 | - Restart the MarzNode service: 49 | ```bash 50 | marznode restart 51 | ``` 52 | 53 | ### Show MarzNode Status 54 | 55 | To check if MarzNode is running and view the uptime: 56 | ```bash 57 | marznode status 58 | ``` 59 | 60 | ### View Logs 61 | 62 | To view recent logs of MarzNode: 63 | ```bash 64 | marznode logs 65 | ``` 66 | 67 | ### Uninstall MarzNode 68 | 69 | To uninstall MarzNode and remove all related files: 70 | ```bash 71 | marznode uninstall 72 | ``` 73 | 74 | ### Script Version 75 | 76 | To check the current version of the script: 77 | ```bash 78 | marznode version 79 | ``` 80 | 81 | ## Updating the Script 82 | 83 | To update the script itself: 84 | ```bash 85 | marznode update-script 86 | ``` 87 | 88 | ## Uninstall the Script 89 | 90 | To uninstall the script and remove it from `/usr/local/bin`: 91 | ```bash 92 | marznode uninstall-script 93 | ``` 94 | 95 | ## Full Command List 96 | 97 | ```bash 98 | marznode install # Install MarzNode 99 | marznode uninstall # Uninstall MarzNode 100 | marznode start # Start MarzNode service 101 | marznode stop # Stop MarzNode service 102 | marznode restart # Restart MarzNode service 103 | marznode status # Show MarzNode status 104 | marznode logs # Show MarzNode logs 105 | marznode version # Show script version 106 | marznode install-script # Install this script to /usr/local/bin 107 | marznode uninstall-script # Uninstall this script from /usr/local/bin 108 | marznode update-script # Update this script to the latest version 109 | marznode help # Show help message 110 | ``` 111 | -------------------------------------------------------------------------------- /install.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -euo pipefail 4 | IFS=$'\n\t' 5 | 6 | SCRIPT_NAME="marznode" 7 | SCRIPT_VERSION="v0.1.0" 8 | SCRIPT_URL="https://raw.githubusercontent.com/erfjab/marznode/main/install.sh" 9 | INSTALL_DIR="/var/lib/marznode" 10 | LOG_FILE="${INSTALL_DIR}/marznode.log" 11 | COMPOSE_FILE="${INSTALL_DIR}/docker-compose.yml" 12 | GITHUB_REPO="https://github.com/marzneshin/marznode.git" 13 | GITHUB_API="https://api.github.com/repos/XTLS/Xray-core/releases" 14 | 15 | declare -r -A COLORS=( 16 | [RED]='\033[0;31m' 17 | [GREEN]='\033[0;32m' 18 | [YELLOW]='\033[0;33m' 19 | [BLUE]='\033[0;34m' 20 | [PURPLE]='\033[0;35m' 21 | [CYAN]='\033[0;36m' 22 | [RESET]='\033[0m' 23 | ) 24 | 25 | DEPENDENCIES=( 26 | "docker" 27 | "docker-compose" 28 | "curl" 29 | "wget" 30 | "unzip" 31 | "git" 32 | "jq" 33 | ) 34 | 35 | log() { echo -e "${COLORS[BLUE]}[INFO]${COLORS[RESET]} $*"; } 36 | warn() { echo -e "${COLORS[YELLOW]}[WARN]${COLORS[RESET]} $*" >&2; } 37 | error() { echo -e "${COLORS[RED]}[ERROR]${COLORS[RESET]} $*" >&2; exit 1; } 38 | success() { echo -e "${COLORS[GREEN]}[SUCCESS]${COLORS[RESET]} $*"; } 39 | 40 | check_root() { 41 | [[ $EUID -eq 0 ]] || error "This script must be run as root" 42 | } 43 | 44 | show_version() { 45 | log "MarzNode Script Version: $SCRIPT_VERSION" 46 | } 47 | 48 | update_script() { 49 | local script_path="/usr/local/bin/$SCRIPT_NAME" 50 | 51 | if [[ -f "$script_path" ]]; then 52 | log "Updating the script..." 53 | curl -o "$script_path" $SCRIPT_URL 54 | chmod +x "$script_path" 55 | success "Script updated to the latest version!" 56 | echo "Current version: $SCRIPT_VERSION" 57 | else 58 | warn "Script is not installed. Use 'install-script' command to install the script first." 59 | fi 60 | } 61 | 62 | 63 | check_dependencies() { 64 | local missing_deps=() 65 | for dep in "${DEPENDENCIES[@]}"; do 66 | command -v "$dep" &>/dev/null || missing_deps+=("$dep") 67 | done 68 | 69 | if [[ ${#missing_deps[@]} -gt 0 ]]; then 70 | log "Installing missing dependencies: ${missing_deps[*]}" 71 | apt update && apt install -y "${missing_deps[@]}" || warn "Some dependencies might have failed to install." 72 | fi 73 | 74 | command -v docker &>/dev/null || { log "Installing Docker..."; curl -fsSL https://get.docker.com | sh; } 75 | command -v docker-compose &>/dev/null || { 76 | log "Installing Docker Compose..." 77 | curl -L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose 78 | chmod +x /usr/local/bin/docker-compose 79 | } 80 | } 81 | 82 | is_installed() { [[ -d "$INSTALL_DIR" && -f "$COMPOSE_FILE" ]]; } 83 | is_running() { docker ps | grep -q "marznode"; } 84 | 85 | create_directories() { 86 | mkdir -p "$INSTALL_DIR" "${INSTALL_DIR}/data" 87 | } 88 | 89 | get_certificate() { 90 | log "Please paste the Marznode certificate from the Marzneshin panel (press Ctrl+D when finished):" 91 | cat > "${INSTALL_DIR}/client.pem" 92 | echo 93 | success "Certificate saved to ${INSTALL_DIR}/client.pem" 94 | } 95 | 96 | show_xray_versions() { 97 | log "Available Xray versions:" 98 | curl -s "$GITHUB_API" | jq -r '.[0:10] | .[] | .tag_name' | nl 99 | } 100 | 101 | select_xray_version() { 102 | show_xray_versions 103 | local choice 104 | read -p "Select Xray version (1-10): " choice 105 | local selected_version=$(curl -s "$GITHUB_API" | jq -r ".[0:10] | .[$((choice-1))] | .tag_name") 106 | 107 | echo "Selected Xray version: $selected_version" 108 | while true; do 109 | read -p "Confirm selection? (Y/n): " confirm 110 | if [[ $confirm =~ ^[Yy]$ ]] || [[ -z $confirm ]]; then 111 | download_xray_core "$selected_version" 112 | return 0 113 | elif [[ $confirm =~ ^[Nn]$ ]]; then 114 | echo "Selection cancelled. Please choose again." 115 | return 1 116 | else 117 | echo "Invalid input. Please enter Y or n." 118 | fi 119 | done 120 | } 121 | 122 | 123 | download_xray_core() { 124 | local version="$1" 125 | case "$(uname -m)" in 126 | 'i386' | 'i686') arch='32' ;; 127 | 'amd64' | 'x86_64') arch='64' ;; 128 | 'armv5tel') arch='arm32-v5' ;; 129 | 'armv6l') 130 | arch='arm32-v6' 131 | grep Features /proc/cpuinfo | grep -qw 'vfp' || arch='arm32-v5' 132 | ;; 133 | 'armv7' | 'armv7l') 134 | arch='arm32-v7a' 135 | grep Features /proc/cpuinfo | grep -qw 'vfp' || arch='arm32-v5' 136 | ;; 137 | 'armv8' | 'aarch64') arch='arm64-v8a' ;; 138 | 'mips') arch='mips32' ;; 139 | 'mipsle') arch='mips32le' ;; 140 | 'mips64') 141 | arch='mips64' 142 | lscpu | grep -q "Little Endian" && arch='mips64le' 143 | ;; 144 | 'mips64le') arch='mips64le' ;; 145 | 'ppc64') arch='ppc64' ;; 146 | 'ppc64le') arch='ppc64le' ;; 147 | 'riscv64') arch='riscv64' ;; 148 | 's390x') arch='s390x' ;; 149 | *) 150 | print_error "Error: The architecture is not supported." 151 | exit 1 152 | ;; 153 | esac 154 | local xray_filename="Xray-linux-${arch}.zip" 155 | local download_url="https://github.com/XTLS/Xray-core/releases/download/${version}/${xray_filename}" 156 | 157 | wget -q --show-progress "$download_url" -O "/tmp/${xray_filename}" 158 | unzip -o "/tmp/${xray_filename}" -d "${INSTALL_DIR}" 159 | rm "/tmp/${xray_filename}" 160 | 161 | chmod +x "${INSTALL_DIR}/xray" 162 | 163 | wget -q --show-progress "https://github.com/Loyalsoldier/v2ray-rules-dat/releases/latest/download/geoip.dat" -O "${INSTALL_DIR}/data/geoip.dat" 164 | wget -q --show-progress "https://github.com/Loyalsoldier/v2ray-rules-dat/releases/latest/download/geosite.dat" -O "${INSTALL_DIR}/data/geosite.dat" 165 | 166 | success "Xray-core ${version} installed successfully." 167 | } 168 | 169 | setup_docker_compose() { 170 | local port="${1:-5566}" 171 | cat > "$COMPOSE_FILE" < /dev/null; then 234 | ufw allow "$port" 235 | log "Firewall rule added for port $port" 236 | else 237 | warn "ufw not found. Please manually open port $port in your firewall." 238 | fi 239 | 240 | success "MarzNode installed successfully!" 241 | } 242 | 243 | uninstall_marznode() { 244 | log "Uninstalling MarzNode..." 245 | if [[ -f "$COMPOSE_FILE" ]]; then 246 | docker-compose -f "$COMPOSE_FILE" down --remove-orphans 247 | fi 248 | rm -rf "$INSTALL_DIR" 249 | success "MarzNode uninstalled successfully" 250 | } 251 | 252 | manage_service() { 253 | if ! is_installed; then 254 | error "MarzNode is not installed. Please install it first." 255 | return 1 256 | fi 257 | 258 | local action=$1 259 | case "$action" in 260 | start) 261 | if is_running; then 262 | warn "MarzNode is already running." 263 | else 264 | log "Starting MarzNode..." 265 | docker-compose -f "$COMPOSE_FILE" up -d 266 | success "MarzNode started" 267 | fi 268 | ;; 269 | stop) 270 | if ! is_running; then 271 | warn "MarzNode is not running." 272 | else 273 | log "Stopping MarzNode..." 274 | docker-compose -f "$COMPOSE_FILE" down 275 | success "MarzNode stopped" 276 | fi 277 | ;; 278 | restart) 279 | log "Restarting MarzNode..." 280 | docker-compose -f "$COMPOSE_FILE" down 281 | docker-compose -f "$COMPOSE_FILE" up -d 282 | success "MarzNode restarted" 283 | ;; 284 | esac 285 | } 286 | 287 | show_status() { 288 | if ! is_installed; then 289 | error "Status: Not Installed" 290 | return 1 291 | fi 292 | 293 | if is_running; then 294 | success "Status: Up and Running [uptime: $(docker ps --filter "name=marznode_marznode_1" --format "{{.Status}}")]" 295 | else 296 | error "Status: Stopped" 297 | fi 298 | } 299 | 300 | 301 | show_logs() { 302 | log "Showing MarzNode logs (press Ctrl+C to exit):" 303 | docker-compose -f "$COMPOSE_FILE" logs --tail=100 -f 304 | } 305 | 306 | install_script() { 307 | local script_path="/usr/local/bin/$SCRIPT_NAME" 308 | 309 | curl -s -o "$script_path" $SCRIPT_URL 310 | chmod +x "$script_path" 311 | success "Script installed successfully. You can now use '$SCRIPT_NAME' command from anywhere." 312 | } 313 | 314 | uninstall_script() { 315 | local script_path="/usr/local/bin/$SCRIPT_NAME" 316 | if [[ -f "$script_path" ]]; then 317 | rm "$script_path" 318 | success "Script uninstalled successfully from $script_path" 319 | else 320 | warn "Script not found at $script_path. Nothing to uninstall." 321 | fi 322 | } 323 | 324 | print_help() { 325 | echo 326 | echo "Usage: $SCRIPT_NAME " 327 | echo 328 | echo "Commands [$SCRIPT_VERSION]:" 329 | echo " install Install MarzNode" 330 | echo " uninstall Uninstall MarzNode" 331 | echo " update Update MarzNode to the latest version" 332 | echo " start Start MarzNode service" 333 | echo " stop Stop MarzNode service" 334 | echo " restart Restart MarzNode service" 335 | echo " status Show MarzNode and Xray status" 336 | echo " logs Show MarzNode logs" 337 | echo " version Show script version" 338 | echo " install-script Install this script to /usr/local/bin" 339 | echo " uninstall-script Uninstall this script from /usr/local/bin" 340 | echo " update-script Update this script to the latest version" 341 | echo " help Show this help message" 342 | echo 343 | } 344 | 345 | 346 | main() { 347 | check_root 348 | 349 | if [[ $# -eq 0 ]]; then 350 | print_help 351 | exit 0 352 | fi 353 | 354 | case "$1" in 355 | install) install_marznode ;; 356 | uninstall) uninstall_marznode ;; 357 | update) update_marznode ;; 358 | start|stop|restart) manage_service "$1" ;; 359 | status) show_status ;; 360 | logs|log) show_logs ;; 361 | version) show_version ;; 362 | install-script) install_script ;; 363 | uninstall-script) uninstall_script ;; 364 | update-script) update_script ;; 365 | help|*) print_help ;; 366 | esac 367 | } 368 | 369 | main "$@" --------------------------------------------------------------------------------