#!/bin/bash # terminal-setup.sh # OpenDRS Online Maintenance Tracking System # Copyright (C) 2022 Rod Wright # SPDX-License-Identifier: GPL-2.0 source common.sh current_user=`whoami` current_login=`who am i | awk '{print $1}'` if [ "$current_user" != "root" ] then echo "You must have root privileges to run this setup." echo "Try 'sudo ./terminal-setup.sh'" exit 1 fi echo "" echo "" echo "" echo "" echo "This script will configure a Raspberry Pi to be an OpenDRS terminal." echo "" echo "" echo "You should have already completed the following steps:" echo "" echo "1. Created a Raspberry Pi OS Lite SD card from the latest release." echo "" echo "2. Installed the card in a Raspberry Pi, booted it, and completed" echo " initial configuration." echo "" echo "3. Ran sudo raspi-config and :" echo " a. Set locale, timezone, and WLAN Country under" echo " Localisation Options. " echo "" echo " b. Set hostname and Boot / Auto Login to Console under System Options." echo "" echo " c. If accessing a network through wifi, the Wireless LAN SSID" echo " and passphrase under System Options." echo "" echo " d. Enable SSH under Interface Options." echo "" echo " e. Set underscan as required under Display Options to get rid of any" echo " black borders around the edge of the display." echo "" echo " f. Reboot when prompted and logged back in as $current_login." echo "" echo "4. Transferred the OpenDRS distribution package to /home/$current_login on the" echo " Raspberry Pi and extracted it." echo "5. Changed directory to RPiSetup in the extracted distribution directory." echo "" echo "" echo "If you have completed these steps, press enter to continue. If not," echo -n "press ctrl-c to quit." read continueok echo "" getmodel echo "" getosrelease echo "" getarch echo "" if [ $arch_32_64 -eq 64 -a "$ismodel3" = "true" ] then echo "Raspberry Pi 3 hardware is known to have problems with acting as a" echo "wireless access point when 64 bit kernels are used. If you intend for" echo "this terminal to act as a wireless access point, you should stop here," echo "power off, remove the microsd card and re-image using a 32 bit version" echo "of Raspberry Pi OS." echo -n "Ignore and [c]ontinue or [A]bort? [c/A]: " read archabort if [ "$archabort" = "C" -o "$archabort" = "c" ] then echo "" echo "Continuing with installation." else echo "" echo "Aborting installation." exit 0 fi fi echo "" echo "" echo "Updating Raspberry Pi OS..." sleep 10 echo "" echo "" echo "" echo "" apt update && apt dist-upgrade -y echo "" echo "" echo "" echo "" echo "...done." sleep 10 echo "" echo "Copying files..." chmod +x $os_rel_ver/usr/local/bin/* cp -v $os_rel_ver/usr/local/bin/* /usr/local/bin cp -v $os_rel_ver/etc/drs.conf /etc cp -v $os_rel_ver/etc/apt/sources.list.d/* /etc/apt/sources.list.d cp -v $os_rel_ver/lib/systemd/system/getty@tty1.service /lib/systemd/system echo "" echo "" echo "" echo "" echo "...done." sleep 10 echo "" echo "" echo "Installing required terminal packages..." sleep 10 echo "" echo "" echo "" echo "" apt install apt-transport-https skipwebmin="false" curl -o setup-repos.sh https://raw.githubusercontent.com/webmin/webmin/master/setup-repos.sh if [ $? -ne 0 ] then echo "Warning: failed to download Webmin repo setup script." echo -n "Ignore and [c]ontinue or [A]bort? [c/A]: " read wmfailchoice if [ "$wmfailchoice" = "C" -o "$wmfailchoice" = "c" ] then skipwebmin="true" echo "Continuing without installing Webmin. You should investigate the failure" echo "and install Webmin manually after the terminal is set up, as the" echo "Manage Terminal link in the OpenDRS menu depends on it." echo -n "Press enter to continue." read continueok echo "" apt update else echo "Aborting terminal setup." exit 0 fi fi if [ "$skipwebmin" = "false" ] then sh setup-repos.sh -f apt update apt install -y --install-recommends webmin fi apt install -y --no-install-recommends xorg openbox chromium-browser apt install -y cups libcups2-dev cmake addgroup lpadmin usermod -a -G lpadmin $current_login systemctl enable getty@tty1.service service cups-browsed stop systemctl disable cups-browsed.service cp $os_rel_ver/etc/cups/cupsd.conf /etc/cups/ service cups restart cd $os_rel_ver/brlaser-master cmake . && make && make install cd ../.. myhn=`hostname` echo "" echo "" echo "" echo "" echo "Drivers have been installed for the Brother HL-L2300D printer that may come" echo "with the terminal." echo "After the terminal is set up and working, you can use another network" echo "computer to point a web browser to $myhn:631 to add this or another printer" echo "of your choosing." echo -n "Press enter to continue." read continueok echo "" echo "Creating customer user..." sleep 10 echo "" echo "" echo "" echo "" cloneuser $current_login customer mkdir -p /home/customer/.config/openbox cp $os_rel_ver/home/customer/.profile /home/customer cp $os_rel_ver/home/customer/.config/openbox/rc.xml /home/customer/.config/openbox chown -R customer:customer /home/customer/.config /home/customer/.profile echo "" echo "" echo "" echo "" echo "...done." echo "" echo "" echo "This terminal will need to communicate with an OpenDRS server. If" echo "you intend to host the server directly on this terminal, leave this" echo -n "blank. Otherwise, enter the server URL :" read server_url if [[ $server_url == "" ]] then conftype="Server/Terminal" ./server-setup.sh else conftype="Terminal" sed -i 's,'DRS_SERVER=.*','DRS_SERVER="\"$server_url\""',' /etc/drs.conf fi echo "" echo "" ./ap-setup.sh if [ $? -ne 0 ] then echo "If you would like to configure this terminal as an access point at some" echo "time in the future, log in, change directory to the" echo "extracted distribution's RPiSetup directory, and run:" echo " sudo ./ap-setup.sh" fi echo "" echo "" echo "$conftype configuration is now complete. " echo "" echo "" echo "It is highly recommended that after rebooting, you run ssh $current_login@$HOSTNAME" echo "from another computer on the network, then create new users for" echo "any other administrators using the cloneuser command" echo "(cloneuser $current_login )." echo "" echo "" echo "Terminal setup complete." echo "" if [ "$conftype" = "Terminal" ] then echo "If you would like to use this terminal as a DRS server, after rebooting" echo "and logging back in, change directory to the extracted distribution's" echo "RPiSetup directory, and run:" echo " sudo ./server-setup.sh" echo "" fi echo "" echo "A reboot is required to start using this terminal." echo -n "Would you like to reboot now? [Y/n]: " read rebootok if [ "$rebootok" = "N" -o "$rebootok" = "n" ] then exit 0 else reboot fi