mirror of
https://github.com/AlbrechtL/openwrt-docker.git
synced 2026-10-18 16:01:38 +00:00
Add inital settings migration
This commit is contained in:
@@ -0,0 +1,10 @@
|
||||
|
||||
echo "Backup configuration"
|
||||
mkdir -p /root/backup
|
||||
sysupgrade -k -b /root/backup/config.tar.gz
|
||||
sync
|
||||
|
||||
echo "Shutdown system"
|
||||
halt
|
||||
|
||||
exit 0
|
||||
@@ -0,0 +1,9 @@
|
||||
|
||||
echo "Restore configuration"
|
||||
sysupgrade -r /root/backup/config.tar.gz
|
||||
sync
|
||||
|
||||
echo "Shutdown system"
|
||||
halt
|
||||
|
||||
exit 0
|
||||
+87
-4
@@ -51,7 +51,7 @@ FILE=/storage/rootfs-${OPENWRT_VERSION}.img
|
||||
if [ -f "$FILE" ]; then
|
||||
info "$FILE exists. Nothing to do."
|
||||
else
|
||||
info "$FILE does not exist. Copying image to storage ..."
|
||||
info "$FILE does not exist. Copying rootfs-${OPENWRT_VERSION}.img to storage ..."
|
||||
cp /var/vm/rootfs-${OPENWRT_VERSION}.img.gz /storage/rootfs-${OPENWRT_VERSION}.img.gz
|
||||
gzip -d /storage/rootfs-${OPENWRT_VERSION}.img.gz
|
||||
|
||||
@@ -61,9 +61,16 @@ else
|
||||
chmod +x /var/vm/openwrt_additional/bin/*
|
||||
cp /var/vm/openwrt_additional/bin/* /mnt/usr/bin/
|
||||
umount /mnt
|
||||
|
||||
if [ -f "/storage/current_version" ]; then
|
||||
mv /storage/current_version /storage/old_version
|
||||
fi
|
||||
|
||||
touch /storage/current_version
|
||||
echo "rootfs-${OPENWRT_VERSION}.img" > /storage/current_version
|
||||
fi
|
||||
|
||||
|
||||
# Enable VNC
|
||||
info "Activating web VNC ..."
|
||||
[ ! -f "$INFO" ] && error "File $INFO not found?!"
|
||||
rm -f "$INFO"
|
||||
@@ -71,6 +78,7 @@ rm -f "$INFO"
|
||||
rm -f "$PAGE"
|
||||
|
||||
|
||||
# Check KVM
|
||||
info "Checking for KVM ..."
|
||||
KVM_ERR=""
|
||||
CPU_ARGS="-cpu cortex-a53"
|
||||
@@ -119,9 +127,84 @@ else
|
||||
USB_ARGS="-device usb-host,vendorid=0x$USB_VID_1,productid=0x$USB_PID_1"
|
||||
fi
|
||||
|
||||
info "Booting image using $VERS..."
|
||||
# Migrate settings from old OpenWrt version to new one
|
||||
if [ -f /storage/old_version ]; then
|
||||
OLD_VERSION_ROOTFS=`cat /storage/old_version`
|
||||
|
||||
info "Migrate settings from $OLD_VERSION_ROOTFS to rootfs-${OPENWRT_VERSION}.img. This can take some time because we need to boot openwrt multiple times."
|
||||
|
||||
mount /storage/$OLD_VERSION_ROOTFS /mnt
|
||||
mv /mnt/etc/rc.local /mnt/etc/rc.local.disabled
|
||||
cp /var/vm/openwrt_additional/do_backup_rc.local /mnt/etc/rc.local
|
||||
chmod +x /mnt/etc/rc.local
|
||||
umount /mnt
|
||||
|
||||
qemu-system-aarch64 -M virt \
|
||||
-m 128 \
|
||||
-nodefaults \
|
||||
$CPU_ARGS -smp $CPU_COUNT \
|
||||
-bios /usr/share/qemu/edk2-aarch64-code.fd \
|
||||
-display vnc=:0,websocket=5700 \
|
||||
-vga none -device ramfb \
|
||||
-kernel /var/vm/kernel.bin -append "root=fe00 console=tty0" \
|
||||
-blockdev driver=raw,node-name=hd0,cache.direct=on,file.driver=file,file.filename=/storage/${OLD_VERSION_ROOTFS} \
|
||||
-device virtio-blk-pci,drive=hd0 \
|
||||
-device qemu-xhci -device usb-kbd
|
||||
|
||||
# Get config backup from old rootfs
|
||||
mount /storage/$OLD_VERSION_ROOTFS /mnt
|
||||
rm /mnt/etc/rc.local
|
||||
mv /mnt/etc/rc.local.disabled /mnt/etc/rc.local
|
||||
|
||||
if [ -f /mnt/root/backup/config.tar.gz ]; then
|
||||
cp /mnt/root/backup/config.tar.gz /storage/config-`basename $OLD_VERSION_ROOTFS .img`.tar.gz
|
||||
else
|
||||
error "No config.tar.gz in $OLD_VERSION_ROOTFS found"
|
||||
fi
|
||||
umount /mnt
|
||||
|
||||
# Put config backup to new rootfs
|
||||
mount $FILE /mnt
|
||||
mkdir -p /mnt/root/backup
|
||||
cp /storage/config-`basename $OLD_VERSION_ROOTFS .img`.tar.gz /mnt/root/backup/config.tar.gz
|
||||
|
||||
mv /mnt/etc/rc.local /mnt/etc/rc.local.disabled
|
||||
cp /var/vm/openwrt_additional/restore_backup_rc.local /mnt/etc/rc.local
|
||||
chmod +x /mnt/etc/rc.local
|
||||
umount /mnt
|
||||
|
||||
qemu-system-aarch64 -M virt \
|
||||
-m 128 \
|
||||
-nodefaults \
|
||||
$CPU_ARGS -smp $CPU_COUNT \
|
||||
-bios /usr/share/qemu/edk2-aarch64-code.fd \
|
||||
-display vnc=:0,websocket=5700 \
|
||||
-vga none -device ramfb \
|
||||
-kernel /var/vm/kernel.bin -append "root=fe00 console=tty0" \
|
||||
-blockdev driver=raw,node-name=hd0,cache.direct=on,file.driver=file,file.filename=${FILE} \
|
||||
-device virtio-blk-pci,drive=hd0 \
|
||||
-device qemu-xhci -device usb-kbd
|
||||
|
||||
mount $FILE /mnt
|
||||
rm /mnt/etc/rc.local
|
||||
mv /mnt/etc/rc.local.disabled /mnt/etc/rc.local
|
||||
mv /mnt/root/backup/config.tar.gz /mnt/root/backup/config-`basename $OLD_VERSION_ROOTFS .img`.tar.gz
|
||||
umount /mnt
|
||||
|
||||
# Finally remove old rootfs and old files
|
||||
rm /storage/$OLD_VERSION_ROOTFS
|
||||
rm /storage/old_version
|
||||
rm /storage/config-`basename $OLD_VERSION_ROOTFS .img`.tar.gz
|
||||
fi
|
||||
|
||||
|
||||
|
||||
# See qemu command if debug is enabled
|
||||
[[ "$DEBUG" == [Yy1]* ]] && set -x
|
||||
|
||||
#************************ FINAL BOOTING ************************
|
||||
|
||||
info "Booting image using $VERS..."
|
||||
exec qemu-system-aarch64 -M virt \
|
||||
-m 128 \
|
||||
-nodefaults \
|
||||
@@ -130,7 +213,7 @@ exec qemu-system-aarch64 -M virt \
|
||||
-display vnc=:0,websocket=5700 \
|
||||
-vga none -device ramfb \
|
||||
-kernel /var/vm/kernel.bin -append "root=fe00 console=tty0" \
|
||||
-blockdev driver=raw,node-name=hd0,cache.direct=on,file.driver=file,file.filename=/storage/rootfs-${OPENWRT_VERSION}.img \
|
||||
-blockdev driver=raw,node-name=hd0,cache.direct=on,file.driver=file,file.filename=${FILE} \
|
||||
-device virtio-blk-pci,drive=hd0 \
|
||||
-device qemu-xhci -device usb-kbd \
|
||||
$LAN_ARGS \
|
||||
|
||||
Reference in New Issue
Block a user