#!/usr/bin/env bash set -e TOR_CONFIG="/etc/tor/torrc" ENV_FILE="/app/.env" remove_duplicated_lines() { local file="$1" local temp_file="/tmp/$(basename "$file")" awk '!seen[$0]++' "$file" >"$temp_file" mv "$temp_file" "$file" } remove_duplicate_env() { local file="$1" local temp_file="/tmp/$(basename "$file")" awk -F "=" -e '!seen[$1]++' "$file" >"$temp_file" mv "$temp_file" "$file" } to_camel_case() { echo "${1}" | awk -F_ '{for(i=1;i<=NF;i++) $i=toupper(substr($i,1,1)) tolower(substr($i,2));}1' OFS="" } # Checking if there is /data folder if [ ! -d "/data" ]; then mkdir -p /data chmod 700 /data fi mkdir -p /var/vlogs touch "${ENV_FILE}" chmod 400 "${ENV_FILE}" if ! grep -q "AUTH_SECRET" "${ENV_FILE}"; then cat "${ENV_FILE}" &>/dev/null </dev/null <>"${TOR_CONFIG}" done # Removing duplicated lines form "${TOR_CONFIG}" file remove_duplicated_lines "${TOR_CONFIG}" # Checking if there is /etc/torrc.d folder and if there is # any file in it, adding them to the torrc file if [ -d "/etc/torrc.d" ]; then for file in /etc/torrc.d/*; do cat "$file" >>"${TOR_CONFIG}" done fi # Start Tor on the background screen -L -Logfile /var/vlogs/tor -dmS tor \ bash -c "tor -f ${TOR_CONFIG}" # Starting Redis server in detached mode screen -L -Logfile /var/vlogs/redis -dmS redis \ bash -c "redis-server --port 6479 --daemonize no --dir /data --appendonly yes" echo " " echo " _ ___ ___ __ _ " echo "| | / (_)_______ / | ____/ /___ ___ (_)___ " echo "| | /| / / / ___/ _ \/ /| |/ __ / __ \`__ \/ / __ \\" echo "| |/ |/ / / / / __/ ___ / /_/ / / / / / / / / / /" echo "|__/|__/_/_/ \___/_/ |_\__,_/_/ /_/ /_/_/_/ /_/ " echo " " sleep 1 echo -e "\n======================== Versions ========================" echo -e "Alpine Version: \c" && cat /etc/alpine-release echo -e "WireGuard Version: \c" && wg -v | head -n 1 | awk '{print $1,$2}' echo -e "Tor Version: \c" && tor --version | head -n 1 echo -e "Obfs4proxy Version: \c" && obfs4proxy -version echo -e "\n========================= Torrc =========================" cat "${TOR_CONFIG}" echo -e "========================================================\n" sleep 1 screen -L -Logfile /var/vlogs/warmup -dmS warmup \ bash -c "sleep 10; echo -n '[+] Warming Up...'; curl -s http://127.0.0.1:3000/; echo -e 'Done!'" exec "$@"