Skip to content

Commit

Permalink
Port OS upgrade stuff to master-v3.x
Browse files Browse the repository at this point in the history
  • Loading branch information
dkulp committed Feb 20, 2020
1 parent 165ff9d commit 9cb482e
Show file tree
Hide file tree
Showing 4 changed files with 126 additions and 1 deletion.
38 changes: 38 additions & 0 deletions SD/upgradeOS-part1.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/bin/bash

mount $1 /mnt


ORIGTYPE=$(</etc/fpp/platform)
NEWTYPE=$(</mnt/etc/fpp/platform)

if [ $ORIGTYPE != $NEWTYPE ]; then
echo "Image of '${NEWTYPE}' does no match '${ORIGTYPE}'"
umount /mnt
exit 1;
fi

mount -o bind / /mnt/mnt
mount -o bind /boot /mnt/mnt/boot
mount -t tmpfs tmpfs /mnt/tmp
mount -o bind /dev /mnt/dev

chroot /mnt /mnt/opt/fpp/SD/upgradeOS-part2.sh

echo "Done copy"
sync
umount /mnt/dev
umount /mnt/tmp
umount /mnt/mnt/boot
umount /mnt/mnt

sync

echo "</pre>"
echo "<b>Rebooting.... please wait for FPP to reboot.</b><br>"
echo "<a href='index.php'>Go to FPP Main Status Page</a><br>"
echo "<a href='about.php'>Go back to FPP About page</a><br>"
echo "</body>"
echo "</html>"

reboot -f -f
42 changes: 42 additions & 0 deletions SD/upgradeOS-part2.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/bin/bash

. /opt/fpp/scripts/common
. /opt/fpp/scripts/functions

cd /

if [ "${FPPPLATFORM}" = "Raspberry Pi" ]
then
BOOTSIZE=$(sfdisk -q -l -o size /dev/mmcblk0 2>/dev/null | grep M)
BOOTSIZE=${BOOTSIZE::-1}
if [ `echo "$BOOTSIZE < 120"|bc` -eq 1 ]; then
# 2.x image, boot partition is tiny and cannot fit everything needed for Pi4 so we need to exclude some more things
rsync -aAxv boot /mnt --delete-before --exclude=boot/kernel8.img --exclude=boot/kernel7l.img --exclude=boot/.Spotlight*
else
rsync -aAxv boot /mnt --delete-before
fi
else
rsync -aAxv boot /mnt --delete-during
fi

if [ "${FPPPLATFORM}" = "BeagleBone Black" ]; then
# need to install the bootloader that goes with this version of the os
cd /opt/backup/uboot
dd if=MLO of=/dev/mmcblk1 seek=1 bs=128k
dd if=u-boot.img of=/dev/mmcblk1 seek=1 bs=384k
dd if=MLO of=/dev/mmcblk0 seek=1 bs=128k
dd if=u-boot.img of=/dev/mmcblk0 seek=1 bs=384k
cd /
fi

# temporarily copy the ssh keys
mkdir tmp/ssh
cp -a mnt/etc/ssh/*key* tmp/ssh

#copy everything other than fstab
rsync -aAxv bin etc lib opt root sbin usr var /mnt --delete-during --exclude=etc/fstab

#restore the ssh keys
cp -a tmp/ssh/* mnt/etc/ssh

exit
17 changes: 16 additions & 1 deletion www/about.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,12 @@ function ToggleAutoUpdate() {
SetAutoUpdate(1);
}
}

function UpgradeOS() {
var os = $('#OSSelect').val();
if (confirm('Upgrade the OS using ' + os + '?\nThis can take a long time.')) {
location.href="upgradeOS.php?os=" + os;
}
}
</script>
<title><? echo $pageTitle; ?></title>
<style>
Expand Down Expand Up @@ -226,6 +231,16 @@ function ToggleAutoUpdate() {
checked
<? } ?>
> <input type='button' value='Manual Update' onClick='location.href="manualUpdate.php";' class='buttons' id='ManualUpdate'></td></tr>
<?
$osUpdateFiles = getFileList($uploadDirectory, "fppos");
if (count($osUpdateFiles) > 0) {
echo "<tr><td>Upgrade OS:</td><td><select class='OSSelect' id='OSSelect'>\n";
foreach ($osUpdateFiles as $key => $value) {
echo "<option value='" . $value . "'>" . $value . "</option>\n";
}
echo "</select>&nbsp;<input type='button' value='Upgrade OS' onClick='UpgradeOS();' class='buttons' id='OSUpgrade'></td></tr>";
}
?>
<tr><td>&nbsp;</td><td>&nbsp;</td></tr>
<tr><td><b>System Utilization</b></td><td>&nbsp;</td></tr>
<tr><td>CPU Usage:</td><td><? printf( "%.2f", get_server_cpu_usage()); ?>%</td></tr>
Expand Down
30 changes: 30 additions & 0 deletions www/upgradeOS.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<!DOCTYPE html>
<html>
<?php

$skipJSsettings = 1;
require_once("common.php");

DisableOutputBuffering();

?>

<head>
<title>
FPP OS Uprade
</title>
</head>
<body>
<h2>FPP OS Upgrade</h2>
<pre>
==========================================================================
<?
system($SUDO . " $fppDir/SD/upgradeOS-part1.sh /home/fpp/media/upload/" . $_GET['os']);
?>
==========================================================================
</pre>
<b>Rebooting.... please wait for FPP to reboot.</b>
<a href='index.php'>Go to FPP Main Status Page</a><br>
<a href='about.php'>Go back to FPP About page</a><br>
</body>
</html>

0 comments on commit 9cb482e

Please sign in to comment.