Skip to content

Instantly share code, notes, and snippets.

@AymaneHrouch
Last active May 14, 2025 10:07
Show Gist options
  • Select an option

  • Save AymaneHrouch/ecdb1bbde8f2c22a677f4f9266010b1d to your computer and use it in GitHub Desktop.

Select an option

Save AymaneHrouch/ecdb1bbde8f2c22a677f4f9266010b1d to your computer and use it in GitHub Desktop.
Bash script to run on the first time working with a raspberrypi, (installs nodejs, npm, chromium-browser, noip, and sets a static ip)
#! /bin/bash
RED="\e[31m"
ENDCOLOR="\e[0m"
echo -e "${RED}Updating packages list${ENDCOLOR}\n\n"
sudo apt update
echo -e "${RED}Installing Node.js${ENDCOLOR}\n\n"
sudo apt --assume-yes install nodejs
echo -e "${RED}Installing npm${ENDCOLOR}\n\n"
sudo apt --assume-yes install npm
echo -e "${RED}Installing live-server${ENDCOLOR}\n\n"
sudo npm i -g live-server
echo -e "${RED}Installing chromium-browser and chromium-codecs-ffmpeg${ENDCOLOR}\n\n"
sudo apt --assume-yes install chromium-browser chromium-codecs-ffmpeg
echo -e "${RED}Installing noip${ENDCOLOR}\n\n"
sudo apt --assume-yes install wget
cd /usr/local/src
sudo wget http://www.no-ip.com/client/linux/noip-duc-linux.tar.gz
sudo tar xzf noip-duc-linux.tar.gz
cd noip-2.1.9-1
sudo make
sudo make install
echo -e "${RED}If you want to configure the client please run: sudo /usr/local/bin/noip2 -C${ENDCOLOR}\n\n"
echo -e "${RED}The script will now run in the background${ENDCOLOR}\n\n"
sudo /usr/local/bin/noip2
CRON_JOB="@reboot sleep 10 && sudo /usr/local/bin/noip2"
crontab -l | grep -q "$CRON_JOB"
if [ $? -eq 0 ]
then
echo "Cron job already exists in this machine"
else
(crontab -l 2>/dev/null || true; echo $CRON_JOB) | crontab -
echo "Cron job added, noip will run on startup"
fi
echo -e "${RED}Setting a static IP${ENDCOLOR}\n\n"
tail -n 2 /etc/resolv.conf
read -p "Copy and paste the DNS IP above: " DNS_IP
read -p "Enter STATIC IP [192.168.1.66]: " STATIC_IP
STATIC_IP=${STATIC_IP:-192.168.1.66}
echo interface wlan0 >> /etc/dhcpcd.conf
echo static ip_address=$STATIC_IP/24 >> /etc/dhcpcd.conf
echo static routers=$DNS_IP >> /etc/dhcpcd.conf
echo static domain_name_servers=$DNS_IP >> /etc/dhcpcd.conf
echo -e "${RED}All done :) please reboot so the changes take effect!${ENDCOLOR}"
echo "Happy Coding!"
@AymaneHrouch
Copy link
Author

sudo netstat -tlnp | grep vnc

this to check on which PORT the vncserver is listening. You can restart it through sudo systemctl restart vncserver-x11-serviced.
And if you notice that the port is not equal to 5900 for some reason, you can edit the config file from sudo nano config.d/vncserver-x11

@AymaneHrouch
Copy link
Author

A better solution than screen is tmux. To launch something as a service you can use
sudo nano /etc/systemd/system/tswira.service

service looks like this:

[Unit]
Description=Run tswira_follow_likers.sh on startup in tmux
After=network.target

[Service]
Type=oneshot
ExecStart=/bin/bash -c "sleep 30 && sudo -u pi tmux new-session -d -s tswira_session '/home/pi/Desktop/archive/ig_bot_selenium/bash_scripts/tswira_follow_likers.sh'"
RemainAfterExit=true

[Install]
WantedBy=multi-user.target

Reload and enable the service

sudo systemctl daemon-reload
sudo systemctl enable tswira.service

** (Optional) Start it manually to test**
sudo systemctl start tswira.service

Check status or logs

sudo systemctl status tswira.service
journalctl -u tswira.service

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment