Skip to content
Snippets Groups Projects
Commit 339d7c05 authored by tobiglaser's avatar tobiglaser
Browse files

Add setup.sh

parent 452b25d3
No related branches found
No related tags found
No related merge requests found
setup.sh 0 → 100755
#!/bin/sh
# ToDo:
# - Fix systemctl
# - DE for VNC maybe RPD?
# - Check VNC of pi? users
# - Check VNC if headless
# - Adjust VNC to liking
# - get new PiCam
# - Setup Camera
# - Fix mjpeg-streamer
# getting all the input right away
echo "Please enter base username for vnc accounts:"
read vncBaseName
echo "Please enter base password for vnc accounts:"
read vncBasepasswd
echo "Please enter the number of vnc accounts:"
read vncCount
# update
echo "Updating OS, this may take a while."
sudo apt -qq update
sudo apt -qq upgrade -y -qq
# create vnc users
echo "Creating VNC Users"
for i in $(seq 1 $vncCount)
do
echo " Creating pi$i"
sudo adduser --gecos --quiet --disabled-login --disabled-password pi$i > /dev/null
sudo usermod -a -G i2c,dialout pi$i
# VNC Password:
myuser=$vncBaseName$i
mypasswd=$vncBasepasswd$i
sudo mkdir -p /home/$myuser/.vnc
echo $mypasswd | vncpasswd -f > passwd
sudo mv passwd /home/$myuser/.vnc/passwd
sudo chown -R $myuser:$myuser /home/$myuser/.vnc
sudo chmod 0600 /home/$myuser/.vnc/passwd
# thx https://askubuntu.com/questions/328240/assign-vnc-password-using-script
echo " VNC Password: $mypasswd"
done
# setup vnc
echo "Setting up VNC Server."
echo " Installing tightvnc."
sudo apt -qq install -qq -y tightvncserver
echo " Checking for autostart service."
VNC=$(systemctl status vncserver)
if [ -z "$VNC" \
-o -n "$(echo $VNC | grep "not found")" \
-o -n "$(echo $VNC | grep "Active: failed")" ] # empty -> could not be found
then
echo " Creating autostart service."
echo "[Unit]
Description=TightVNC remote desktop server
After=network.target
[Service]
User=pi
Type=forking
ExecStart=/usr/bin/vncserver :1 -geometry 1440x900
ExecStop=/usr/bin/vncserver -kill :1
[Install]
WantedBy=multi-user.target" > vncserver.service
echo "[Unit]
Description=1 TightVNC remote desktop server
After=syslog.target network.target
[Service]
User=pi1
Type=forking
PIDFile=/home/pi1/.vnc/%H:2.pid
ExecStartPre=-/usr/bin/vncserver -kill :2 > /dev/null 2>&1
ExecStart=/usr/bin/vncserver :2 -depth 16 -geometry 1600x800
ExecStop=/usr/bin/vncserver -kill :2
[Install]
WantedBy=multi-user.target" > vncserver1.service
# echo "[Unit]
# Description=Start TightVNC server at startup
# After=syslog.target network.target
#
# [Service]
# Type=forking
# User=pi%i
# PIDFile=/home/pi%i/.vnc/%H:%i.pid
# ExecStartPre=-/usr/bin/vncserver -kill :%i > /dev/null 2>&1
# ExecStart=/usr/bin/vncserver :%i -depth 16 -geometry 1600x800
# ExecStop=/usr/bin/vncserver -kill :%i
#
# [Install]
# WantedBy=multi-user.target" > vncserver.service
sudo mv vncserver.service /etc/systemd/system/vncserver.service
sudo mv vncserver1.service /etc/systemd/system/vncserverA.service
sudo systemctl daemon-reload
else
echo " Autostart service already present."
fi
echo " Testing service:"
sudo systemctl start vncserver
sudo systemctl start vncserverA
VNC=$(systemctl status vncserverA | grep -e "Active: active (running)")
if [ "$VNC" ]
then
echo " Sucessful, enabling service!"
sudo systemctl enable vncserver
sudo systemctl enable vncserverA
else
echo "!Something went wrong! See status:"
systemctl status vncserverA | cat
fi
# Enable I2C
echo "Checking I2C"
for i in 0 1
do
I2C=$(sudo raspi-config nonint get_i2c)
if [ $I2C -eq 1 ] # if I2C is off
then
echo " Turning on I2C."
sudo raspi-config nonint do_i2c 0
else
echo " I2C is active."
break
fi
done
# Install user software
echo "Installing letsgoING ArduinoControl"
sudo -H python3 -m pip install -q letsgoing-rpi-arduinocontrol
echo "Installing Arduino IDE."
sudo apt -qq install -y -qq arduino
# Create Shortcuts
echo "Creating desktop and start menu shortcuts for ArduinoControl."
wget -qO- http://letsgoing.org/img/personen/SMack.jpg > /home/pi/Downloads/SMack.jpg
echo "[Desktop Entry]
Encoding=UTF-8
Type=Application
Name=Arduino Control
Exec=letsgoing-rpi-arduinocontrol
Comment=Control your Arduino from here!
Icon=/home/pi/Downloads/SMack.jpg
Terminal=false
Categories=Development;Engineering;Electronics" > arduinocontrol.desktop
#start menu
sudo cp arduinocontrol.desktop /usr/share/applications/
#desktops
for i in $(seq 1 $vncCount)
do
sudo mkdir -p /home/pi$i/Desktop/
sudo cp arduinocontrol.desktop /home/pi$i/Desktop/
done
echo "Creating desktop shortcuts for Arduino IDE."
for i in $(seq 1 $vncCount)
do
sudo cp /usr/share/applications/arduino.desktop /home/pi$i/Desktop/
done
# Not functional as no vnc has been set up for pi? users
# Disable "How to execute"-PopUp
# echo " Enabling quick execution of desktop shortcuts."
# for i in $(seq 1 $vncCount)
# do
# sed -e 's/quick_exec=0/quick_exec=1/' -i /home/pi$i/.config/libfm/libfm.conf
# done
# Camera Stuff...
#sudo systemctl daemon-reload ?
#python3 -m pip install --upgrade --force-reinstall Pillow
# https://gist.github.com/melissacoleman/8e6bf42089ccb2a5ee60c0bea26c2061
# sudo userdel -r -f pi5
# sudo apt install xscreensaver ?
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment