Skip to content

Commit

Permalink
Merge pull request #4537 from raspiblitz/dev
Browse files Browse the repository at this point in the history
v1.11.0rc7
  • Loading branch information
rootzoll committed Apr 8, 2024
2 parents f9ae449 + 208cd6a commit 125de57
Show file tree
Hide file tree
Showing 12 changed files with 204 additions and 104 deletions.
73 changes: 45 additions & 28 deletions build_sdcard.sh
Expand Up @@ -270,6 +270,17 @@ else
fi
echo "baseimage=${baseimage}"

# AUTO-DETECTION: CONFIGFILES
# ---------------------------------------
raspi_configfile="/boot/config.txt"
raspi_commandfile="/boot/cmdline.txt"
if [ -d /boot/firmware ];then
raspi_configfile="/boot/firmware/config.txt"
raspi_commandfile="/boot/firmware/cmdline.txt"
fi
echo "raspi_configfile=${raspi_configfile}"
echo "raspi_commandfile=${raspi_commandfile}"

# USER-CONFIRMATION
if [ "${interaction}" = "true" ]; then
echo -n "# Do you agree with all parameters above? (yes/no) "
Expand Down Expand Up @@ -431,6 +442,19 @@ if ! compgen -u pi; then
adduser pi sudo
fi

# activate watchdog if ls /dev/watchdog exists - see #4534
if [ -e /dev/watchdog ]; then
echo "Activating watchdog ..."
if [ "${baseimage}" = "raspios_arm64" ]; then
echo "dtparam=watchdog=on" | tee -a $raspi_configfile
fi
sed -i "s/^#RuntimeWatchdogSec=.*/RuntimeWatchdogSec=600s/g" /etc/systemd/system.conf
sed -i "s/^#RebootWatchdogSec=.*/RebootWatchdogSec=3min/g" /etc/systemd/system.conf
sed -i "s/^#WatchdogDevice=.*/WatchdogDevice=\/dev\/watchdog/g" /etc/systemd/system.conf
else
echo "No watchdog device /dev/watchdog found - keep watchdog like default"
fi

# special prepare when RaspberryPi OS
if [ "${baseimage}" = "raspios_arm64" ]; then

Expand All @@ -441,27 +465,21 @@ if [ "${baseimage}" = "raspios_arm64" ]; then
[ "${wifi_region}" != "off" ] && raspi-config nonint do_wifi_country $wifi_region
# see https://github.com/rootzoll/raspiblitz/issues/428#issuecomment-472822840

if [ -d /boot/firmware ];then
configFile="/boot/firmware/config.txt"
else
configFile="/boot/config.txt"
fi
if ! grep "Raspiblitz" $configFile; then
echo "# Adding Raspiblitz Edits to $configFile"
echo | tee -a $configFile
echo "# Raspiblitz" | tee -a $configFile
if ! grep "Raspiblitz" $raspi_configfile; then
echo "# Adding Raspiblitz Edits to $raspi_configfile"
echo | tee -a $raspi_configfile
echo "# Raspiblitz" | tee -a $raspi_configfile
# ensure that kernel8.img is used to set PAGE_SIZE to 4K
# https://github.com/raspiblitz/raspiblitz/issues/4346
if [ -f /boot/kernel8.img ] || [ -f /boot/firmware/kernel8.img ]; then
echo 'kernel=kernel8.img' | tee -a $configFile
echo 'kernel=kernel8.img' | tee -a $raspi_configfile
fi
echo "max_usb_current=1" | tee -a $configFile
echo "dtparam=nvme" | tee -a $configFile
echo "dtparam=watchdog=on" | tee -a $configFile
echo 'dtoverlay=pi3-disable-bt' | tee -a $configFile
echo 'dtoverlay=disable-bt' | tee -a $configFile
echo "max_usb_current=1" | tee -a $raspi_configfile
echo "dtparam=nvme" | tee -a $raspi_configfile
echo 'dtoverlay=pi3-disable-bt' | tee -a $raspi_configfile
echo 'dtoverlay=disable-bt' | tee -a $raspi_configfile
else
echo "# Raspiblitz Edits are already in $configFile"
echo "# Raspiblitz Edits are already in $raspi_configfile"
fi

# run fsck on sd root partition on every startup to prevent "maintenance login" screen
Expand All @@ -476,23 +494,22 @@ if [ "${baseimage}" = "raspios_arm64" ]; then
fi

# edit kernel parameters
kernelOptionsFile=/boot/cmdline.txt
fsOption1="fsck.mode=force"
fsOption2="fsck.repair=yes"
fsOption1InFile=$(grep -c ${fsOption1} ${kernelOptionsFile})
fsOption2InFile=$(grep -c ${fsOption2} ${kernelOptionsFile})
fsOption1InFile=$(grep -c ${fsOption1} ${raspi_commandfile})
fsOption2InFile=$(grep -c ${fsOption2} ${raspi_commandfile})

if [ ${fsOption1InFile} -eq 0 ]; then
sed -i "s/^/$fsOption1 /g" "$kernelOptionsFile"
echo "$fsOption1 added to $kernelOptionsFile"
sed -i "s/^/$fsOption1 /g" "${raspi_commandfile}"
echo "$fsOption1 added to ${raspi_commandfile}"
else
echo "$fsOption1 already in $kernelOptionsFile"
echo "$fsOption1 already in ${raspi_commandfile}"
fi
if [ ${fsOption2InFile} -eq 0 ]; then
sed -i "s/^/$fsOption2 /g" "$kernelOptionsFile"
echo "$fsOption2 added to $kernelOptionsFile"
sed -i "s/^/$fsOption2 /g" "${raspi_commandfile}"
echo "$fsOption2 added to ${raspi_commandfile}"
else
echo "$fsOption2 already in $kernelOptionsFile"
echo "$fsOption2 already in ${raspi_commandfile}"
fi

# *** SAFE SHUTDOWN ***
Expand Down Expand Up @@ -783,16 +800,16 @@ if [ "${baseimage}" = "raspios_arm64" ] || [ "${baseimage}" = "debian" ]; then

# disable audio
echo -e "\n*** DISABLE AUDIO (snd_bcm2835) ***"
sed -i "s/^dtparam=audio=on/# dtparam=audio=on/g" /boot/config.txt
sed -i "s/^dtparam=audio=on/# dtparam=audio=on/g" ${raspi_configfile}

# disable DRM VC4 V3D
echo -e "\n*** DISABLE DRM VC4 V3D driver ***"
dtoverlay=vc4-fkms-v3d
sed -i "s/^dtoverlay=${dtoverlay}/# dtoverlay=${dtoverlay}/g" /boot/config.txt
sed -i "s/^dtoverlay=${dtoverlay}/# dtoverlay=${dtoverlay}/g" ${raspi_configfile}

# I2C fix (make sure dtparam=i2c_arm is not on)
# see: https://github.com/rootzoll/raspiblitz/issues/1058#issuecomment-739517713
sed -i "s/^dtparam=i2c_arm=.*//g" /boot/config.txt
sed -i "s/^dtparam=i2c_arm=.*//g" ${raspi_configfile}
fi

# *** BOOTSTRAP ***
Expand Down
3 changes: 1 addition & 2 deletions ci/packer.sh
Expand Up @@ -241,8 +241,7 @@ fi


echo "# clean up"
cd ..
rm -rf raspiblitz 2>/dev/null
rm -rf ./../raspiblitz 2>/dev/null

echo "# SIGN & SECURE IMAGE ###########################################"
echo
Expand Down
2 changes: 2 additions & 0 deletions home.admin/_background.scan.sh
Expand Up @@ -275,6 +275,8 @@ do
###################
# HARDDRIVE

# info on storage medium
source <(/home/admin/_cache.sh valid hdd_mounted)
if [ "${stillvalid}" == "0" ] || [ ${age} -gt ${MINUTE2} ]; then
echo "updating: /home/admin/config.scripts/blitz.datadrive.sh status"
source <(/home/admin/config.scripts/blitz.datadrive.sh status)
Expand Down
43 changes: 38 additions & 5 deletions home.admin/_background.sh
Expand Up @@ -19,6 +19,15 @@ echo "INFO: _background.sh loop started - sudo journalctl -f -u background" >> /
blitzTUIHeartBeatLine=""
/home/admin/_cache.sh set blitzTUIRestarts "0"

# determine correct raspberrypi boot drive path (that easy to access when sd card is insert into laptop)
raspi_bootdir=""
if [ -d /boot/firmware ]; then
raspi_bootdir="/boot/firmware"
elif [ -d /boot ]; then
raspi_bootdir="/boot"
fi
echo "# raspi_bootdir(${raspi_bootdir})"

counter=0
while [ 1 ]
do
Expand Down Expand Up @@ -481,11 +490,35 @@ do
echo "--> Channel Backup File changed"

# make copy to sd card (as local basic backup)
mkdir -p /home/admin/backups/scb/ 2>/dev/null
mkdir -p ${localBackupDir} 2>/dev/null
cp $scbPath $localBackupPath
if [ $? -eq 0 ]; then
echo "OK channel.backup copied to '${localBackupPath}'"
else
logger -p daemon.err "_background.sh FAIL channel.backup copy to '${localBackupPath}'"
echo "FAIL channel.backup copy to '${localBackupPath}'"
fi

cp $scbPath $localTimestampedPath
cp $scbPath /boot/firmware/channel.backup
echo "OK channel.backup copied to '${localBackupPath}' and '${localTimestampedPath}' and '/boot/firmware/channel.backup'"
if [ $? -eq 0 ]; then
echo "OK channel.backup copied to '${localTimestampedPath}'"
else
logger -p daemon.err "_background.sh FAIL channel.backup copy to '${localTimestampedPath}'"
echo "FAIL channel.backup copy to '${localTimestampedPath}'"
fi

# copy to boot drive (for easy recovery)
if [ "${raspi_bootdir}" != "" ]; then
cp $scbPath ${raspi_bootdir}/channel.backup
if [ $? -eq 0 ]; then
echo "OK channel.backup copied to '${raspi_bootdir}/channel.backup'"
else
logger -p daemon.err "_background.sh FAIL channel.backup copy to '${raspi_bootdir}/channel.backup'"
echo "FAIL channel.backup copy to '${raspi_bootdir}/channel.backup'"
fi
else
echo "No boot drive found - skip copy to boot"
fi

# check if a additional local backup target is set
# see ./config.scripts/blitz.backupdevice.sh
Expand Down Expand Up @@ -590,8 +623,8 @@ do
mkdir -p /home/admin/backups/er/ 2>/dev/null
cp $erPath $localBackupPath
cp $erPath $localTimestampedPath
cp $erPath /boot/firmware/${netprefix}emergency.recover
echo "OK emergency.recover copied to '${localBackupPath}' and '${localTimestampedPath}' and '/boot/firmware/${netprefix}emergency.recover'"
cp $erPath ${raspi_bootdir}/${netprefix}emergency.recover
echo "OK emergency.recover copied to '${localBackupPath}' and '${localTimestampedPath}' and '${raspi_bootdir}/${netprefix}emergency.recover'"

# check if a additional local backup target is set
# see ./config.scripts/blitz.backupdevice.sh
Expand Down
47 changes: 29 additions & 18 deletions home.admin/_bootstrap.sh
Expand Up @@ -115,11 +115,20 @@ chmod 664 ${infoFile}
# write content of raspiblitz.info to logs
cat $infoFile >> $logFile

# determine correct raspberrypi boot drive path (that easy to access when sd card is insert into laptop)
raspi_bootdir=""
if [ -d /boot/firmware ]; then
raspi_bootdir="/boot/firmware"
elif [ -d /boot ]; then
raspi_bootdir="/boot"
fi
echo "# raspi_bootdir(${raspi_bootdir})" >> $logFile

######################################
# STOP file flag - for manual provision

# when a file 'stop' is on the sd card bootfs partition root - stop for manual provision
flagExists=$(ls /boot/firmware/stop | grep -c 'stop')
flagExists=$(ls ${raspi_bootdir}/stop 2>/dev/null | grep -c 'stop')
if [ "${flagExists}" == "1" ]; then
# set state info
/home/admin/_cache.sh set state "stop"
Expand Down Expand Up @@ -173,8 +182,8 @@ source ${configFile} 2>/dev/null
# CHECK SD CARD STATE

# wifi config by file on sd card
wifiFileExists=$(ls /boot/firmware/wifi | grep -c 'wifi')
wpaFileExists=$(ls /boot/firmware/wpa_supplicant.conf | grep -c 'wpa_supplicant.conf')
wifiFileExists=$(ls ${raspi_bootdir}/wifi 2>/dev/null | grep -c 'wifi')
wpaFileExists=$(ls ${raspi_bootdir}/wpa_supplicant.conf 2>/dev/null | grep -c 'wpa_supplicant.conf')
if [ "${wifiFileExists}" == "1" ] || [ "${wpaFileExists}" == "1" ]; then

# set info
Expand All @@ -185,25 +194,25 @@ if [ "${wifiFileExists}" == "1" ] || [ "${wpaFileExists}" == "1" ]; then
# get first line as string from wifi file (NAME OF WIFI)
# get second line as string from wifi file (PASSWORD OF WIFI)
if [ "${wifiFileExists}" == "1" ]; then
echo "Getting data from file: /boot/firmware/wifi" >> ${logFile}
ssid=$(sed -n '1p' /boot/firmware/wifi | tr -d '[:space:]')
password=$(sed -n '2p' /boot/firmware/wifi | tr -d '[:space:]')
echo "Getting data from file: ${raspi_bootdir}/wifi" >> ${logFile}
ssid=$(sed -n '1p' ${raspi_bootdir}/wifi | tr -d '[:space:]')
password=$(sed -n '2p' ${raspi_bootdir}/wifi | tr -d '[:space:]')
fi

# File: wpa_supplicant.conf (legacy way to set wifi)
# see: https://github.com/raspibolt/raspibolt/blob/a21788c0518618d17093e3f447f68a53e4efa6e7/raspibolt/raspibolt_20_pi.md#prepare-wifi
if [ "${wpaFileExists}" == "1" ]; then
echo "Getting data from file: /boot/firmware/wpa_supplicant.conf" >> ${logFile}
ssid=$(grep ssid "/boot/firmware/wpa_supplicant.conf" | awk -F'=' '{print $2}' | tr -d '"')
password=$(grep psk "/boot/firmware/wpa_supplicant.conf" | awk -F'=' '{print $2}' | tr -d '"')
echo "Getting data from file: ${raspi_bootdir}/wpa_supplicant.conf" >> ${logFile}
ssid=$(grep ssid "${raspi_bootdir}/wpa_supplicant.conf" | awk -F'=' '{print $2}' | tr -d '"')
password=$(grep psk "${raspi_bootdir}/wpa_supplicant.conf" | awk -F'=' '{print $2}' | tr -d '"')
fi

# set wifi
err=""
echo "Setting Wifi SSID(${ssid}) Password(${password})" >> ${logFile}
source <(/home/admin/config.scripts/internet.wifi.sh on ${ssid} ${password})
if [ "${err}" != "" ]; then
echo "Setting Wifi failed - edit or remove file /boot/firmware/wifi" >> ${logFile}
echo "Setting Wifi failed - edit or remove file ${raspi_bootdir}/wifi" >> ${logFile}
echo "error(${err})" >> ${logFile}
echo "Will shutdown in 1min ..." >> ${logFile}
/home/admin/_cache.sh set state "errorWIFI"
Expand All @@ -215,8 +224,8 @@ if [ "${wifiFileExists}" == "1" ] || [ "${wpaFileExists}" == "1" ]; then

# remove file
echo "Setting Wifi worked - removing file" >> ${logFile}
rm /boot/firmware/wifi 2>/dev/null
rm /boot/firmware/wpa_supplicant.conf 2>/dev/null
rm ${raspi_bootdir}/wifi 2>/dev/null
rm ${raspi_bootdir}/wpa_supplicant.conf 2>/dev/null
else
echo "No Wifi config by file on sd card." >> ${logFile}
fi
Expand Down Expand Up @@ -315,10 +324,10 @@ systemInitReboot=0
# the sd card - switch to hdmi
################################

forceHDMIoutput=$(ls /boot/firmware/hdmi* 2>/dev/null | grep -c hdmi)
forceHDMIoutput=$(ls ${raspi_bootdir}/hdmi* 2>/dev/null | grep -c hdmi)
if [ ${forceHDMIoutput} -eq 1 ]; then
# delete that file (to prevent loop)
rm /boot/hdmi*
rm ${raspi_bootdir}/hdmi*
# switch to HDMI what will trigger reboot
echo "HDMI switch found ... activating HDMI display output & reboot" >> $logFile
/home/admin/config.scripts/blitz.display.sh set-display hdmi >> $logFile
Expand Down Expand Up @@ -391,10 +400,10 @@ fi
# the sd card - delete old ssh data
################################

sshReset=$(ls /boot/firmware/ssh.reset* 2>/dev/null | grep -c reset)
sshReset=$(ls ${raspi_bootdir}/ssh.reset* 2>/dev/null | grep -c reset)
if [ ${sshReset} -eq 1 ]; then
# delete that file (to prevent loop)
rm /boot/firmware/ssh.reset* >> $logFile
rm ${raspi_bootdir}/ssh.reset* >> $logFile
# delete ssh certs
echo "SSHRESET switch found ... stopping SSH and deleting old certs" >> $logFile
/home/admin/config.scripts/blitz.ssh.sh renew >> $logFile
Expand Down Expand Up @@ -668,7 +677,7 @@ if [ ${isMounted} -eq 0 ]; then

# check if there is a flag set on sd card boot section to format as btrfs (experimental)
filesystem="ext4"
flagBTRFS=$(ls /boot/firmware/btrfs* 2>/dev/null | grep -c btrfs)
flagBTRFS=$(ls ${raspi_bootdir}/btrfs* 2>/dev/null | grep -c btrfs)
if [ "${flagBTRFS}" != "0" ]; then
echo "Found BTRFS flag ---> formatting with experimental BTRFS filesystem" >> ${logFile}
filesystem="btrfs"
Expand Down Expand Up @@ -980,6 +989,7 @@ if [ ${isMounted} -eq 0 ]; then

# system has to wait before reboot to present like seed words and other info/options to user
echo "BOOTSTRAP EXIT ... waiting for final setup controller to initiate final reboot." >> $logFile
echo "------------> You may login thru web browser to continue setup." >> $logFile
exit 1

else
Expand Down Expand Up @@ -1098,8 +1108,9 @@ fi
# FORCE UASP FLAG
####################
# if uasp.force flag was set on sd card - now move into raspiblitz.conf
if [ -f "/boot/firmware/uasp.force" ]; then
if [ -f "${raspi_bootdir}/uasp.force" ]; then
/home/admin/config.scripts/blitz.conf.sh set forceUasp "on"
rm ${raspi_bootdir}/uasp.force* >> $logFile
echo "DONE forceUasp=on recorded in raspiblitz.conf" >> $logFile
fi

Expand Down
2 changes: 1 addition & 1 deletion home.admin/_version.info
@@ -1,3 +1,3 @@
# RaspiBlitz Version - always [major].[main].[sub] (sub can be a string like '2rc1')
codeVersion="1.11.0rc6"
codeVersion="1.11.0rc7"
# keep last line with comment ---> IF YOU HAVE A NEW VERSION BRANCH > EDIT ALSO build_sdcard.sh
21 changes: 15 additions & 6 deletions home.admin/config.scripts/blitz.datadrive.sh
Expand Up @@ -26,6 +26,15 @@ if [ "$EUID" -ne 0 ]; then
exit 1
fi

# determine correct raspberrypi boot drive path (that easy to access when sd card is insert into laptop)
raspi_bootdir=""
if [ -d /boot/firmware ]; then
raspi_bootdir="/boot/firmware"
elif [ -d /boot ]; then
raspi_bootdir="/boot"
fi
echo "# raspi_bootdir(${raspi_bootdir})"

# install BTRFS if needed
btrfsInstalled=$(btrfs --version 2>/dev/null | grep -c "btrfs-progs")
if [ ${btrfsInstalled} -eq 0 ]; then
Expand Down Expand Up @@ -561,7 +570,7 @@ if [ "$1" = "status" ]; then
hddAdapterUSAP=0

# check if force UASP flag is set on sd card
if [ -f "/boot/firmware/uasp.force" ]; then
if [ -f "${raspi_bootdir}/uasp.force" ]; then
hddAdapterUSAP=1
fi
# or UASP is set by config file
Expand Down Expand Up @@ -1881,18 +1890,18 @@ if [ "$1" = "uasp-fix" ]; then

# check if UASP is already deactivated (on RaspiOS)
# https://www.pragmaticlinux.com/2021/03/fix-for-getting-your-ssd-working-via-usb-3-on-your-raspberry-pi/
cmdlineExists=$(ls /boot/cmdline.txt 2>/dev/null | grep -c "cmdline.txt")
cmdlineExists=$(ls ${raspi_bootdir}/cmdline.txt 2>/dev/null | grep -c "cmdline.txt")
if [ ${cmdlineExists} -eq 1 ] && [ ${#hddAdapterUSB} -gt 0 ] && [ ${hddAdapterUSAP} -eq 0 ]; then
echo "# Checking for UASP deactivation ..."
usbQuirkActive=$(cat /boot/cmdline.txt | grep -c "usb-storage.quirks=")
usbQuirkDone=$(cat /boot/cmdline.txt | grep -c "usb-storage.quirks=${hddAdapterUSB}:u")
usbQuirkActive=$(cat ${raspi_bootdir}/cmdline.txt | grep -c "usb-storage.quirks=")
usbQuirkDone=$(cat ${raspi_bootdir}/cmdline.txt | grep -c "usb-storage.quirks=${hddAdapterUSB}:u")
if [ ${usbQuirkActive} -gt 0 ] && [ ${usbQuirkDone} -eq 0 ]; then
# remove old usb-storage.quirks
sed -i "s/usb-storage.quirks=[^ ]* //g" /boot/cmdline.txt
sed -i "s/usb-storage.quirks=[^ ]* //g" ${raspi_bootdir}/cmdline.txt
fi
if [ ${usbQuirkDone} -eq 0 ]; then
# add new usb-storage.quirks
sed -i "s/^/usb-storage.quirks=${hddAdapterUSB}:u /" /boot/cmdline.txt
sed -i "s/^/usb-storage.quirks=${hddAdapterUSB}:u /" ${raspi_bootdir}/cmdline.txt
# go into reboot to activate new setting
echo "# DONE deactivating UASP for ${hddAdapterUSB} ... reboot needed"
echo "neededReboot=1"
Expand Down

0 comments on commit 125de57

Please sign in to comment.