Skip to content

Commit 56993f4

Browse files
Update create_latest_candle.sh
1 parent 96eb532 commit 56993f4

File tree

1 file changed

+118
-78
lines changed

1 file changed

+118
-78
lines changed

create_latest_candle.sh

Lines changed: 118 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,15 @@ set +e # continue on errors
99

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

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

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

1818
# Other parts of the script that can be skipped:
1919
# export SKIP_PARTITIONS=yes
20+
# export TINY_PARTITIONS=yes
2021
# export SKIP_APT_INSTALL=yes
2122
# export SKIP_APT_UPGRADE=yes
2223
# export SKIP_PYTHON=yes
@@ -27,6 +28,7 @@ set +e # continue on errors
2728
# export SKIP_REBOOT=yes
2829

2930
#SKIP_PARTITIONS=yes
31+
#TINY_PARTITIONS=yes # used to create smaller partition images, which are used in the new system update process
3032
#SKIP_APT_INSTALL=yes
3133
#SKIP_APT_UPGRADE=yes
3234
#SKIP_PYTHON=yes
@@ -272,14 +274,24 @@ then
272274
echo "Candle: creating partitions" >> /dev/kmsg
273275
echo "Candle: creating partitions" >> /boot/candle_log.txt
274276
echo
275-
276-
printf "resizepart 2 7000\nmkpart\np\next4\n7001MB\n7500MB\nmkpart\np\next4\n7502MB\n14000MB\nquit" | parted
277-
resize2fs /dev/mmcblk0p2
277+
if [[ -z "${TINY_PARTITIONS}" ]]; then
278+
printf "resizepart 2 7000MB\nmkpart\np\next4\n7001MB\n7500MB\nmkpart\np\next4\n7502MB\n14000MB\nquit" | parted
279+
resize2fs /dev/mmcblk0p2
280+
281+
else
282+
printf "resizepart 2 5000MB\nmkpart\np\next4\n5001MB\n7500MB\nmkpart\np\next4\n7502MB\n9500MB\nquit" | parted
283+
resize2fs /dev/mmcblk0p2
284+
fi
285+
278286
printf "y" | mkfs.ext4 /dev/mmcblk0p3
279287
printf "y" | mkfs.ext4 /dev/mmcblk0p4
280288
mkdir -p /home/pi/.webthings
281289
chown pi:pi /home/pi/.webthings
282290
touch /boot/candle_has_4th_partition.txt
291+
292+
e2label /dev/mmcblk0p2 system
293+
e2label /dev/mmcblk0p3 recovery
294+
e2label /dev/mmcblk0p4 user
283295
else
284296
echo
285297
echo "Partition 2 was missing. Inside chroot?"
@@ -342,47 +354,14 @@ fi
342354
sleep 3
343355
cd /home/pi
344356

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

348-
cd /home/pi/.webthings
349-
350-
if [ -f recovery.fs ]; then
351-
echo "Warning, recovery.fs already existed. Removing it first."
352-
rm recovery.fs
353-
fi
354-
355-
echo "Downloading the recovery partition"
356-
echo "Downloading the recovery partition" >> /dev/kmsg
357-
echo "Downloading the recovery partition" >> /boot/candle_log.txt
358-
359-
wget -c https://www.candlesmarthome.com/img/recovery/recovery.fs.tar.gz -O recovery.fs.tar.gz
360-
361-
echo "untarring the recovery partition"
362-
tar xf recovery.fs.tar.gz
363-
364-
if [ -f recovery.fs ]; then # -n is for "non-zero string"
365-
#echo "Mounting the recovery partition"
366-
#losetup --partscan /dev/loop0 recovery.img
367-
368-
echo "Copying recovery partition data"
369-
echo "Copying recovery partition data" >> /dev/kmsg
370-
echo "Copying recovery partition data" >> /boot/candle_log.txt
371-
dd if=recovery.fs of=/dev/mmcblk0p3 bs=1M
372-
373-
#if [ -n "$(lsblk | grep loop0p2)" ] && [ -n "$(lsblk | grep mmcblk0p3)" ]; then
374-
#fi
375-
else
376-
echo "ERROR, failed to download or extract the recovery disk image"
377-
echo "ERROR, failed to download or extract the recovery disk image" >> /dev/kmsg
378-
echo "ERROR, failed to download or extract the recovery disk image" >> /boot/candle_log.txt
379-
fi
380-
381-
recovery.fs.tar.gz
382-
rm recovery.fs
358+
# Save the bits of the initial kernel the boot partition to a file
359+
if [ "$BIT_TYPE" == 64 ]; then
360+
echo "creating /boot/candle_64bits.txt"
361+
echo "creating /boot/candle_64bits.txt" >> /dev/kmsg
362+
touch /boot/candle_64bits.txt
383363
fi
384364

385-
cd /home/pi
386365

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

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

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

@@ -845,14 +824,14 @@ fi
845824

846825
# Download splash images
847826
if [ -f /boot/cmdline.txt ]; then
848-
wget https://www.candlesmarthome.com/tools/error.png -O /boot/error.png
827+
wget https://www.candlesmarthome.com/tools/error.png -O /boot/error.png --retry-connrefused
849828
echo
850829
echo "Candle: downloading splash images and videos" >> /dev/kmsg
851830
echo "Candle: downloading splash images and videos" >> /boot/candle_log.txt
852831
echo
853832

854-
wget https://www.candlesmarthome.com/tools/splash_updating.png -O /boot/splash_updating.png
855-
wget https://www.candlesmarthome.com/tools/splash_updating180.png -O /boot/splash_updating180.png
833+
wget https://www.candlesmarthome.com/tools/splash_updating.png -O /boot/splash_updating.png --retry-connrefused
834+
wget https://www.candlesmarthome.com/tools/splash_updating180.png -O /boot/splash_updating180.png --retry-connrefused
856835

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

885864
# Download the rest of the images
886-
wget https://www.candlesmarthome.com/tools/splash.png -O /boot/splash.png
887-
wget https://www.candlesmarthome.com/tools/splash180.png -O /boot/splash180.png
888-
wget https://www.candlesmarthome.com/tools/splashalt.png -O /boot/splashalt.png
889-
wget https://www.candlesmarthome.com/tools/splash180alt.png -O /boot/splash180alt.png
890-
wget https://www.candlesmarthome.com/tools/splash.mp4 -O /boot/splash.mp4
891-
wget https://www.candlesmarthome.com/tools/splash180.mp4 -O /boot/splash180.mp4
865+
wget https://www.candlesmarthome.com/tools/splash.png -O /boot/splash.png --retry-connrefused
866+
wget https://www.candlesmarthome.com/tools/splash180.png -O /boot/splash180.png --retry-connrefused
867+
wget https://www.candlesmarthome.com/tools/splashalt.png -O /boot/splashalt.png --retry-connrefused
868+
wget https://www.candlesmarthome.com/tools/splash180alt.png -O /boot/splash180alt.png --retry-connrefused
869+
wget https://www.candlesmarthome.com/tools/splash.mp4 -O /boot/splash.mp4 --retry-connrefused
870+
wget https://www.candlesmarthome.com/tools/splash180.mp4 -O /boot/splash180.mp4 --retry-connrefused
871+
wget https://www.candlesmarthome.com/tools/splash_preparing.png -O /boot/splash_preparing.png --retry-connrefused
872+
wget https://www.candlesmarthome.com/tools/splash_preparing180.png -O /boot/splash_preparing180.png --retry-connrefused
873+
892874
fi
893875

894876

@@ -940,7 +922,7 @@ else
940922
| cut -d : -f 2,3 \
941923
| tr -d \" \
942924
| sed 's/,*$//' \
943-
| wget -qi - -O configuration-files.tar
925+
| wget -qi - -O configuration-files.tar --retry-connrefused
944926

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

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

10241006
tar -xf install-scripts.tar
10251007
rm install-scripts.tar
@@ -1045,8 +1027,8 @@ then
10451027
echo "Candle: Starting download of stable controller tar"
10461028
echo "Candle: Starting download of stable controller tar. Takes a while." >> /dev/kmsg
10471029
echo "Candle: Starting download of stable controller tar" >> /boot/candle_log.txt
1048-
wget -nv https://www.candlesmarthome.com/img/controller/latest_stable_controller.tar -O /home/pi/latest_stable_controller.tar
1049-
wget -nv https://www.candlesmarthome.com/img/controller/latest_stable_controller.tar.txt -O /home/pi/latest_stable_controller.tar.txt
1030+
wget -nv https://www.candlesmarthome.com/img/controller/latest_stable_controller.tar -O /home/pi/latest_stable_controller.tar --retry-connrefused
1031+
wget -nv https://www.candlesmarthome.com/img/controller/latest_stable_controller.tar.txt -O /home/pi/latest_stable_controller.tar.txt --retry-connrefused
10501032

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

@@ -1836,10 +1818,61 @@ rm -rf bluez-alsa
18361818

18371819

18381820

1821+
echo ""
1822+
echo "INSTALLING RECOVERY PARTITION"
1823+
echo ""
18391824

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

1828+
cd /home/pi/.webthings
1829+
1830+
if [ -f recovery.fs ]; then
1831+
echo "Warning, recovery.fs already existed. Removing it first."
1832+
rm recovery.fs
1833+
fi
1834+
1835+
echo "Downloading the recovery partition"
1836+
echo "Downloading the recovery partition" >> /dev/kmsg
1837+
echo "Downloading the recovery partition" >> /boot/candle_log.txt
1838+
1839+
wget https://www.candlesmarthome.com/img/recovery/recovery.fs.tar.gz -O recovery.fs.tar.gz --retry-connrefused
1840+
1841+
if [ -f recovery.fs.tar.gz ]; then
1842+
echo "untarring the recovery partition"
1843+
tar xf recovery.fs.tar.gz
1844+
1845+
if [ -f recovery.fs ]; then # -n is for "non-zero string"
1846+
#echo "Mounting the recovery partition"
1847+
#losetup --partscan /dev/loop0 recovery.img
1848+
1849+
echo "Copying recovery partition data"
1850+
echo "Copying recovery partition data" >> /dev/kmsg
1851+
echo "Copying recovery partition data" >> /boot/candle_log.txt
1852+
dd if=recovery.fs of=/dev/mmcblk0p3 bs=1M
18411853

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

1862+
rm recovery.fs.tar.gz
1863+
rm recovery.fs
1864+
else
1865+
echo "ERROR, recovery partition file not downloaded"
1866+
1867+
# Show error image
1868+
if [ -e "/bin/ply-image" ] && [ -e /dev/fb0 ] && [ -f /boot/error.png ]; then
1869+
/bin/ply-image /boot/error.png
1870+
#sleep 7200
1871+
fi
1872+
1873+
exit 1
1874+
fi
1875+
fi
18431876

18441877

18451878

@@ -1851,6 +1884,8 @@ echo
18511884
echo "INSTALLING OTHER FILES AND SERVICES"
18521885
echo
18531886

1887+
systemctl stop triggerhappy.socket
1888+
systemctl stop triggerhappy.service
18541889

18551890
# switch back to root of home folder
18561891
cd /home/pi
@@ -1908,9 +1943,9 @@ if [ ! -d /home/pi/.webthings/tmp ]; then
19081943
fi
19091944
chmod 1777 /home/pi/.webthings/tmp
19101945
find /home/pi/.webthings/tmp \
1911-
-mindepth 1 \
1912-
-name '.*-unix' -exec chmod 1777 {} + -prune -o \
1913-
-exec chmod go-rwx {} +
1946+
-mindepth 1 \
1947+
-name '.*-unix' -exec chmod 1777 {} + -prune -o \
1948+
-exec chmod go-rwx {} +
19141949

19151950

19161951
# Prepare a location for Matter settings
@@ -2022,6 +2057,7 @@ fi
20222057
# CHMOD THE NEW FILES
20232058
chmod +x /home/pi/candle/early.sh
20242059
chmod +x /etc/rc.local
2060+
chmod +x /home/pi/candle/reboot_to_recovery.sh
20252061
chmod +x /etc/xdg/openbox/autostart
20262062
chmod +x /home/pi/candle/late.sh
20272063
chmod +x /home/pi/candle/every_minute.sh
@@ -2301,7 +2337,7 @@ fi
23012337

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

23062342
# Modify the xinitrc file to automatically log in the pi user
23072343
echo "- Creating xinitrc file"
@@ -2384,19 +2420,19 @@ fi
23842420
# Download some more splash screens
23852421
if [ ! -f "/boot/splash_updating-0.png" ]; then
23862422
echo "Downloading progress bar images"
2387-
wget https://www.candlesmarthome.com/tools/splash_updating-0.png -O /boot/splash_updating-0.png
2388-
wget https://www.candlesmarthome.com/tools/splash_updating-1.png -O /boot/splash_updating-1.png
2389-
wget https://www.candlesmarthome.com/tools/splash_updating-2.png -O /boot/splash_updating-2.png
2390-
wget https://www.candlesmarthome.com/tools/splash_updating-3.png -O /boot/splash_updating-3.png
2391-
wget https://www.candlesmarthome.com/tools/splash_updating-4.png -O /boot/splash_updating-4.png
2392-
wget https://www.candlesmarthome.com/tools/splash_updating-5.png -O /boot/splash_updating-5.png
2393-
wget https://www.candlesmarthome.com/tools/splash_updating180-0.png -O /boot/splash_updating180-0.png
2394-
wget https://www.candlesmarthome.com/tools/splash_updating180-1.png -O /boot/splash_updating180-1.png
2395-
wget https://www.candlesmarthome.com/tools/splash_updating180-2.png -O /boot/splash_updating180-2.png
2396-
wget https://www.candlesmarthome.com/tools/splash_updating180-3.png -O /boot/splash_updating180-3.png
2397-
wget https://www.candlesmarthome.com/tools/splash_updating180-4.png -O /boot/splash_updating180-4.png
2398-
wget https://www.candlesmarthome.com/tools/splash_updating180-5.png -O /boot/splash_updating180-5.png
2399-
wget https://www.candlesmarthome.com/tools/error.png -O /boot/error.png
2423+
wget https://www.candlesmarthome.com/tools/splash_updating-0.png -O /boot/splash_updating-0.png --retry-connrefused
2424+
wget https://www.candlesmarthome.com/tools/splash_updating-1.png -O /boot/splash_updating-1.png --retry-connrefused
2425+
wget https://www.candlesmarthome.com/tools/splash_updating-2.png -O /boot/splash_updating-2.png --retry-connrefused
2426+
wget https://www.candlesmarthome.com/tools/splash_updating-3.png -O /boot/splash_updating-3.png --retry-connrefused
2427+
wget https://www.candlesmarthome.com/tools/splash_updating-4.png -O /boot/splash_updating-4.png --retry-connrefused
2428+
wget https://www.candlesmarthome.com/tools/splash_updating-5.png -O /boot/splash_updating-5.png --retry-connrefused
2429+
wget https://www.candlesmarthome.com/tools/splash_updating180-0.png -O /boot/splash_updating180-0.png --retry-connrefused
2430+
wget https://www.candlesmarthome.com/tools/splash_updating180-1.png -O /boot/splash_updating180-1.png --retry-connrefused
2431+
wget https://www.candlesmarthome.com/tools/splash_updating180-2.png -O /boot/splash_updating180-2.png --retry-connrefused
2432+
wget https://www.candlesmarthome.com/tools/splash_updating180-3.png -O /boot/splash_updating180-3.png --retry-connrefused
2433+
wget https://www.candlesmarthome.com/tools/splash_updating180-4.png -O /boot/splash_updating180-4.png --retry-connrefused
2434+
wget https://www.candlesmarthome.com/tools/splash_updating180-5.png -O /boot/splash_updating180-5.png --retry-connrefused
2435+
wget https://www.candlesmarthome.com/tools/error.png -O /boot/error.png --retry-connrefused
24002436
fi
24012437

24022438

@@ -2732,7 +2768,7 @@ then
27322768
fi
27332769

27342770
elif [ ! -f /home/pi/webthings/gateway/.post_upgrade_complete ] \
2735-
|| [ ! -f /home/pi/node12 ] ; then
2771+
|| [ ! -e /home/pi/node12 ] ; then
27362772

27372773
echo
27382774
echo "ERROR, detected failure to (fully) install candle-controller"
@@ -2839,6 +2875,11 @@ fi
28392875

28402876

28412877

2878+
if [ -d /home/pi/webthings/gateway ] && [ -d /home/pi/webthings/gateway2 ]; then
2879+
rm -rf /home/pi/webthings/gateway2
2880+
fi
2881+
2882+
28422883
# cp /home/pi/.webthings/etc/webthings_settings_backup.js /home/pi/.webthings/etc/webthings_settings.js
28432884

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

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

28562897
# Disable old bootup actions service
28572898
systemctl disable candle_bootup_actions.service
28582899

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

0 commit comments

Comments
 (0)