Skip to content

Instantly share code, notes, and snippets.

@faisalnjs
Last active March 2, 2026 18:01
Show Gist options
  • Select an option

  • Save faisalnjs/ee1ad7527f1827891b003ff46d26c1f0 to your computer and use it in GitHub Desktop.

Select an option

Save faisalnjs/ee1ad7527f1827891b003ff46d26c1f0 to your computer and use it in GitHub Desktop.
Reinstall Raspberry Pi from a manually created save point, connecting to the internet (ethernet, headless, WiFi), installing apps and packages, performing upgrades, and elevating sudo users.
#!/bin/bash
echo "[-] Running reinstall-pi.sh@faisaln..."
read -p "[0] Set up root? (Y/n): " setup_headless
if [[ "$setup_headless" == "n" || "$setup_headless" == "N" ]]; then
echo "[0] Skipping root setup..."
else
echo "[0] Setting root configuration..."
read -sp "[0] Enter new root password: " root_password
echo "root:$root_password" | sudo chpasswd
sudo usermod -aG sudo faisaln
echo "[0] Root configuration set."
fi
echo "[1] Validating current network..."
if ping -c 1 0 &>/dev/null; then
echo "[1] Connected to $(iwgetid -r || echo 'ethernet')."
if tailscale status &>/dev/null; then
echo "[2] Tailscale is already running. Skipping Tailscale setup..."
if ! iwgetid -r || iwgetid -r | grep -q "Faisal N"; then
read -p "[3] Set up headless mode? (y/N): " setup_headless
if [[ "$setup_headless" == "y" || "$setup_headless" == "Y" ]]; then
echo "[3] Setting up headless network..."
while true; do
read -p "[3] Network name: " network_name
if [[ -n "$network_name" ]]; then
break
else
echo "[3] Network name required."
fi
done
found=false
if command -v nmcli &>/dev/null; then
nmcli device wifi rescan >/dev/null 2>&1 || true
if nmcli -t -f SSID device wifi list | grep -xFq "$network_name"; then
found=true
fi
fi
if [ "$found" = false ]; then
if sudo iwlist wlan0 scan | grep -qw "$network_name"; then
found=true
fi
fi
if $found; then
echo "[3] $network_name network found. Creating..."
existing_connections=$(nmcli -t -f NAME connection show | grep -w "$network_name")
if [ -n "$existing_connections" ]; then
echo "[3] Existing connection for $network_name found. Attempting to connect..."
sudo nmcli connection up "$network_name" ifname wlan0
sleep 10
if nmcli -t -f NAME connection show --active | grep -qw "$network_name"; then
echo "[3] Connected to network $network_name."
exit 0
else
echo "[3] Removing existing connections for $network_name..."
echo "$existing_connections" | while IFS= read -r conn; do
sudo nmcli connection delete "$conn"
echo "[3] Deleted connection: $conn"
done
fi
fi
while true; do
read -sp "[3] Enter password for $network_name: " network_password
if [[ -n "$network_password" ]]; then
break
else
echo "[3] Network password required."
fi
done
if [[ "$network_name" == *"wpa"* ]]; then
echo "[3] WPA network found."
while true; do
read -p "[3] Enter username for $network_name: " network_username
if [[ -n "$network_username" ]]; then
break
else
echo "[3] Network username required."
fi
done
read -p "[3] Connect using empty certificate? (Y/n) " empty_cert
if [[ "$empty_cert" == "n" || "$empty_cert" == "N" ]]; then
while true; do
read -p "[3] Enter path to CA certificate (e.g., /path/to/ca.pem): " ca_cert_path
if [[ -n "$ca_cert_path" ]]; then
break
else
echo "[3] CA certificate path required."
fi
done
if [[ ! -f "$ca_cert_path" ]]; then
echo "[3] CA certificate file not found at $ca_cert_path. Exiting."
exit 1
fi
sudo bash -c 'cat <<EOF > /etc/wpa_supplicant/wpa_supplicant.conf
network={
ssid="'"$network_name"'"
key_mgmt=WPA-EAP
eap=PEAP
identity="'"$network_username"'"
password="'"$network_password"'"
phase1="peaplabel=1"
phase2="auth=MSCHAPV2"
ca_cert="/etc/wpa_supplicant/ca-cert.pem"
}
EOF'
else
sudo bash -c 'cat <<EOF > /etc/wpa_supplicant/wpa_supplicant.conf
network={
ssid="'"$network_name"'"
key_mgmt=WPA-EAP
eap=PEAP
identity="'"$network_username"'"
password="'"$network_password"'"
phase1="peaplabel=1"
phase2="auth=MSCHAPV2"
ca_cert="/etc/wpa_supplicant/empty-ca.pem"
}
EOF'
sudo touch /etc/wpa_supplicant/empty-ca.pem
fi
else
sudo bash -c 'cat <<EOF > /etc/wpa_supplicant/wpa_supplicant.conf
network={
ssid="'"$network_name"'"
psk="'"$network_password"'"
}x
EOF'
fi
if [[ "$network_name" == *"wpa"* ]]; then
sudo nmcli connection add type wifi ifname wlan0 \
con-name "$network_name" ssid "$network_name" \
802-11-wireless.mode infrastructure \
802-11-wireless-security.key-mgmt WPA-EAP \
802-1x.eap peap \
802-1x.identity "$network_username" \
802-1x.password "$network_password" \
802-1x.phase2-auth mschapv2 \
$ca_opt \
connection.autoconnect yes
else
sudo nmcli connection add type wifi ifname wlan0 con-name $network_name ssid "$network_name" 802-11-wireless.mode infrastructure
sudo nmcli connection modify $network_name \
802-1x.identity "$network_username" \
802-1x.password "$network_password" \
802-11-wireless-security.psk "$network_password"
fi
sudo nmcli connection modify $network_name connection.autoconnect yes
echo "[3] Connecting to $network_name..."
sudo nmcli connection up $network_name ifname wlan0
sleep 10
if nmcli -t -f NAME connection show --active | grep -qw "$network_name"; then
echo "[3] Connected to network $network_name."
else
echo "[3] Failed to connect to network $network_name. Please check your credentials and try again."
exit 1
fi
else
echo "[3] $network_name network not found. Please ensure the network is available."
exit 1
fi
else
echo "[3] Skipping headless network setup..."
fi
else
echo "[3] Already connected to headless network, skipping network setup..."
fi
else
read -p "[2] Install Tailscale? (Y/n): " install_tailscale
if [[ "$install_tailscale" == "n" || "$install_tailscale" == "N" ]]; then
echo "[2] Skipping Tailscale setup..."
else
while true; do
read -p "[2] Enter Tailscale install script from https://login.tailscale.com/admin/machines/new-linux: " tailscale_install_script
if [[ -n "$tailscale_install_script" ]]; then
break
else
echo "[2] Tailscale install script required."
fi
done
echo "[2] Installing Tailscale..."
if [[ "$tailscale_install_script" =~ ^https?:// ]]; then
curl -fsSL "$tailscale_install_script" | sh
else
bash -c "$tailscale_install_script"
fi
if tailscale status &>/dev/null; then
echo "[2] Tailscale started successfully."
else
echo "[2] Tailscale failed to start. Please check the install script and try again."
exit 1
fi
echo "[2] Configuring IP forwarding..."
if [ -d /etc/sysctl.d ]; then
echo 'net.ipv4.ip_forward = 1' | sudo tee -a /etc/sysctl.d/99-tailscale.conf
echo 'net.ipv6.conf.all.forwarding = 1' | sudo tee -a /etc/sysctl.d/99-tailscale.conf
sudo sysctl -p /etc/sysctl.d/99-tailscale.conf
else
echo 'net.ipv4.ip_forward = 1' | sudo tee -a /etc/sysctl.conf
echo 'net.ipv6.conf.all.forwarding = 1' | sudo tee -a /etc/sysctl.conf
sudo sysctl -p /etc/sysctl.conf
fi
echo "[2] Tailscale setup completed. Reconnect using Tailscale hostname."
exit 1
fi
fi
if man cockpit &>/dev/null; then
echo "[4] Cockpit is already installed. Skipping Cockpit installation..."
else
read -p "[4] Install Cockpit? (Y/n): " install_cockpit
if [[ "$install_cockpit" == "n" || "$install_cockpit" == "N" ]]; then
echo "[4] Skipping Cockpit installation..."
else
echo "[4] Installing Cockpit..."
sudo apt-get update
sudo apt-get install -y cockpit
echo "[4] Cockpit installed. http://faisaln:9090"
echo "[4] Installing Cockpit applications..."
cd /usr/share/cockpit
sudo git clone https://github.com/ocristopfer/cockpit-sensors.git
sudo git clone https://github.com/gbraad-cockpit/cockpit-tailscale.git
echo "[4] Cockpit applications installed."
fi
fi
echo "[5] Setting up cron jobs..."
if systemctl list-timers | grep -q heartbeat.timer; then
echo "[5] Better Stack Heartbeat timer already exists. Skipping..."
else
echo "[5] Setting up Better Stack Heartbeat timer..."
sudo bash -c "cat <<EOF > /etc/systemd/system/heartbeat.service
[Unit]
Description=Better Stack Heartbeat
[Service]
ExecStart=/bin/sh -c 'curl --silent https://uptime.betterstack.com/api/v1/heartbeat/8FU4TeHFzcBCExJSKuqJVfQg'
EOF"
sudo chmod 644 /etc/systemd/system/heartbeat.service
sudo chown root:root /etc/systemd/system/heartbeat.service
sudo bash -c "cat <<EOF > /etc/systemd/system/heartbeat.timer
[Unit]
Description=Better Stack Heartbeat
[Timer]
OnCalendar=*-*-* *:0,20,40
[Install]
WantedBy=timers.target
EOF"
sudo chmod 644 /etc/systemd/system/heartbeat.timer
sudo chown root:root /etc/systemd/system/heartbeat.timer
if [ ! -e /etc/systemd/system/timers.target.wants/heartbeat.timer ]; then
sudo ln -s /etc/systemd/system/heartbeat.timer /etc/systemd/system/timers.target.wants/heartbeat.timer
fi
sudo systemctl enable heartbeat.timer
echo "[5] Enabled cron job for Better Stack Heartbeat."
fi
if systemctl list-timers | grep -q heartbeat-boot.timer; then
echo "[5] Better Stack Heartbeat on boot timer already exists. Skipping..."
else
echo "[5] Setting up Better Stack Heartbeat on boot timer..."
sudo bash -c "cat <<EOF > /etc/systemd/system/heartbeat-boot.service
[Unit]
Description=Better Stack Heartbeat
[Service]
ExecStart=/bin/sh -c 'curl --silent https://uptime.betterstack.com/api/v1/heartbeat/8FU4TeHFzcBCExJSKuqJVfQg'
EOF"
sudo chmod 644 /etc/systemd/system/heartbeat-boot.service
sudo chown root:root /etc/systemd/system/heartbeat-boot.service
sudo bash -c "cat <<EOF > /etc/systemd/system/heartbeat-boot.timer
[Unit]
Description=Better Stack Heartbeat
[Timer]
OnBootSec=2min
[Install]
WantedBy=timers.target
EOF"
sudo chmod 644 /etc/systemd/system/heartbeat-boot.timer
sudo chown root:root /etc/systemd/system/heartbeat-boot.timer
if [ ! -e /etc/systemd/system/timers.target.wants/heartbeat.timer ]; then
sudo ln -s /etc/systemd/system/heartbeat.timer /etc/systemd/system/timers.target.wants/heartbeat.timer
fi
sudo systemctl enable heartbeat-boot.timer
echo "[5] Enabled cron job for Better Stack Heartbeat on boot."
fi
if systemctl list-timers | grep -q reboot-daily.timer; then
echo "[5] Daily Reboot timer already exists. Skipping..."
else
echo "[5] Setting up Daily Reboot timer..."
sudo bash -c "cat <<EOF > /etc/systemd/system/reboot-daily.service
[Unit]
Description=Reboots the system daily to prevent overload
[Service]
ExecStart=/bin/sh -c 'sudo shutdown -r now'
EOF"
sudo chmod 644 /etc/systemd/system/reboot-daily.service
sudo chown root:root /etc/systemd/system/reboot-daily.service
sudo bash -c "cat <<EOF > /etc/systemd/system/reboot-daily.timer
[Unit]
Description=Reboots the system daily to prevent overload
[Timer]
OnCalendar=*-*-* 00:30:00
[Install]
WantedBy=timers.target
EOF"
sudo chmod 644 /etc/systemd/system/reboot-daily.timer
sudo chown root:root /etc/systemd/system/reboot-daily.timer
if [ ! -e /etc/systemd/system/timers.target.wants/reboot-daily.timer ]; then
sudo ln -s /etc/systemd/system/reboot-daily.timer /etc/systemd/system/timers.target.wants/reboot-daily.timer
fi
sudo systemctl enable reboot-daily.timer
echo "[5] Enabled cron job for Daily Reboot."
fi
current_ssid=$(iwgetid -r 2>/dev/null || true)
if [ -n "$current_ssid" ] && ! printf '%s\n' "$current_ssid" | grep -qF "Faisal N"; then
if systemctl list-timers | grep -q wifi-reconnect.timer; then
echo "[5] WiFi Reconnect timer already exists. Skipping..."
else
echo "[5] Setting up WiFi Reconnect timer..."
sudo bash -c "cat <<EOF > /etc/systemd/system/wifi-reconnect.service
[Unit]
Description=Automatically reconnect to headless WiFi if required
[Service]
ExecStart=/bin/sh -c '/home/faisaln/reconnect-pi.sh -n $network_name -u $network_username -p $network_password'
EOF"
sudo chmod 644 /etc/systemd/system/wifi-reconnect.service
sudo chown root:root /etc/systemd/system/wifi-reconnect.service
sudo bash -c "cat <<EOF > /etc/systemd/system/wifi-reconnect.timer
[Unit]
Description=Automatically reconnect to headless WiFi if required
[Timer]
OnCalendar=*-*-* *:0,20,40
[Install]
WantedBy=timers.target
EOF"
sudo chmod 644 /etc/systemd/system/wifi-reconnect.timer
sudo chown root:root /etc/systemd/system/wifi-reconnect.timer
if [ ! -e /etc/systemd/system/timers.target.wants/wifi-reconnect.timer ]; then
sudo ln -s /etc/systemd/system/wifi-reconnect.timer /etc/systemd/system/timers.target.wants/wifi-reconnect.timer
fi
sudo systemctl enable wifi-reconnect.timer
echo "[5] Enabled cron job for WiFi Reconnect."
fi
if systemctl list-timers | grep -q wifi-reconnect-boot.timer; then
echo "[5] WiFi Reconnect on boot timer already exists. Skipping..."
else
echo "[5] Setting up WiFi Reconnect on boot timer..."
sudo bash -c "cat <<EOF > /etc/systemd/system/wifi-reconnect-boot.service
[Unit]
Description=Automatically reconnect to headless WiFi if required
[Service]
ExecStart=/bin/sh -c '/home/faisaln/reconnect-pi.sh -n $network_name -u $network_username -p $network_password'
EOF"
sudo chmod 644 /etc/systemd/system/wifi-reconnect-boot.service
sudo chown root:root /etc/systemd/system/wifi-reconnect-boot.service
sudo bash -c "cat <<EOF > /etc/systemd/system/wifi-reconnect-boot.timer
[Unit]
Description=Automatically reconnect to headless WiFi if required
[Timer]
OnBootSec=90sec
[Install]
WantedBy=timers.target
EOF"
sudo chmod 644 /etc/systemd/system/wifi-reconnect-boot.timer
sudo chown root:root /etc/systemd/system/wifi-reconnect-boot.timer
if [ ! -e /etc/systemd/system/timers.target.wants/wifi-reconnect.timer ]; then
sudo ln -s /etc/systemd/system/wifi-reconnect.timer /etc/systemd/system/timers.target.wants/wifi-reconnect.timer
fi
sudo systemctl enable wifi-reconnect-boot.timer
echo "[5] Enabled cron job for WiFi Reconnect on boot."
fi
fi
sudo systemctl daemon-reload
echo "[5] Cron jobs enabled."
sudo apt install -y nodejs npm
read -p "[7] Upgrade Node.js? (Y/n): " upgrade_node
if [[ "$upgrade_node" == "n" || "$upgrade_node" == "N" ]]; then
echo "[7] Skipping Node.js upgrade..."
else
echo "[7] Upgrading Node.js..."
sudo npm install n -g
sudo n stable
echo "[7] Node.js upgraded."
fi
if 1; then
echo "[8] MusicBrainz Proxy has been disabled. Skipping MusicBrainz Proxy installation..."
else
if [ -f /home/faisaln/proxy/proxy.js ] || [ -f /home/faisaln/proxy/proxyNew.js ]; then
echo "[8] MusicBrainz Proxy is already installed. Skipping MusicBrainz Proxy installation..."
else
read -p "[8] Install MusicBrainz Proxy? (Y/n): " install_proxy
if [[ "$install_proxy" == "n" || "$install_proxy" == "N" ]]; then
echo "[8] Skipping MusicBrainz Proxy installation..."
else
echo "[8] Installing MusicBrainz Proxy..."
mkdir -p /home/faisaln/proxy
cd /home/faisaln
if [ -f /home/faisaln/proxyNew.js ]; then
mv /home/faisaln/proxyNew.js /home/faisaln/proxy/proxyNew.js
sed -i 's/localhost:3000/faisaln.com/g' /home/faisaln/proxy/proxyNew.js
sudo bash -c "cat <<EOF > /etc/systemd/system/startproxy.service
[Unit]
Description=Starts the personal proxy on restart
[Service]
ExecStart=/bin/sh -c 'node ../home/faisaln/proxy/proxyNew.js'
EOF"
elif [ -f /home/faisaln/proxy.js ]; then
mv /home/faisaln/proxy.js /home/faisaln/proxy/proxy.js
node index.js
echo "[8] MusicBrainz Proxy started."
echo "[8] [ACTION] Port forwarding MusicBrainz Proxy is required. Port forward via router."
sudo bash -c "cat <<EOF > /etc/systemd/system/startproxy.service
[Unit]
Description=Starts the personal proxy on restart
[Service]
ExecStart=/bin/sh -c 'node ../home/faisaln/proxy/proxy.js'
EOF"
else
echo "[8] No proxy.js or proxyNew.js file found in /home/faisaln. Please upload the file and try again."
exit 1
fi
sudo chmod 644 /etc/systemd/system/startproxy.service
sudo chown root:root /etc/systemd/system/startproxy.service
sudo bash -c "cat <<EOF > /etc/systemd/system/startproxy.timer
[Unit]
Description=Starts the personal proxy on restart
[Timer]
OnBootSec=2min
[Install]
WantedBy=timers.target
EOF"
sudo chmod 644 /etc/systemd/system/startproxy.timer
sudo chown root:root /etc/systemd/system/startproxy.timer
if [ ! -e /etc/systemd/system/timers.target.wants/startproxy.timer ]; then
sudo ln -s /etc/systemd/system/startproxy.timer /etc/systemd/system/timers.target.wants/startproxy.timer
fi
sudo systemctl enable startproxy.timer
echo "[8] Enabled cron job for MusicBrainz Proxy."
sudo systemctl daemon-reload
echo "[8] MusicBrainz Proxy installed."
fi
fi
fi
if [ -d /home/faisaln/Mart-Mail ]; then
echo "[9] Mart-Mail is already installed. Skipping Mart-Mail installation..."
else
read -p "[9] Install Mart-Mail? (Y/n): " install_mart_mail
if [[ "$install_mart_mail" == "n" || "$install_mart_mail" == "N" ]]; then
echo "[9] Skipping Mart-Mail installation..."
else
echo "[9] Installing Mart-Mail..."
cd /home/faisaln
git clone https://github.com/faisalnjs/Mart-Mail.git
cd Mart-Mail
npm i
echo "[9] [ACTION] An .env is required to be uploaded in the repo directory."
read -p "[9] Continue: " action_complete
echo "[9] [ACTION] Update .env values."
read -p "[9] Continue: " action_complete
sudo bash -c "cat <<EOF > /etc/systemd/system/mart-mail.service
[Unit]
Description=Starts periodic Mart-Mail webhook message sends
[Service]
ExecStart=/bin/sh -c 'node ../home/faisaln/Mart-Mail/martMail.js'
EOF"
sudo chmod 644 /etc/systemd/system/mart-mail.service
sudo chown root:root /etc/systemd/system/mart-mail.service
sudo bash -c "cat <<EOF > /etc/systemd/system/mart-mail.timer
[Unit]
Description=Starts periodic Mart-Mail webhook message sends
[Timer]
OnCalendar=*-*-* 01:00:00
OnCalendar=*-*-* 03:00:00
OnCalendar=*-*-* 05:00:00
OnCalendar=*-*-* 07:00:00
OnCalendar=*-*-* 09:00:00
OnCalendar=*-*-* 11:00:00
OnCalendar=*-*-* 13:00:00
OnCalendar=*-*-* 15:00:00
OnCalendar=*-*-* 17:00:00
OnCalendar=*-*-* 19:00:00
OnCalendar=*-*-* 21:00:00
OnCalendar=*-*-* 23:00:00
[Install]
WantedBy=timers.target
EOF"
sudo chmod 644 /etc/systemd/system/mart-mail.timer
sudo chown root:root /etc/systemd/system/mart-mail.timer
if [ ! -e /etc/systemd/system/timers.target.wants/mart-mail.timer ]; then
sudo ln -s /etc/systemd/system/mart-mail.timer /etc/systemd/system/timers.target.wants/mart-mail.timer
fi
sudo systemctl enable mart-mail.timer
echo "[5] Enabled cron job for Mart-Mail."
sudo systemctl daemon-reload
echo "[9] Mart-Mail installed."
fi
fi
if [ -d /home/faisaln/Red-Tie-Reminders ]; then
echo "[10] Red-Tie-Reminders is already installed. Skipping Red-Tie-Reminders installation..."
else
read -p "[10] Install Red-Tie-Reminders? (Y/n): " install_red_tie_reminders
if [[ "$install_red_tie_reminders" == "n" || "$install_red_tie_reminders" == "N" ]]; then
echo "[10] Skipping Red-Tie-Reminders installation..."
else
echo "[10] Installing Red-Tie-Reminders..."
cd /home/faisaln
git clone https://github.com/faisalnjs/Red-Tie-Reminders.git
cd Red-Tie-Reminders
npm i
echo "[10] [ACTION] An .env is required to be uploaded in the repo directory."
read -p "[10] Continue: " action_complete
echo "[10] [ACTION] Update .env values."
read -p "[10] Continue: " action_complete
sudo bash -c "cat <<EOF > /etc/systemd/system/red-tie-reminders.service
[Unit]
Description=Starts periodic Red-Tie-Reminders webhook message sends
[Service]
ExecStart=/bin/sh -c 'node ../home/faisaln/Red-Tie-Reminders/redTieReminders.js'
EOF"
sudo chmod 644 /etc/systemd/system/red-tie-reminders.service
sudo chown root:root /etc/systemd/system/red-tie-reminders.service
sudo bash -c "cat <<EOF > /etc/systemd/system/red-tie-reminders.timer
[Unit]
Description=Starts periodic Red-Tie-Reminders webhook message sends
[Timer]
OnCalendar=mon *-*-* 17:00:00
OnCalendar=mon *-*-* 19:00:00
OnCalendar=mon *-*-* 21:00:00
[Install]
WantedBy=timers.target
EOF"
sudo chmod 644 /etc/systemd/system/red-tie-reminders.timer
sudo chown root:root /etc/systemd/system/red-tie-reminders.timer
if [ ! -e /etc/systemd/system/timers.target.wants/red-tie-reminders.timer ]; then
sudo ln -s /etc/systemd/system/red-tie-reminders.timer /etc/systemd/system/timers.target.wants/red-tie-reminders.timer
fi
sudo systemctl enable red-tie-reminders.timer
echo "[5] Enabled cron job for Red-Tie-Reminders."
sudo systemctl daemon-reload
echo "[10] Red-Tie-Reminders installed."
fi
fi
if man motion &>/dev/null; then
echo "[11] Raspberry Pi Camera Streaming is already installed. Skipping Raspberry Pi Camera Streaming installation..."
else
read -p "[11] Install Raspberry Pi Camera Streaming? (Y/n): " install_rpicam
if [[ "$install_rpicam" == "n" || "$install_rpicam" == "N" ]]; then
echo "[11] Skipping Raspberry Pi Camera Streaming installation..."
else
echo "[11] Installing Raspberry Pi Camera Streaming..."
cd /home/faisaln
sudo apt install -y autoconf automake build-essential pkgconf libtool git libzip-dev libjpeg-dev gettext libmicrohttpd-dev libavformat-dev libavcodec-dev libavutil-dev libswscale-dev libavdevice-dev default-libmysqlclient-dev libpq-dev libsqlite3-dev libwebp-dev libcamera-v4l2
wget https://github.com/Motion-Project/motion/releases/download/release-4.7.1/$(lsb_release -cs)_motion_4.7.1-1_$(dpkg --print-architecture).deb -O motion.deb
sudo dpkg -i motion.deb
if [ -f /home/faisaln/motion.conf ]; then
sudo cp /home/faisaln/motion.conf /etc/motion/motion.conf
else
echo "[11] No motion.conf file found in /home/faisaln. Please upload the file and try again."
exit 1
fi
sudo systemctl enable motion
sudo systemctl start motion
echo "[11] Raspberry Pi Camera Streaming installed. http://faisaln:8888 http://faisaln:8080"
fi
fi
if earnapp status &>/dev/null; then
echo "[12] EarnApp is already installed. Skipping EarnApp installation..."
else
read -p "[12] Install EarnApp? (Y/n): " install_earnapp
if [[ "$install_earnapp" == "n" || "$install_earnapp" == "N" ]]; then
echo "[12] Skipping EarnApp installation..."
else
echo "[12] Installing EarnApp..."
wget -qO- https://brightdata.com/static/earnapp/install.sh >/tmp/earnapp.sh
sudo bash /tmp/earnapp.sh
echo "[12] EarnApp installed."
fi
fi
if ! command -v docker &>/dev/null; then
echo "[13] Installing Docker..."
curl -fsSL https://get.docker.com -o get-docker.sh
sudo sh get-docker.sh
echo "[13] $(docker --version) installed."
fi
if sudo docker ps | grep -q honeygain; then
echo "[13] Honeygain is already installed. Skipping Honeygain installation..."
else
read -p "[13] Install Honeygain? (Y/n): " install_honeygain
if [[ "$install_honeygain" == "n" || "$install_honeygain" == "N" ]]; then
echo "[13] Skipping Honeygain installation..."
else
echo "[13] Installing Honeygain..."
while true; do
read -p "[13] Enter Honeygain account email: " honeygain_email
if [[ -n "$honeygain_email" ]]; then
break
else
echo "[13] Honeygain account email required."
fi
done
while true; do
read -sp "[13] Enter Honeygain account password: " honeygain_password
if [[ -n "$honeygain_password" ]]; then
break
else
echo "[13] Honeygain account password required."
fi
done
while true; do
read -p "[13] Enter Honeygain device name: " honeygain_device_name
if [[ -n "$honeygain_device_name" ]]; then
break
else
echo "[13] Honeygain unique device name required."
fi
done
sudo docker run -d --restart unless-stopped honeygain/honeygain -tou-accept -email $honeygain_email -pass $honeygain_password -device $honeygain_device_name
echo "[13] Honeygain installed."
fi
fi
if sudo docker ps | grep -q earnfm; then
echo "[14] EarnFM is already installed. Skipping EarnFM installation..."
else
read -p "[14] Install EarnFM? (Y/n): " install_earnfm
if [[ "$install_earnfm" == "n" || "$install_earnfm" == "N" ]]; then
echo "[14] Skipping EarnFM installation..."
else
echo "[14] Installing EarnFM..."
while true; do
read -sp "[14] Enter EarnFM API key: " earnfm_api_key
if [[ -n "$earnfm_api_key" ]]; then
break
else
echo "[14] EarnFM API key required."
fi
done
sudo docker stop watchtower
sudo docker rm watchtower
sudo docker rmi containrrr/watchtower
sudo docker stop earnfm-client
sudo docker rm earnfm-client
sudo docker rmi earnfm/earnfm-client:latest
sudo docker run -d --restart=always -e EARNFM_TOKEN="$earnfm_api_key" --name earnfm-client earnfm/earnfm-client:latest
sudo docker run -d --restart=always --name watchtower -v /var/run/docker.sock:/var/run/docker.sock containrrr/watchtower --cleanup --include-stopped --include-restarting --revive-stopped --interval 60 earnfm-client
echo "[14] EarnFM installed."
fi
fi
if sudo docker ps | grep -q pawns-cli; then
echo "[15] Pawns.app is already installed. Skipping Pawns.app installation..."
else
read -p "[15] Install Pawns.app? (Y/n): " install_pawns
if [[ "$install_pawns" == "n" || "$install_pawns" == "N" ]]; then
echo "[15] Skipping Pawns.app installation..."
else
echo "[15] Installing Pawns.app..."
while true; do
read -p "[15] Enter Pawns.app email address: " pawns_email
if [[ -n "$pawns_email" ]]; then
break
else
echo "[15] Pawns.app email address required."
fi
done
while true; do
read -sp "[15] Enter Pawns.app password: " pawns_password
if [[ -n "$pawns_password" ]]; then
break
else
echo "[15] Pawns.app password required."
fi
done
sudo docker pull iproyal/pawns-cli:latest
sudo docker run -d --restart=always iproyal/pawns-cli:latest -email=$pawns_email -password=$pawns_password -device-name=faisaln-rpi -device-id=faisaln-rpi -accept-tos
echo "[15] Pawns.app installed."
fi
fi
if sudo docker ps | grep -q psclient; then
echo "[16] PacketStream is already installed. Skipping PacketStream installation..."
else
read -p "[16] Install PacketStream? (Y/n): " install_packetstream
if [[ "$install_packetstream" == "n" || "$install_packetstream" == "N" ]]; then
echo "[16] Skipping PacketStream installation..."
else
echo "[16] Installing PacketStream..."
sudo docker stop watchtower
sudo docker rm watchtower
sudo docker rmi containrrr/watchtower
sudo docker stop psclient
sudo docker rm psclient
sudo docker rmi packetstream/psclient
sudo docker run -d --restart=always -e CID=7gPh --name psclient packetstream/psclient:latest
sudo docker run -d --restart=always --name watchtower -v /var/run/docker.sock:/var/run/docker.sock containrrr/watchtower --cleanup --include-stopped --include-restarting --revive-stopped --interval 60 psclient
echo "[16] PacketStream installed."
fi
fi
if sudo teamviewer info &>/dev/null; then
echo "[17] TeamViewer is already installed. Skipping TeamViewer installation..."
else
if [ -n "$XDG_CURRENT_DESKTOP" ]; then
read -p "[17] Install TeamViewer? (Y/n): " install_teamviewer
if [[ "$install_teamviewer" == "n" || "$install_teamviewer" == "N" ]]; then
echo "[17] Skipping TeamViewer installation..."
else
echo "[17] Installing TeamViewer..."
cd /home/faisaln
wget https://download.teamviewer.com/download/linux/teamviewer-host_arm64.deb
sudo apt install ./teamviewer-host_arm64.deb
sudo sudo teamviewer setup
echo "[17] TeamViewer installed."
fi
else
echo "[17] No desktop environment detected. Skipping TeamViewer installation..."
fi
if [ -d /home/faisaln/Verify-RCSID ]; then
echo "[10] Verify-RCSID is already installed. Skipping Verify-RCSID installation..."
else
read -p "[10] Install Verify-RCSID? (Y/n): " install_verify_rcsid
if [[ "$install_verify_rcsid" == "n" || "$install_verify_rcsid" == "N" ]]; then
echo "[10] Skipping Verify-RCSID installation..."
else
echo "[10] Installing Verify-RCSID..."
cd /home/faisaln
read -p "[10] Enter GitHub PAT for faisalnjs/Verify-RCSID: " verify_rcsid_pat
git clone https://faisalnjs:$verify_rcsid_pat@github.com/faisalnjs/Verify-RCSID.git
cd Verify-RCSID
npm i
sudo apt-get install chromium -y
sudo bash -c "cat <<EOF > /etc/systemd/system/verify-rcsid.service
[Unit]
Description=Starts periodic Verify-RCSID rounds
[Service]
ExecStart=/bin/sh -c 'node ../home/faisaln/Verify-RCSID/verifyRCSID.js'
EOF"
sudo chmod 644 /etc/systemd/system/verify-rcsid.service
sudo chown root:root /etc/systemd/system/verify-rcsid.service
sudo bash -c "cat <<EOF > /etc/systemd/system/verify-rcsid.timer
[Unit]
Description=Starts periodic Verify-RCSID rounds
[Timer]
OnCalendar=*-*-* *:*:*
[Install]
WantedBy=timers.target
EOF"
sudo chmod 644 /etc/systemd/system/verify-rcsid.timer
sudo chown root:root /etc/systemd/system/verify-rcsid.timer
if [ ! -e /etc/systemd/system/timers.target.wants/verify-rcsid.timer ]; then
sudo ln -s /etc/systemd/system/verify-rcsid.timer /etc/systemd/system/timers.target.wants/verify-rcsid.timer
fi
sudo systemctl enable verify-rcsid.timer
echo "[5] Enabled cron job for Verify-RCSID."
sudo systemctl daemon-reload
echo "[10] Verify-RCSID installed."
fi
fi
sudo apt autoremove
echo "[+] reinstall-pi.sh completed."
exit 0
else
echo "[1] No internet connection found. Connect to the internet and try again."
exit 1
fi
echo "[-] reinstall-pi.sh aborted."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment