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

for puppeteer use

const browser = await puppeteer.launch({product: "chrome", executablePath: "/usr/bin/chromium-browser"})

for whatsapp-js

const { Client, LocalAuth, sessionCfg } = require('whatsapp-web.js');
const client = new Client({ authStrategy: new LocalAuth(), puppeteer: { product: "chrome", executablePath: "/usr/bin/chromium-browser" } });

test-selenium.py

import platform

from selenium import webdriver
from selenium.webdriver.chrome.service import Service


def get_binary_location():
    if platform.system() == "Windows":
        return r"C:\Program Files\BraveSoftware\Brave-Browser\Application\brave.exe"
    elif platform.system() == "Linux":
        return "/usr/bin/chromium-browser"

def get_service_path():
    if platform.system() == "Windows":
        return r"C:\Users\ayman\Downloads\chromedriver-win64\chromedriver.exe"
    else:
        return "/usr/bin/chromedriver"

options = webdriver.ChromeOptions()
mobile_user_agent = (
    "Mozilla/5.0 (iPhone; CPU iPhone OS 14_0 like Mac OS X) "
    "AppleWebKit/537.36 (KHTML, like Gecko) Mobile/15E148 Safari/537.36"
)
options.add_argument(f"user-agent={mobile_user_agent}")
options.add_argument("--disable-notifications")  # Disable pop-ups
options.add_argument("--start-maximized")  # Start maximized
options.add_argument("--headless")  # Headless
options.binary_location = get_binary_location()

service = Service(get_service_path())
driver = webdriver.Chrome(service=service, options=options)

driver.get("https://example.com/")
driver.get_screenshot_as_file("img.jpg")

example of whatsapp-web.js (not sure if it still works as of today)

const fs = require('fs');
var stream = fs.createWriteStream("log.txt", {flags:'a'});

const { Client, LocalAuth, sessionCfg } = require('whatsapp-web.js');
//const client = new Client({ authStrategy: new LocalAuth() });
const client = new Client({ authStrategy: new LocalAuth(), puppeteer: { product: "chrome", executablePath: "/usr/bin/chromium-browser" } });
//const client = new Client({ authStrategy: new LocalAuth() })
const qrcode = require('qrcode-terminal');

client.on('qr', qr => {
  console.log("let's go")
  qrcode.generate(qr, { small: true });
});


client.on('message_create', async msg => {
  if (msg.body == '!ping') {
    msg.reply('pong');
  }
  if (msg.body.toLowerCase() == '!publicip') {
   msg.reply(shell.exec('curl ifconfig.me'))
  }
});
 
client.initialize();

@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