Skip to content

Commit

Permalink
Update create_latest_candle.sh
Browse files Browse the repository at this point in the history
  • Loading branch information
flatsiedatsie committed Jan 30, 2023
1 parent 96eb532 commit 56993f4
Showing 1 changed file with 118 additions and 78 deletions.
196 changes: 118 additions & 78 deletions create_latest_candle.sh
Expand Up @@ -9,14 +9,15 @@ set +e # continue on errors

# By default it acts as an upgrade script (not doing a factory reset at the end, rebooting the system when done)

# If you want to use this script to directly create disk images, then you can use:
# If you want to use this script to directly create disk imagesrecovery, then you can use:
# export CREATE_DISK_IMAGE=yes

# Set the script to download the very latest available version. Risky. Enabling this creates the /boot/candle_cutting_edge.txt file
# export CUTTING_EDGE=yes

# Other parts of the script that can be skipped:
# export SKIP_PARTITIONS=yes
# export TINY_PARTITIONS=yes
# export SKIP_APT_INSTALL=yes
# export SKIP_APT_UPGRADE=yes
# export SKIP_PYTHON=yes
Expand All @@ -27,6 +28,7 @@ set +e # continue on errors
# export SKIP_REBOOT=yes

#SKIP_PARTITIONS=yes
#TINY_PARTITIONS=yes # used to create smaller partition images, which are used in the new system update process
#SKIP_APT_INSTALL=yes
#SKIP_APT_UPGRADE=yes
#SKIP_PYTHON=yes
Expand Down Expand Up @@ -272,14 +274,24 @@ then
echo "Candle: creating partitions" >> /dev/kmsg
echo "Candle: creating partitions" >> /boot/candle_log.txt
echo

printf "resizepart 2 7000\nmkpart\np\next4\n7001MB\n7500MB\nmkpart\np\next4\n7502MB\n14000MB\nquit" | parted
resize2fs /dev/mmcblk0p2
if [[ -z "${TINY_PARTITIONS}" ]]; then
printf "resizepart 2 7000MB\nmkpart\np\next4\n7001MB\n7500MB\nmkpart\np\next4\n7502MB\n14000MB\nquit" | parted
resize2fs /dev/mmcblk0p2

else
printf "resizepart 2 5000MB\nmkpart\np\next4\n5001MB\n7500MB\nmkpart\np\next4\n7502MB\n9500MB\nquit" | parted
resize2fs /dev/mmcblk0p2
fi

printf "y" | mkfs.ext4 /dev/mmcblk0p3
printf "y" | mkfs.ext4 /dev/mmcblk0p4
mkdir -p /home/pi/.webthings
chown pi:pi /home/pi/.webthings
touch /boot/candle_has_4th_partition.txt

e2label /dev/mmcblk0p2 system
e2label /dev/mmcblk0p3 recovery
e2label /dev/mmcblk0p4 user
else
echo
echo "Partition 2 was missing. Inside chroot?"
Expand Down Expand Up @@ -342,47 +354,14 @@ fi
sleep 3
cd /home/pi

# only install the recovery partition if the system has a recovery partition
if lsblk | grep -q 'mmcblk0p4'; then

cd /home/pi/.webthings

if [ -f recovery.fs ]; then
echo "Warning, recovery.fs already existed. Removing it first."
rm recovery.fs
fi

echo "Downloading the recovery partition"
echo "Downloading the recovery partition" >> /dev/kmsg
echo "Downloading the recovery partition" >> /boot/candle_log.txt

wget -c https://www.candlesmarthome.com/img/recovery/recovery.fs.tar.gz -O recovery.fs.tar.gz

echo "untarring the recovery partition"
tar xf recovery.fs.tar.gz

if [ -f recovery.fs ]; then # -n is for "non-zero string"
#echo "Mounting the recovery partition"
#losetup --partscan /dev/loop0 recovery.img

echo "Copying recovery partition data"
echo "Copying recovery partition data" >> /dev/kmsg
echo "Copying recovery partition data" >> /boot/candle_log.txt
dd if=recovery.fs of=/dev/mmcblk0p3 bs=1M

#if [ -n "$(lsblk | grep loop0p2)" ] && [ -n "$(lsblk | grep mmcblk0p3)" ]; then
#fi
else
echo "ERROR, failed to download or extract the recovery disk image"
echo "ERROR, failed to download or extract the recovery disk image" >> /dev/kmsg
echo "ERROR, failed to download or extract the recovery disk image" >> /boot/candle_log.txt
fi

recovery.fs.tar.gz
rm recovery.fs
# Save the bits of the initial kernel the boot partition to a file
if [ "$BIT_TYPE" == 64 ]; then
echo "creating /boot/candle_64bits.txt"
echo "creating /boot/candle_64bits.txt" >> /dev/kmsg
touch /boot/candle_64bits.txt
fi

cd /home/pi

# Make sure there is a current time
if [ -f /boot/candle_hardware_clock.txt ]; then
Expand Down Expand Up @@ -527,7 +506,7 @@ echo
if [ -f /boot/candle_cutting_edge.txt ]; then
echo "Candle: Downloading cutting edge read-only script" >> /dev/kmsg
echo "Candle: Downloading cutting edge read-only script" >> /boot/candle_log.txt
wget https://raw.githubusercontent.com/createcandle/ro-overlay/main/bin/ro-root.sh -O ./ro-root.sh
wget https://raw.githubusercontent.com/createcandle/ro-overlay/main/bin/ro-root.sh -O ./ro-root.sh --retry-connrefused

else
echo "Candle: Downloading stable read-only script" >> /dev/kmsg
Expand All @@ -537,7 +516,7 @@ else
| cut -d : -f 2,3 \
| tr -d \" \
| sed 's/,*$//' \
| wget -qi - -O ro-overlay.tar
| wget -qi - -O ro-overlay.tar --retry-connrefused

if [ -f ro-overlay.tar ]; then

Expand Down Expand Up @@ -845,14 +824,14 @@ fi

# Download splash images
if [ -f /boot/cmdline.txt ]; then
wget https://www.candlesmarthome.com/tools/error.png -O /boot/error.png
wget https://www.candlesmarthome.com/tools/error.png -O /boot/error.png --retry-connrefused
echo
echo "Candle: downloading splash images and videos" >> /dev/kmsg
echo "Candle: downloading splash images and videos" >> /boot/candle_log.txt
echo

wget https://www.candlesmarthome.com/tools/splash_updating.png -O /boot/splash_updating.png
wget https://www.candlesmarthome.com/tools/splash_updating180.png -O /boot/splash_updating180.png
wget https://www.candlesmarthome.com/tools/splash_updating.png -O /boot/splash_updating.png --retry-connrefused
wget https://www.candlesmarthome.com/tools/splash_updating180.png -O /boot/splash_updating180.png --retry-connrefused

if [ "$scriptname" = "bootup_actions.sh" ] || [ "$scriptname" = "bootup_actions_failed.sh" ] || [ "$scriptname" = "post_bootup_actions.sh" ] || [ "$scriptname" = "post_bootup_actions_failed.sh" ];
then
Expand Down Expand Up @@ -883,12 +862,15 @@ if [ -f /boot/cmdline.txt ]; then
fi

# Download the rest of the images
wget https://www.candlesmarthome.com/tools/splash.png -O /boot/splash.png
wget https://www.candlesmarthome.com/tools/splash180.png -O /boot/splash180.png
wget https://www.candlesmarthome.com/tools/splashalt.png -O /boot/splashalt.png
wget https://www.candlesmarthome.com/tools/splash180alt.png -O /boot/splash180alt.png
wget https://www.candlesmarthome.com/tools/splash.mp4 -O /boot/splash.mp4
wget https://www.candlesmarthome.com/tools/splash180.mp4 -O /boot/splash180.mp4
wget https://www.candlesmarthome.com/tools/splash.png -O /boot/splash.png --retry-connrefused
wget https://www.candlesmarthome.com/tools/splash180.png -O /boot/splash180.png --retry-connrefused
wget https://www.candlesmarthome.com/tools/splashalt.png -O /boot/splashalt.png --retry-connrefused
wget https://www.candlesmarthome.com/tools/splash180alt.png -O /boot/splash180alt.png --retry-connrefused
wget https://www.candlesmarthome.com/tools/splash.mp4 -O /boot/splash.mp4 --retry-connrefused
wget https://www.candlesmarthome.com/tools/splash180.mp4 -O /boot/splash180.mp4 --retry-connrefused
wget https://www.candlesmarthome.com/tools/splash_preparing.png -O /boot/splash_preparing.png --retry-connrefused
wget https://www.candlesmarthome.com/tools/splash_preparing180.png -O /boot/splash_preparing180.png --retry-connrefused

fi


Expand Down Expand Up @@ -940,7 +922,7 @@ else
| cut -d : -f 2,3 \
| tr -d \" \
| sed 's/,*$//' \
| wget -qi - -O configuration-files.tar
| wget -qi - -O configuration-files.tar --retry-connrefused

tar -xf configuration-files.tar
rm configuration-files.tar
Expand Down Expand Up @@ -1007,7 +989,7 @@ then
echo "Candle: Starting download of cutting edge controller install script" >> /dev/kmsg
echo "Candle: Starting download of cutting edge controller install script" >> /boot/candle_log.txt
echo
wget https://raw.githubusercontent.com/createcandle/install-scripts/main/install_candle_controller.sh -O ./install_candle_controller.sh
wget https://raw.githubusercontent.com/createcandle/install-scripts/main/install_candle_controller.sh -O ./install_candle_controller.sh --retry-connrefused

else
echo "Candle: Starting download of stable controller install script"
Expand All @@ -1019,7 +1001,7 @@ then
| cut -d : -f 2,3 \
| tr -d \" \
| sed 's/,*$//' \
| wget -qi - -O install-scripts.tar
| wget -qi - -O install-scripts.tar --retry-connrefused

tar -xf install-scripts.tar
rm install-scripts.tar
Expand All @@ -1045,8 +1027,8 @@ then
echo "Candle: Starting download of stable controller tar"
echo "Candle: Starting download of stable controller tar. Takes a while." >> /dev/kmsg
echo "Candle: Starting download of stable controller tar" >> /boot/candle_log.txt
wget -nv https://www.candlesmarthome.com/img/controller/latest_stable_controller.tar -O /home/pi/latest_stable_controller.tar
wget -nv https://www.candlesmarthome.com/img/controller/latest_stable_controller.tar.txt -O /home/pi/latest_stable_controller.tar.txt
wget -nv https://www.candlesmarthome.com/img/controller/latest_stable_controller.tar -O /home/pi/latest_stable_controller.tar --retry-connrefused
wget -nv https://www.candlesmarthome.com/img/controller/latest_stable_controller.tar.txt -O /home/pi/latest_stable_controller.tar.txt --retry-connrefused

if [ -f /home/pi/latest_stable_controller.tar ] && [ -f /home/pi/latest_stable_controller.tar.txt ]; then

Expand Down Expand Up @@ -1836,10 +1818,61 @@ rm -rf bluez-alsa



echo ""
echo "INSTALLING RECOVERY PARTITION"
echo ""

# only install the recovery partition if the system has a recovery partition
if lsblk | grep -q 'mmcblk0p4'; then

cd /home/pi/.webthings

if [ -f recovery.fs ]; then
echo "Warning, recovery.fs already existed. Removing it first."
rm recovery.fs
fi

echo "Downloading the recovery partition"
echo "Downloading the recovery partition" >> /dev/kmsg
echo "Downloading the recovery partition" >> /boot/candle_log.txt

wget https://www.candlesmarthome.com/img/recovery/recovery.fs.tar.gz -O recovery.fs.tar.gz --retry-connrefused

if [ -f recovery.fs.tar.gz ]; then
echo "untarring the recovery partition"
tar xf recovery.fs.tar.gz

if [ -f recovery.fs ]; then # -n is for "non-zero string"
#echo "Mounting the recovery partition"
#losetup --partscan /dev/loop0 recovery.img

echo "Copying recovery partition data"
echo "Copying recovery partition data" >> /dev/kmsg
echo "Copying recovery partition data" >> /boot/candle_log.txt
dd if=recovery.fs of=/dev/mmcblk0p3 bs=1M

#if [ -n "$(lsblk | grep loop0p2)" ] && [ -n "$(lsblk | grep mmcblk0p3)" ]; then
#fi
else
echo "ERROR, failed to download or extract the recovery disk image"
echo "ERROR, failed to download or extract the recovery disk image" >> /dev/kmsg
echo "ERROR, failed to download or extract the recovery disk image" >> /boot/candle_log.txt
fi

rm recovery.fs.tar.gz
rm recovery.fs
else
echo "ERROR, recovery partition file not downloaded"

# Show error image
if [ -e "/bin/ply-image" ] && [ -e /dev/fb0 ] && [ -f /boot/error.png ]; then
/bin/ply-image /boot/error.png
#sleep 7200
fi

exit 1
fi
fi



Expand All @@ -1851,6 +1884,8 @@ echo
echo "INSTALLING OTHER FILES AND SERVICES"
echo

systemctl stop triggerhappy.socket
systemctl stop triggerhappy.service

# switch back to root of home folder
cd /home/pi
Expand Down Expand Up @@ -1908,9 +1943,9 @@ if [ ! -d /home/pi/.webthings/tmp ]; then
fi
chmod 1777 /home/pi/.webthings/tmp
find /home/pi/.webthings/tmp \
-mindepth 1 \
-name '.*-unix' -exec chmod 1777 {} + -prune -o \
-exec chmod go-rwx {} +
-mindepth 1 \
-name '.*-unix' -exec chmod 1777 {} + -prune -o \
-exec chmod go-rwx {} +


# Prepare a location for Matter settings
Expand Down Expand Up @@ -2022,6 +2057,7 @@ fi
# CHMOD THE NEW FILES
chmod +x /home/pi/candle/early.sh
chmod +x /etc/rc.local
chmod +x /home/pi/candle/reboot_to_recovery.sh
chmod +x /etc/xdg/openbox/autostart
chmod +x /home/pi/candle/late.sh
chmod +x /home/pi/candle/every_minute.sh
Expand Down Expand Up @@ -2301,7 +2337,7 @@ fi

# Disable Openbox keyboard shortcuts to make the kiosk mode harder to escape
#rm /etc/xdg/openbox/rc.xml
#wget https://www.candlesmarthome.com/tools/rc.xml /etc/xdg/openbox/rc.xml
#wget https://www.candlesmarthome.com/tools/rc.xml /etc/xdg/openbox/rc.xml --retry-connrefused

# Modify the xinitrc file to automatically log in the pi user
echo "- Creating xinitrc file"
Expand Down Expand Up @@ -2384,19 +2420,19 @@ fi
# Download some more splash screens
if [ ! -f "/boot/splash_updating-0.png" ]; then
echo "Downloading progress bar images"
wget https://www.candlesmarthome.com/tools/splash_updating-0.png -O /boot/splash_updating-0.png
wget https://www.candlesmarthome.com/tools/splash_updating-1.png -O /boot/splash_updating-1.png
wget https://www.candlesmarthome.com/tools/splash_updating-2.png -O /boot/splash_updating-2.png
wget https://www.candlesmarthome.com/tools/splash_updating-3.png -O /boot/splash_updating-3.png
wget https://www.candlesmarthome.com/tools/splash_updating-4.png -O /boot/splash_updating-4.png
wget https://www.candlesmarthome.com/tools/splash_updating-5.png -O /boot/splash_updating-5.png
wget https://www.candlesmarthome.com/tools/splash_updating180-0.png -O /boot/splash_updating180-0.png
wget https://www.candlesmarthome.com/tools/splash_updating180-1.png -O /boot/splash_updating180-1.png
wget https://www.candlesmarthome.com/tools/splash_updating180-2.png -O /boot/splash_updating180-2.png
wget https://www.candlesmarthome.com/tools/splash_updating180-3.png -O /boot/splash_updating180-3.png
wget https://www.candlesmarthome.com/tools/splash_updating180-4.png -O /boot/splash_updating180-4.png
wget https://www.candlesmarthome.com/tools/splash_updating180-5.png -O /boot/splash_updating180-5.png
wget https://www.candlesmarthome.com/tools/error.png -O /boot/error.png
wget https://www.candlesmarthome.com/tools/splash_updating-0.png -O /boot/splash_updating-0.png --retry-connrefused
wget https://www.candlesmarthome.com/tools/splash_updating-1.png -O /boot/splash_updating-1.png --retry-connrefused
wget https://www.candlesmarthome.com/tools/splash_updating-2.png -O /boot/splash_updating-2.png --retry-connrefused
wget https://www.candlesmarthome.com/tools/splash_updating-3.png -O /boot/splash_updating-3.png --retry-connrefused
wget https://www.candlesmarthome.com/tools/splash_updating-4.png -O /boot/splash_updating-4.png --retry-connrefused
wget https://www.candlesmarthome.com/tools/splash_updating-5.png -O /boot/splash_updating-5.png --retry-connrefused
wget https://www.candlesmarthome.com/tools/splash_updating180-0.png -O /boot/splash_updating180-0.png --retry-connrefused
wget https://www.candlesmarthome.com/tools/splash_updating180-1.png -O /boot/splash_updating180-1.png --retry-connrefused
wget https://www.candlesmarthome.com/tools/splash_updating180-2.png -O /boot/splash_updating180-2.png --retry-connrefused
wget https://www.candlesmarthome.com/tools/splash_updating180-3.png -O /boot/splash_updating180-3.png --retry-connrefused
wget https://www.candlesmarthome.com/tools/splash_updating180-4.png -O /boot/splash_updating180-4.png --retry-connrefused
wget https://www.candlesmarthome.com/tools/splash_updating180-5.png -O /boot/splash_updating180-5.png --retry-connrefused
wget https://www.candlesmarthome.com/tools/error.png -O /boot/error.png --retry-connrefused
fi


Expand Down Expand Up @@ -2732,7 +2768,7 @@ then
fi

elif [ ! -f /home/pi/webthings/gateway/.post_upgrade_complete ] \
|| [ ! -f /home/pi/node12 ] ; then
|| [ ! -e /home/pi/node12 ] ; then

echo
echo "ERROR, detected failure to (fully) install candle-controller"
Expand Down Expand Up @@ -2839,6 +2875,11 @@ fi



if [ -d /home/pi/webthings/gateway ] && [ -d /home/pi/webthings/gateway2 ]; then
rm -rf /home/pi/webthings/gateway2
fi


# cp /home/pi/.webthings/etc/webthings_settings_backup.js /home/pi/.webthings/etc/webthings_settings.js

if [ -f /boot/candle_first_run_complete.txt ] && [ ! -f /boot/candle_original_version.txt ]; then
Expand All @@ -2851,12 +2892,11 @@ if [ ! -f /home/pi/candle/creation_date.txt ]; then
fi

# remember when the update script was last run
echo "$(date +%s)" > /home/pi/candle/update_date.txt
#echo "$(date +%s)" > /home/pi/candle/update_date.txt

# Disable old bootup actions service
systemctl disable candle_bootup_actions.service


# delete bootup_actions, just in case this script is being run as a bootup_actions script.
if [ -f /boot/bootup_actions.sh ]; then
rm /boot/bootup_actions.sh
Expand Down

0 comments on commit 56993f4

Please sign in to comment.