|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# This file is part of TorBox, an easy to use anonymizing router based on Raspberry Pi. |
| 4 | +# Copyright (C) 2025 radio24 |
| 5 | +# Contact: anonym@torbox.ch |
| 6 | +# |
| 7 | +# This program is free software: you can redistribute it and/or modify |
| 8 | +# it under the terms of the GNU General Public License as published by |
| 9 | +# the Free Software Foundation, either version 3 of the License, or |
| 10 | +# (at your option) any later version. |
| 11 | +# |
| 12 | +# This program is distributed in the hope that it is useful, |
| 13 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | +# GNU General Public License for more details. |
| 16 | +# |
| 17 | +# You should have received a copy of the GNU General Public License |
| 18 | +# along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 19 | +# |
| 20 | +# DESCRIPTION |
| 21 | +# THIS SCRIPT IS INTENDED TO BE USED BY THE DEVELOPERS ONLY! |
| 22 | +# This script converts a TorBox mini installation to a default TorBox installation. |
| 23 | +# Important: This script must be run locally and not via a network connection. |
| 24 | +# |
| 25 | +# SYNTAX |
| 26 | +# sudo bash convert_to_torbox |
| 27 | +# |
| 28 | +# |
| 29 | +##### SET VARIABLES ###### |
| 30 | +# |
| 31 | +# SIZE OF THE MENU |
| 32 | +# |
| 33 | +#Set the the variables for the menu |
| 34 | +MENU_WIDTH=80 |
| 35 | +MENU_HEIGHT_15=15 |
| 36 | + |
| 37 | +#Colors |
| 38 | +RED='\033[1;31m' |
| 39 | +YELLOW='\033[1;93m' |
| 40 | +NOCOLOR='\033[0m' |
| 41 | + |
| 42 | +# What main version is installed |
| 43 | +DEBIAN_VERSION=$(sed 's/\..*//' /etc/debian_version) |
| 44 | + |
| 45 | +# Where is the config.txt? |
| 46 | +if [ "$DEBIAN_VERSION" -gt "11" ]; then |
| 47 | + CONFIGFILE="/boot/firmware/config.txt" |
| 48 | +else |
| 49 | + CONFIGFILE="/boot/config.txt" |
| 50 | +fi |
| 51 | + |
| 52 | +# Where is the cmdline.txt? |
| 53 | +if [ "$DEBIAN_VERSION" -gt "11" ]; then |
| 54 | + CMDLINEFILE="/boot/firmware/cmdline.txt" |
| 55 | +else |
| 56 | + CMDLINEFILE="/boot/cmdline.txt" |
| 57 | +fi |
| 58 | + |
| 59 | +#Other variables |
| 60 | +TORBOX_PATH="/home/torbox/torbox" |
| 61 | +RUNFILE="run/torbox.run" |
| 62 | + |
| 63 | +############################## |
| 64 | +######## FUNCTIONS ########### |
| 65 | + |
| 66 | +#include lib |
| 67 | +. /home/torbox/torbox/lib/torbox.lib |
| 68 | + |
| 69 | +INPUT=$(cat text/convert_to_torbox-text) |
| 70 | +if (whiptail --title "TorBox - INFO" --defaultno --yesno "$INPUT" $MENU_HEIGHT_15 $MENU_WIDTH); then |
| 71 | + cd $TORBOX_PATH |
| 72 | + |
| 73 | + # Reinstalling kernel-headers and dkms |
| 74 | + clear |
| 75 | + echo -e "${RED}[+] Reinstalling kernel-headers and dkms....${NOCOLOR}" |
| 76 | + echo "" |
| 77 | + |
| 78 | + # Fixing and cleaning |
| 79 | + echo -e "${RED}[+] Fixing and cleaning${NOCOLOR}" |
| 80 | + echo "" |
| 81 | + sudo apt --fix-broken install |
| 82 | + sudo apt-get -y clean; sudo apt-get -y autoclean; sudo apt-get -y autoremove |
| 83 | + go clean -cache |
| 84 | + sudo setcap 'cap_net_bind_service=+ep' /usr/bin/obfs4proxy |
| 85 | + sudo sed -i "s/^NoNewPrivileges=yes/NoNewPrivileges=no/g" /lib/systemd/system/tor@default.service |
| 86 | + sudo sed -i "s/^NoNewPrivileges=yes/NoNewPrivileges=no/g" /lib/systemd/system/tor@.service |
| 87 | + sudo systemctl daemon-reload |
| 88 | + |
| 89 | + # Updating the system |
| 90 | + echo -e "${RED}[+] Updating the system...${NOCOLOR}" |
| 91 | + echo "" |
| 92 | + sudo apt-get -y update |
| 93 | + sudo apt-get -y dist-upgrade |
| 94 | + sudo apt-get -y clean |
| 95 | + sudo apt-get -y autoclean |
| 96 | + sudo apt-get -y autoremove |
| 97 | + sudo setcap 'cap_net_bind_service=+ep' /usr/bin/obfs4proxy |
| 98 | + sudo sed -i "s/^NoNewPrivileges=yes/NoNewPrivileges=no/g" /lib/systemd/system/tor@default.service |
| 99 | + sudo sed -i "s/^NoNewPrivileges=yes/NoNewPrivileges=no/g" /lib/systemd/system/tor@.service |
| 100 | + sudo systemctl daemon-reload |
| 101 | + |
| 102 | + # NEW v.0.5.5: This is necessary for installing linux-headers, which replaces raspberrypi-kernel-headers on Debian Trixie |
| 103 | + LINUX_HEADERS="linux-headers-$(uname -r)" |
| 104 | + sudo apt-get install $LINUX_HEADERS dkms |
| 105 | + |
| 106 | + # Set up WiFi AP (Hostapd) - the files should already be there, but to be sure |
| 107 | + sudo cp etc/default/hostapd /etc/default/ |
| 108 | + sudo cp etc/hostapd/hostapd.conf /etc/hostapd/ |
| 109 | + |
| 110 | + # Set up DHCP (Removes the IP Pool for 192.168.44.x) |
| 111 | + sudo cp etc/dhcp/dhcpd.conf /etc/dhcp/ |
| 112 | + sudo cp etc/default/isc-dhcp-server /etc/default/ |
| 113 | + |
| 114 | + # Assign the correct IPs for the server and the client (192.168.44.x —> 192.168.42.x) - activated after the reboot |
| 115 | + sudo cp etc/network/interfaces /etc/network/ |
| 116 | + |
| 117 | + # Set the correct routing for wlan0 and 192.168.42.x - activated after the reboot |
| 118 | + sudo cp etc/iptables.ipv4.nat /etc/ |
| 119 | + |
| 120 | + # Necessary boot-script to activate etc/iptables.ipv4.nat after the reboot |
| 121 | + sudo cp etc/rc.local /etc/ |
| 122 | + |
| 123 | + INPUT=$(cat text/convert_to_torbox-question-text) |
| 124 | + if (whiptail --title "TorBox - INFO" --yesno --defaultno "$INPUT" $MENU_HEIGHT_20 $MENU_WIDTH); then |
| 125 | + if sudo [ ! -e /etc/modprobe.d/brcmfmac.conf ] || sudo [ ! -s /etc/modprobe.d/brcmfmac.conf ]; then |
| 126 | + echo "options brcmfmac roamoff=1 feature_disable=0x82000" | sudo tee /etc/modprobe.d/brcmfmac.conf |
| 127 | + elif ! grep "options brcmfmac roamoff=1 feature_disable=0x82000" /etc/modprobe.d/brcmfmac.conf ; then |
| 128 | + sudo sed -i "s/^options brcmfmac/options brcmfmac roamoff=1 feature_disable=0x82000/g" /etc/modprobe.d/brcmfmac.conf |
| 129 | + fi |
| 130 | + sudo update-initramfs -u |
| 131 | + # In rc.local it is tested if the hostapd interface is up. Only in this case, hostapd will be startet. |
| 132 | + # That could lead to problems, if the interface is not up when running the test, for exemple on a slow Raspberry Pi 2 W |
| 133 | + if ! grep -qF "(sleep 15; systemctl restart hostapd) &" /etc/rc.local; then |
| 134 | + sudo sed -i '/exit 0/i # Added by convert_to_torbox' /etc/rc.local |
| 135 | + sudo sed -i '/exit 0/i (sleep 15; systemctl restart hostapd) &' /etc/rc.local |
| 136 | + fi |
| 137 | + fi |
| 138 | + |
| 139 | + # Setting up the correct runtime variables (used by rc.local) |
| 140 | + sudo sed -i "s/^TORBOX_MINI_DEFAULT=.*/TORBOX_MINI_DEFAULT=0/" ${RUNFILE} |
| 141 | + sudo sed -i "s/^TORBOX_MINI=.*/TORBOX_MINI=0/" ${RUNFILE} |
| 142 | + # Forgot that - could be the reason that it didn’t work (it doesn’t matter if the interfaces are available or not - it will autoconfigure after the reboot and your choices in the main menu) |
| 143 | + sudo sed -i "s/^INTERNET_IFACE=.*/INTERNET_IFACE=eth0/" ${RUNFILE} |
| 144 | + sudo sed -i "s/^CLIENT_IFACE=.*/CLIENT_IFACE=wlan0 eth1/" ${RUNFILE} |
| 145 | + |
| 146 | + # Set up systemctl services |
| 147 | + sudo systemctl unmask hostapd |
| 148 | + sudo systemctl enable hostapd |
| 149 | + sudo systemctl start hostapd |
| 150 | + sudo systemctl daemon-reload |
| 151 | + |
| 152 | + # Remove Ethernet-Gadget capabilities |
| 153 | + if grep "modules-load=dwc2,g_ether" "dwc2,g_ether" ${CMDLINEFILE}; then |
| 154 | + sudo sed -i "s|modules-load=dwc2,g_ether ||g" ${CMDLINEFILE} |
| 155 | + elif grep "dwc2,g_ether" ${CMDLINEFILE}; then |
| 156 | + sudo sed -i "s|dwc2,g_ether ||g" ${CMDLINEFILE} |
| 157 | + fi |
| 158 | + if grep "dtoverlay=dwc2,dr_mode=peripheral" ${CONFIGFILE}; then |
| 159 | + sudo sed -i "/^dtoverlay=dwc2,dr_mode=peripheral/d" /boot/firmware/config.txt |
| 160 | + fi |
| 161 | + clear |
| 162 | + echo -e "${RED}[+]TorBox is now configured to be used in a Raspberry Pi Zero 2 W${NOCOLOR}" |
| 163 | +fi |
| 164 | + |
| 165 | +# Reboot |
| 166 | +recommended_reboot |
0 commit comments