Skip to content

Instantly share code, notes, and snippets.

@xslendix
Created September 1, 2021 20:49
Show Gist options
  • Save xslendix/44703043bfe623d358b31807540316f1 to your computer and use it in GitHub Desktop.
Save xslendix/44703043bfe623d358b31807540316f1 to your computer and use it in GitHub Desktop.
#!/bin/sh
osname="$(lsb_release -c -s)"
if [ -z "$DISPLAY" ] && [ "$(fgconsole)" -eq 1 ]; then
echo "Please switch TTY to something other than 1."
exit
fi
nc -z gnu.org 80
if [ "$?" -ne 0 ]; then
echo "No internet connection detected, if you rebooted and chornyd is not running,"
echo "please make sure the date is correct."
exit
fi
if [ "$osname" != "void" -o "$osname" != "buster" ]; then
echo "You need to be running on a Void Linux or a Debian Buster system."
exit
fi
if [ "$(whoami)" != "root" ]; then
echo "This script needs to be ran as root."
exit
fi
read -p "What hostname should the robot have? " hostname
hostname=${hostname:-voidbot}
wirelessDrivers=0
while true; do read -p "Do you wish to install wireless drivers?" yn
case $yn in
[Yy]* ) wirelessDrivers=1; break;;
[Nn]* ) wirelessDrivers=0; break;;
* ) echo "Please enter Yes or No.";;
esac
done
installX11=0
while true; do read -p "Do you wish to install a graphical enviroment?" yn
case $yn in
[Yy]* ) installX11=1; break;;
[Nn]* ) installX11=0; break;;
* ) echo "Please enter Yes or No.";;
esac
done
experimentalVideo=0
if [ "$installX11" -eq 1 ]
while true; do read -p "Do you wish to enable the experimental desktop GL driver?" yn
case $yn in
[Yy]* ) installX11=1; break;;
[Nn]* ) installX11=0; break;;
* ) echo "Please enter Yes or No.";;
esac
done
fi
say() {
printf "\033[0;34m :: \033[0m%s\n" "$1"
}
# INSTALL
# System update
say "Updating system"
if [ "$osname" != "void" ]; then
xbps-install -S
xbps-install -uy xbps
xbps-install -Suy
xbps-install -y wget
else
apt update
apt upgrade -y
apt install -y wget
fi
# RPi kernel
if [ "$osname" != "void" ]; then
say "Installing the RPi kernel"
xbps-install -Sy rpi-base
fi
# Install chrony
if [ "$osname" != "void" ]; then
say "Installing chrony"
xbps-install -Sy chrony
ln -s /etc/sv/chrony /var/service
sv start chrony
fi
# Hostname setup
say "Setting up hostname"
echo "$hostname" > /etc/hostname
# Wireless drivers
if [ "$wirelessDrivers" -eq 1 ]; then
say "Installing wireless drivers"
curl -L http://downloads.fars-robotics.net/wifi-drivers/install-wifi -o /usr/bin/install-wifi
chmod +x /usr/bin/install-wifi
install-wifi
fi
# Enable RNG
if [ "$osname" != "void" ]; then
say "Enabling RNG"
xbps-install -Sy rng-tools
ln -s /etc/sv/rngd /etc/service
sv start rngd
fi
# Enable ssh
say "Enabling ssh"
if [ "$osname" != "void" ]; then
xbps-install -Sy openssh
ln -s /etc/sv/sshd /var/service
else
apt install openssh -y
systemctl enable sshd
fi
sed -i 's/#PermitRootLogin prohibit-password/PermitRootLogin yes/g' /etc/ssh/sshd_config
if [ "$osname" != "void" ]; then
sv start sshd
else
systemctl start sshd
fi
# Install python
say "Installing python"
if [ "$osname" != "void" ]; then
xbps-install -Sy python3 python3-pip base-devel python3-devel git
export CFLAGS=-fcommon
pip3 install RPi.GPIO
export CFLAGS=
else
apt install python3 python3-pip build-essential git -y
fi
# Install pigpio
say "Installing pigpio"
if [ "$osname" != "void" ]; then
mkdir -p /root/.local/src
git clone --depth 1 https://github.com/joan2937/pigpio /root/.local/src/pigpio
cd /root/.local/src/pigpio
make -j$(nproc)
make install
cd /root
mkdir /etc/sv/pigpiod
cat<<EOF > /etc/sv/dripd/run
#!/bin/sh
exec /usr/local/bin/pigpiod -g 2>&1
EOF
chmod +x /etc/sv/pigpiod/run
ln -s /etc/sv/pigpiod /var/service
sv start pigpiod
else
sudo apt install pigpio python3-pigpio -y
systemctl enable pigpiod
systemctl start pigpiod
fi
# Enable I2C
say "Enabling I2C"
if [ "$osname" != "void" ]; then
echo 'device_tree_param=i2c_arm=on' >> /boot/config.txt
sed '1 s/$/ bcm2708.vc_i2c_override=1/' /boot/cmdline.txt
mkdir -p /etc/modules-load.d
echo 'i2c-dev' > /etc/modules-load.d/00-i2c.conf
else
echo "Since you are not using Void, you need to do this step manually."
echo "Press [ENTER] to continue."
read
raspi-config
fi
# Install I2C tools
say "Installing I2C tools."
if [ "$osname" != "void" ]; then
xbps-install -Sy i2c-tools
else
apt install -y i2c-tools
fi
# Get Drip
say "Getting Drip server"
if [ "$osname" != "void" ]; then
xbps-install -Sy git neovim
else
apt install -y git neovim
fi
git clone --depth 1 https://git.xslendi.xyz/xSlendiX/DripServer.git /root/DripServer
echo "You now need to configure Drip. Opening in vim."
echo "Press [ENTER] to continue."
vim /root/DripServer/config.py
# Install Drip
say "Installing Drip server as a service"
if [ "$osname" != "void" ]; then
mkdir /etc/sv/dripd
cat<<EOF > /etc/sv/dripd/run
#!/bin/sh
cd /root/DripServer
exec ./app.py 2>&1
EOF
chmod +x /etc/sv/dripd/run
ln -s /etc/sv/dripd /var/service
else
cat<<EOF > /etc/systemd/system/dripd.service
[Unit]
Description=Drip server system service
After=pigpiod.service
[Service]
Type=simple
Restart=always
RestartSec=1
User=root
WorkingDirectory=/root/DripServer
ExecStart=python3 ./app.py
[Install]
WantedBy=multi-user.target
EOF
systemctl enable dripd.service
systemctl start dripd.service
fi
# Installing debugging tools
if [ "$osname" != "void" ]; then
xbps-install -Sy xtools htop
else
apt install -y htop
fi
# Autologin
say "Configuring autologin"
if [ "$osname" != "void" ]; then
cp -R /etc/sv/agetty-tty1 /etc/sv/agetty-autologin-tty1
sed -i 's/GETTY_ARGS="--noclear"/GETTY_ARGS="--autologin root --noclear"/g' /etc/sv/agetty-autologin-tty1/conf
rm /var/service/agetty-tty1
ln -s /etc/sv/agetty-autologin-tty1 /var/service
else
mkdir -p /etc/systemd/getty\@tty1.service.d/
cat<<EOF > /etc/systemd/getty\@tty1.service.d/autologin.conf
[Service]
ExecStart=
ExecStart=-/sbin/agetty --autologin pi --noclear %I 38400 linux
EOF
systemctl enable getty@tty1.service
fi
chsh -s /bin/bash root
say "Disabling boot-slowing options"
cat << EOF >> /boot/config.txt
disable_spash=1
dtoverlay=disable-bt
boot_delay=0
EOF
# X11
if [ "$installX11" -eq 1 ]; then
if [ "$osname" != "void" ]; then
say "Installing drivers"
xbps-install -Sy mesa-dri
fi
say "Installing xorg"
if [ "$osname" != "void" ]; then
xbps-install -Sy xorg xinit harfbuzz-devel libXft-devel libXinerama-devel
else
apt install -y xorg xinit harfbuzz-dev libxft-dev libxinerama-dev libx11-dev
fi
say "Installing dmenu"
if [ "$osname" != "void" ]; then
xbps-install -Sy dmenu
else
apt install -y dmenu
fi
say "Installing st"
cd /root/.local/src
git clone --depth 1 https://git.xslendi.xyz/xSlendiX/st.git
cd st
make -j4
make install
cd ..
say "Installing dwm"
git clone --depth 1 https://git.xslendi.xyz/xSlendiX/dwm.git
cd dwm
make -j4
make install
cd /root
say "Creating xinitrc"
cat << EOF > /root/.xinitrc
#!/bin/sh
start-pipewire &
dwm
EOF
say "Installing dbus and rtkit"
if [ "$osname" != "void" ]; then
xbps-install -Sy dbus rtkit
ln -sf /etc/sv/dbus /var/service harfbuzz-devel
ln -sf /etc/sv/rtkit /var/service
sv start dbus rtkit
else
apt install dbus rtkit
systemctl enable dbus rtkit
systemctl start dbus rtkit
fi
say "Enabling audio sound chip"
sed -i 's/#dtparam=audio=on/dtparam=audio=on/g' /boot/config.txt
if [ experimentalVideo -eq 1 ]; then
say "Enabling experimental desktop GL driver"
sed -i 's/#dtoverlay=vc4-kms-v3d/dtoverlay=vc4-kms-v3d/g' /boot/config.txt
fi
cat << EOF > /root/.profile
#!/bin/sh
if [ -z "\$DISPLAY" ] && [ "\$(fgconsole)" -eq 1 ]; then
exec startx
fi
EOF
chmod a+x /root/.profile
say "Installing pipewire"
if [ "$osname" != "void" ]; then
xbps-install -Sy pipewire pavucontrol pulseaudio-utils
else
apt install -y pipewire pavucontrol pulseaudio-utils
fi
say "Creating pipewire startup script"
cat<<EOF > /usr/local/bin/start-pipewire
#!/bin/sh
pgrep -x pipewire > /dev/null || pipewire &
pgrep -x pipewire-pulse > /dev/null || pipewire-pulse &
EOF
chmod a+x /usr/local/bin/start-pipewire
fi
say "Installation finished. After reboot please run `i2c-detect` to make sure everything installed properly."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment