Merge pull request #1 from adevoss/adevoss-build-script-extra-parameters

Extra parameters in build script
This commit is contained in:
arno 2020-06-22 12:20:35 +02:00 committed by GitHub
commit f9d958b96b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,9 +1,9 @@
#!/bin/bash #!/bin/bash
######################################################################### #########################################################################
# Build your SD card image based on: # Build your SD card image based on:
# Raspbian Buster Desktop (2020-05-27) # Raspberry PiOS Buster Lite (2020-05-27)
# https://www.raspberrypi.org/downloads/raspbian/ # https://www.raspberrypi.org/downloads/raspberry-pi-os/
# SHA256: b9a5c5321b3145e605b3bcd297ca9ffc350ecb1844880afd8fb75a7589b7bd04 # SHA256: f5786604be4b41e292c5b3c711e2efa64b25a5b51869ea8313d58da0b46afc64
########################################################################## ##########################################################################
# setup fresh SD card with image above - login per SSH and run this script: # setup fresh SD card with image above - login per SSH and run this script:
########################################################################## ##########################################################################
@ -20,19 +20,74 @@ echo "*** CHECK INPUT PARAMETERS ***"
wantedBranch="$1" wantedBranch="$1"
if [ ${#wantedBranch} -eq 0 ]; then if [ ${#wantedBranch} -eq 0 ]; then
wantedBranch="master" wantedBranch="master"
else
if [ "${wantedBranch}" == "-h" -o "${wantedBranch}" == "--help" ]; then
echo "Usage: [branch] [github user] [root partition] [LCD screen installed true|false] [Wifi disabled true|false]"
echo "Example (USB boot, no LCD and no wifi): $0 v1.6 rootzoll /dev/sdb2 false true"
exit 1
fi
fi fi
echo "will use code from branch --> '${wantedBranch}'" echo "will use code from branch --> '${wantedBranch}'"
# 2nd optional parameter is the GITHUB-USERNAME to get code from when # 2nd optional parameter is the GITHUB-USERNAME to get code from when
# provisioning sd card with raspiblitz assets/scripts later on # provisioning sd card with raspiblitz assets/scripts later on
# if 2nd parameter is used - 1st is mandatory # if 2nd parameter is used - 1st is mandatory
echo "*** CHECK INPUT PARAMETERS ***"
githubUser="$2" githubUser="$2"
if [ ${#githubUser} -eq 0 ]; then if [ ${#githubUser} -eq 0 ]; then
githubUser="rootzoll" githubUser="rootzoll"
fi fi
echo "will use code from user --> '${githubUser}'" echo "will use code from user --> '${githubUser}'"
# 3rd optional parameter is the root partition
rootPartition="$3"
if [ ${#rootPartition} -eq 0 ]; then
rootPartition="/dev/mmcblk0p2"
fi
echo "will use root partition --> '${rootPartition}'"
# 4th optional parameter is the LCD screen
lcdInstalled="$4"
if [ ${#lcdInstalled} -eq 0 ]; then
lcdInstalled="true"
else
if [ "${lcdInstalled}" != "false" ]; then
lcdInstalled="true"
fi
fi
echo "will activate LCD screen --> '${lcdInstalled}'"
# 5th optional parameter is Wifi
disableWifi="$5"
if [ ${#disableWifi} -eq 0 ]; then
disableWifi="false"
else
if [ "${disableWifi}" != "true" ]; then
disableWifi="false"
fi
fi
echo "will disable wifi --> '${disableWifi}'"
# 6th optional parameter is Wifi country
wifiCountry="$6"
if [ ${#wifiCountry} -eq 0 ]; then
wifiCountry="US"
fi
if [ "${disableWifi}" == "false" ]; then
echo "will use Wifi country --> '${wifiCountry}'"
fi
echo -n "Do you wish to install Raspiblitz branch ${wantedBranch}? (yes/no) "
read installRaspiblitzAnswer
if [ "$installRaspiblitzAnswer" == "yes" ] ;then
echo ""
echo ""
else
exit 1
fi
echo "Installing Raspiblitz..."
sleep 3 sleep 3
echo "" echo ""
@ -104,12 +159,12 @@ if [ "${baseImage}" = "raspbian" ] || [ "${baseImage}" = "dietpi" ] ; then
fi fi
# remove some (big) packages that are not needed # remove some (big) packages that are not needed
sudo apt-get remove -y --purge libreoffice* oracle-java* chromium-browser nuscratch scratch sonic-pi minecraft-pi plymouth python2 sudo apt-get remove -y --purge python2 python2-minimal
sudo apt-get clean sudo apt-get clean
sudo apt-get -y autoremove sudo apt-get -y autoremove
if [ -f "/usr/bin/python3.7" ]; then if [ -f "/usr/bin/python3.7" ]; then
# make sure /usr/bin/python exists (and calls Python3.7 in Debian Buster) # make sure /usr/bin/python exists (and calls Python3.7 in Buster)
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.7 1 sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.7 1
echo "python calls python3.7" echo "python calls python3.7"
elif [ -f "/usr/bin/python3.8" ]; then elif [ -f "/usr/bin/python3.8" ]; then
@ -124,7 +179,7 @@ fi
# update debian # update debian
echo "" echo ""
echo "*** UPDATE DEBIAN ***" echo "*** UPDATE ***"
sudo apt-get update -y sudo apt-get update -y
sudo apt-get upgrade -f -y sudo apt-get upgrade -f -y
@ -144,15 +199,32 @@ if [ "${baseImage}" = "raspbian" ]; then
# set to wait until network is available on boot (0 seems to yes) # set to wait until network is available on boot (0 seems to yes)
sudo raspi-config nonint do_boot_wait 0 sudo raspi-config nonint do_boot_wait 0
# set WIFI country so boot does not block # set WIFI country so boot does not block
sudo raspi-config nonint do_wifi_country US if [ "${disableWifi}" == "false" ]; then
sudo raspi-config nonint do_wifi_country $wifiCountry
fi
# see https://github.com/rootzoll/raspiblitz/issues/428#issuecomment-472822840 # see https://github.com/rootzoll/raspiblitz/issues/428#issuecomment-472822840
echo "max_usb_current=1" | sudo tee -a /boot/config.txt echo "max_usb_current=1" | sudo tee -a /boot/config.txt
# run fsck on sd boot partition on every startup to prevent "maintenance login" screen # run fsck on sd boot partition on every startup to prevent "maintenance login" screen
# see: https://github.com/rootzoll/raspiblitz/issues/782#issuecomment-564981630 # see: https://github.com/rootzoll/raspiblitz/issues/782#issuecomment-564981630
# use command to check last fsck check: sudo tune2fs -l /dev/mmcblk0p2 # use command to check last fsck check: sudo tune2fs -l ${rootPartition}
sudo tune2fs -c 1 /dev/mmcblk0p2 sudo tune2fs -c 1 ${rootPartition}
# see https://github.com/rootzoll/raspiblitz/issues/1053#issuecomment-600878695 # see https://github.com/rootzoll/raspiblitz/issues/1053#issuecomment-600878695
sudo sed -i 's/^/fsck.mode=force fsck.repair=yes /g' /boot/cmdline.txt
# edit kernel parameters
kernelOptionsFile=/boot/cmdline.txt
fsOption1="fsck.mode=force"
fsOption2="fsck.repair=yes"
kernelOptions=$(cat $kernelOptionsFile)
fsOption1InFile=$(cat ${kernelOptionsFile}|grep -c ${fsOption1})
fsOption2InFile=$(cat ${kernelOptionsFile}|grep -c ${fsOption2})
if [ ${fsOption1InFile} -eq 0 ]; then
sudo sed -i "s/^/$fsOption1 /g" "$kernelOptionsFile"
fi
if [ ${fsOption2InFile} -eq 0 ]; then
sudo sed -i "s/^/$fsOption2 /g" "$kernelOptionsFile"
fi
fi fi
# special prepare when Ubuntu or Armbian # special prepare when Ubuntu or Armbian
@ -172,30 +244,32 @@ echo ""
echo "*** CONFIG ***" echo "*** CONFIG ***"
# based on https://github.com/Stadicus/guides/blob/master/raspibolt/raspibolt_20_pi.md#raspi-config # based on https://github.com/Stadicus/guides/blob/master/raspibolt/raspibolt_20_pi.md#raspi-config
# set new default passwort for root user # set new default password for root user
echo "root:raspiblitz" | sudo chpasswd echo "root:raspiblitz" | sudo chpasswd
echo "pi:raspiblitz" | sudo chpasswd echo "pi:raspiblitz" | sudo chpasswd
if [ "${baseImage}" = "raspbian" ]; then if [ "${lcdInstalled}" == "true" ]; then
# set Raspi to boot up automatically with user pi (for the LCD) if [ "${baseImage}" = "raspbian" ]; then
# https://www.raspberrypi.org/forums/viewtopic.php?t=21632 # set Raspi to boot up automatically with user pi (for the LCD)
sudo raspi-config nonint do_boot_behaviour B2 # https://www.raspberrypi.org/forums/viewtopic.php?t=21632
sudo bash -c "echo '[Service]' >> /etc/systemd/system/getty@tty1.service.d/autologin.conf" sudo raspi-config nonint do_boot_behaviour B2
sudo bash -c "echo 'ExecStart=' >> /etc/systemd/system/getty@tty1.service.d/autologin.conf" sudo bash -c "echo '[Service]' >> /etc/systemd/system/getty@tty1.service.d/autologin.conf"
sudo bash -c "echo 'ExecStart=-/sbin/agetty --autologin pi --noclear %I 38400 linux' >> /etc/systemd/system/getty@tty1.service.d/autologin.conf" sudo bash -c "echo 'ExecStart=' >> /etc/systemd/system/getty@tty1.service.d/autologin.conf"
fi sudo bash -c "echo 'ExecStart=-/sbin/agetty --autologin pi --noclear %I 38400 linux' >> /etc/systemd/system/getty@tty1.service.d/autologin.conf"
fi
if [ "${baseImage}" = "dietpi" ]; then if [ "${baseImage}" = "dietpi" ]; then
# set DietPi to boot up automatically with user pi (for the LCD) # set DietPi to boot up automatically with user pi (for the LCD)
# requires AUTO_SETUP_AUTOSTART_TARGET_INDEX=7 in the dietpi.txt # requires AUTO_SETUP_AUTOSTART_TARGET_INDEX=7 in the dietpi.txt
# /DietPi/dietpi/dietpi-autostart overwrites /etc/systemd/system/getty@tty1.service.d/dietpi-autologin.conf on reboot # /DietPi/dietpi/dietpi-autostart overwrites /etc/systemd/system/getty@tty1.service.d/dietpi-autologin.conf on reboot
sudo sed -i 's/agetty --autologin root %I $TERM/agetty --autologin pi --noclear %I 38400 linux/' /DietPi/dietpi/dietpi-autostart sudo sed -i 's/agetty --autologin root %I $TERM/agetty --autologin pi --noclear %I 38400 linux/' /DietPi/dietpi/dietpi-autostart
fi fi
if [ "${baseImage}" = "ubuntu" ] || [ "${baseImage}" = "armbian" ]; then if [ "${baseImage}" = "ubuntu" ] || [ "${baseImage}" = "armbian" ]; then
sudo bash -c "echo '[Service]' >> /lib/systemd/system/getty@.service" sudo bash -c "echo '[Service]' >> /lib/systemd/system/getty@.service"
sudo bash -c "echo 'ExecStart=' >> /lib/systemd/system/getty@.service" sudo bash -c "echo 'ExecStart=' >> /lib/systemd/system/getty@.service"
sudo bash -c "echo 'ExecStart=-/sbin/agetty --autologin pi --noclear %I 38400 linux' >> /lib/systemd/system/getty@.service" sudo bash -c "echo 'ExecStart=-/sbin/agetty --autologin pi --noclear %I 38400 linux' >> /lib/systemd/system/getty@.service"
fi
fi fi
# change log rotates # change log rotates
@ -647,23 +721,25 @@ sudo bash -c "echo '# when running in a tmux session' >> /home/admin/.bashrc"
sudo bash -c "echo 'if [ -z \"\$TMUX\" ]; then' >> /home/admin/.bashrc" sudo bash -c "echo 'if [ -z \"\$TMUX\" ]; then' >> /home/admin/.bashrc"
sudo bash -c "echo ' ./00raspiblitz.sh' >> /home/admin/.bashrc" sudo bash -c "echo ' ./00raspiblitz.sh' >> /home/admin/.bashrc"
sudo bash -c "echo 'fi' >> /home/admin/.bashrc" sudo bash -c "echo 'fi' >> /home/admin/.bashrc"
if [ "${lcdInstalled}" == "true" ]; then
if [ "${baseImage}" = "raspbian" ] || [ "${baseImage}" = "armbian" ] || [ "${baseImage}" = "ubuntu" ]; then
# bash autostart for pi
# run as exec to dont allow easy physical access by keyboard
# see https://github.com/rootzoll/raspiblitz/issues/54
sudo bash -c 'echo "# automatic start the LCD info loop" >> /home/pi/.bashrc'
sudo bash -c 'echo "SCRIPT=/home/admin/00infoLCD.sh" >> /home/pi/.bashrc'
sudo bash -c 'echo "# replace shell with script => logout when exiting script" >> /home/pi/.bashrc'
sudo bash -c 'echo "exec \$SCRIPT" >> /home/pi/.bashrc'
fi
if [ "${baseImage}" = "raspbian" ] || [ "${baseImage}" = "armbian" ] || [ "${baseImage}" = "ubuntu" ]; then if [ "${baseImage}" = "dietpi" ]; then
# bash autostart for pi # bash autostart for dietpi
# run as exec to dont allow easy physical access by keyboard sudo bash -c 'echo "# automatic start the LCD info loop" >> /home/dietpi/.bashrc'
# see https://github.com/rootzoll/raspiblitz/issues/54 sudo bash -c 'echo "SCRIPT=/home/admin/00infoLCD.sh" >> /home/dietpi/.bashrc'
sudo bash -c 'echo "# automatic start the LCD info loop" >> /home/pi/.bashrc' sudo bash -c 'echo "# replace shell with script => logout when exiting script" >> /home/dietpi/.bashrc'
sudo bash -c 'echo "SCRIPT=/home/admin/00infoLCD.sh" >> /home/pi/.bashrc' sudo bash -c 'echo "exec \$SCRIPT" >> /home/dietpi/.bashrc'
sudo bash -c 'echo "# replace shell with script => logout when exiting script" >> /home/pi/.bashrc' fi
sudo bash -c 'echo "exec \$SCRIPT" >> /home/pi/.bashrc'
fi
if [ "${baseImage}" = "dietpi" ]; then
# bash autostart for dietpi
sudo bash -c 'echo "# automatic start the LCD info loop" >> /home/dietpi/.bashrc'
sudo bash -c 'echo "SCRIPT=/home/admin/00infoLCD.sh" >> /home/dietpi/.bashrc'
sudo bash -c 'echo "# replace shell with script => logout when exiting script" >> /home/dietpi/.bashrc'
sudo bash -c 'echo "exec \$SCRIPT" >> /home/dietpi/.bashrc'
fi fi
echo "" echo ""
@ -674,6 +750,13 @@ echo "*** HARDENING ***"
sudo apt-get install -y --no-install-recommends python3-systemd fail2ban sudo apt-get install -y --no-install-recommends python3-systemd fail2ban
if [ "${baseImage}" = "raspbian" ]; then if [ "${baseImage}" = "raspbian" ]; then
if [ "${disableWifi}" == "true" ]; then
echo ""
echo "*** DISABLE WIFI ***"
sudo systemctl disable wpa_supplicant.service
sudo ifconfig wlan0 down
fi
echo "" echo ""
echo "*** DISABLE BLUETOOTH ***" echo "*** DISABLE BLUETOOTH ***"
@ -715,37 +798,40 @@ echo ""
# *** RASPIBLITZ LCD DRIVER (do last - because makes a reboot) *** # *** RASPIBLITZ LCD DRIVER (do last - because makes a reboot) ***
# based on https://www.elegoo.com/tutorial/Elegoo%203.5%20inch%20Touch%20Screen%20User%20Manual%20V1.00.2017.10.09.zip # based on https://www.elegoo.com/tutorial/Elegoo%203.5%20inch%20Touch%20Screen%20User%20Manual%20V1.00.2017.10.09.zip
if [ "${baseImage}" = "raspbian" ] || [ "${baseImage}" = "dietpi" ]; then if [ "${lcdInstalled}" == "true" ]; then
echo "*** LCD DRIVER ***" if [ "${baseImage}" = "raspbian" ] || [ "${baseImage}" = "dietpi" ]; then
echo "--> Downloading LCD Driver from Github" echo "*** LCD DRIVER ***"
cd /home/admin/ echo "--> Downloading LCD Driver from Github"
sudo -u admin git clone https://github.com/goodtft/LCD-show.git cd /home/admin/
sudo -u admin chmod -R 755 LCD-show sudo -u admin git clone https://github.com/goodtft/LCD-show.git
sudo -u admin chown -R admin:admin LCD-show sudo -u admin chmod -R 755 LCD-show
cd LCD-show/ sudo -u admin chown -R admin:admin LCD-show
# set comit hard to old version - that seemed to run better cd LCD-show/
# # set comit hard to old version - that seemed to run better
sudo -u admin git reset --hard ce52014 #
sudo -u admin git reset --hard ce52014
# install xinput calibrator package # install xinput calibrator package
echo "--> install xinput calibrator package" echo "--> install xinput calibrator package"
sudo dpkg -i xinput-calibrator_0.7.5-1_armhf.deb sudo apt-get install -y libxi6
fi sudo dpkg -i xinput-calibrator_0.7.5-1_armhf.deb
fi
# make dietpi preparations # make dietpi preparations
if [ "${baseImage}" = "dietpi" ]; then if [ "${baseImage}" = "dietpi" ]; then
echo "--> dietpi preparations" echo "--> dietpi preparations"
sudo rm -rf /etc/X11/xorg.conf.d/40-libinput.conf sudo rm -rf /etc/X11/xorg.conf.d/40-libinput.conf
sudo mkdir /etc/X11/xorg.conf.d sudo mkdir /etc/X11/xorg.conf.d
sudo cp ./usr/tft35a-overlay.dtb /boot/overlays/ sudo cp ./usr/tft35a-overlay.dtb /boot/overlays/
sudo cp ./usr/tft35a-overlay.dtb /boot/overlays/tft35a.dtbo sudo cp ./usr/tft35a-overlay.dtb /boot/overlays/tft35a.dtbo
sudo cp -rf ./usr/99-calibration.conf-35 /etc/X11/xorg.conf.d/99-calibration.conf sudo cp -rf ./usr/99-calibration.conf-35 /etc/X11/xorg.conf.d/99-calibration.conf
sudo cp -rf ./usr/99-fbturbo.conf /usr/share/X11/xorg.conf.d/ sudo cp -rf ./usr/99-fbturbo.conf /usr/share/X11/xorg.conf.d/
sudo cp ./usr/cmdline.txt /DietPi/ sudo cp ./usr/cmdline.txt /DietPi/
sudo cp ./usr/inittab /etc/ sudo cp ./usr/inittab /etc/
sudo cp ./boot/config-35.txt /DietPi/config.txt sudo cp ./boot/config-35.txt /DietPi/config.txt
# make LCD screen rotation correct # make LCD screen rotation correct
sudo sed -i "s/dtoverlay=tft35a/dtoverlay=tft35a:rotate=270/" /DietPi/config.txt sudo sed -i "s/dtoverlay=tft35a/dtoverlay=tft35a:rotate=270/" /DietPi/config.txt
fi
fi fi
# *** RASPIBLITZ IMAGE READY *** # *** RASPIBLITZ IMAGE READY ***
@ -754,27 +840,36 @@ echo "**********************************************"
echo "SD CARD BUILD DONE" echo "SD CARD BUILD DONE"
echo "**********************************************" echo "**********************************************"
echo "" echo ""
echo "Your SD Card Image for RaspiBlitz is almost ready."
if [ "${baseImage}" = "raspbian" ]; then if [ "${lcdInstalled}" == "true" ]; then
echo "Last step is to install LCD drivers. This will reboot your Pi when done." echo "Your SD Card Image for RaspiBlitz is almost ready."
echo "" if [ "${baseImage}" = "raspbian" ]; then
echo "Last step is to install LCD drivers. This will reboot your Pi when done."
echo ""
fi
else
echo "Your SD Card Image for RaspiBlitz is ready."
fi fi
echo "Take the chance & look thru the output above if you can spot any errror." echo "Take the chance & look thru the output above if you can spot any errror."
echo "" echo ""
echo "After final reboot - your SD Card Image is ready." if [ "${lcdInstalled}" == "true" ]; then
echo "" echo "After final reboot - your SD Card Image is ready."
echo ""
fi
echo "IMPORTANT IF WANT TO MAKE A RELEASE IMAGE FROM THIS BUILD:" echo "IMPORTANT IF WANT TO MAKE A RELEASE IMAGE FROM THIS BUILD:"
echo "login once after reboot without external HDD/SSD and run 'XXprepareRelease.sh'" echo "login once after reboot without external HDD/SSD and run 'XXprepareRelease.sh'"
echo "REMEMBER for login now use --> user:admin password:raspiblitz" echo "REMEMBER for login now use --> user:admin password:raspiblitz"
echo "" echo ""
# activate LCD and trigger reboot sudo chmod +x -R /home/admin/LCD-show
# dont do this on dietpi to allow for automatic build if [ "${lcdInstalled}" == "true" ]; then
if [ "${baseImage}" = "raspbian" ]; then # activate LCD and trigger reboot
sudo chmod +x -R /home/admin/LCD-show # dont do this on dietpi to allow for automatic build
cd /home/admin/LCD-show/ if [ "${baseImage}" = "raspbian" ]; then
sudo apt-mark hold raspberrypi-bootloader cd /home/admin/LCD-show/
sudo ./LCD35-show sudo apt-mark hold raspberrypi-bootloader
else sudo ./LCD35-show
echo "Use 'sudo reboot' to restart manually." else
echo "Use 'sudo reboot' to restart manually."
fi
fi fi