Implement script to download and upload OpenWrt config files and more...

This commit is contained in:
Albrecht Lohofener
2024-02-19 23:55:54 +01:00
parent 764efb3177
commit 9f501cb120
13 changed files with 136 additions and 13 deletions
@@ -0,0 +1,8 @@
{
"name": "1 Backup OpenWrt config",
"description": "Backup OpenWrt config. WARNING: OpenWrt will be stopped during this operation.",
"script_path": "/run/backup_openwrt_config.sh",
"output_files": [
"/tmp/openwrt_config.tar.gz"
]
}
+3 -3
View File
@@ -1,6 +1,6 @@
{
"name": "Apply factory reset",
"description": "Hard factory reset of Openwrt",
"script_path": "/run/qemu_qmp.sh -f"
"name": "99 Factory reset",
"description": "Hard factory reset of Openwrt. WARNING: OpenWrt will be stopped during this operation.",
"script_path": "/run/factory_reset.sh"
}
+2 -2
View File
@@ -1,6 +1,6 @@
{
"name": "Reset OpenWRT",
"description": "Hard reset of Openwrt VM",
"name": "98 Reset OpenWrt",
"description": "Hard reset of OpenWrt VM",
"script_path": "/run/qemu_qmp.sh -r"
}
@@ -0,0 +1,15 @@
{
"name": "2 Restore OpenWrt config",
"description": "Restore OpenWrt config. WARNING: OpenWrt will be stopped during this operation.",
"script_path": "/run/restore_openwrt_config.sh",
"parameters": [
{
"name": "File upload",
"param": "--file_upload",
"type": "file_upload",
"description": "File upload testing",
"ui": {
"width_weight": 2
}
}]
}
+6
View File
@@ -0,0 +1,6 @@
{
"name": "4 Start OpenWrt",
"description": "Start OpenWrt VM",
"script_path": "supervisorctl start openwrt"
}
+6
View File
@@ -0,0 +1,6 @@
{
"name": "5 Stop OpenWrt",
"description": "Stop OpenWrt VM",
"script_path": "supervisorctl stop openwrt"
}
+27
View File
@@ -0,0 +1,27 @@
#!/usr/bin/env bash
set -Eeuo pipefail
trap - ERR
. /run/helpers.sh
CURRENT_VERSION_ROOTFS=`cat /storage/current_version`
# Stop openwrt
echo "****** Stop openwrt ******"
supervisorctl stop openwrt
# Get config
echo "****** Mount $CURRENT_VERSION_ROOTFS ******"
mount /storage/$CURRENT_VERSION_ROOTFS /mnt
echo "****** Create openwrt_config.tar.gz ******"
chroot /mnt /sbin/sysupgrade -k -b /tmp/openwrt_config.tar.gz
mv /mnt/tmp/openwrt_config.tar.gz /tmp/openwrt_config.tar.gz
echo "****** umount $CURRENT_VERSION_ROOTFS ******"
umount /mnt
# Start openwrt again
echo "****** Start openwrt again ******"
supervisorctl start openwrt
+23
View File
@@ -0,0 +1,23 @@
#!/usr/bin/env bash
set -Eeuo pipefail
trap - ERR
. /run/helpers.sh
CURRENT_VERSION_ROOTFS=`cat /storage/current_version`
# Stop openwrt
echo "****** Stop openwrt ******"
supervisorctl stop openwrt
# Do factory reset
echo "****** Do factory reset ******"
echo "Deleting all files in /storage ..."
ls /storage/
rm -f /storage/*
# Start openwrt again
echo "****** Start openwrt again ******"
supervisorctl start openwrt
+1 -1
View File
@@ -56,4 +56,4 @@ supervisorctl start nginx # Start webserver
# ******* OpenWrt handling *******
supervisorctl start openwrt # Start webserver
supervisorctl start openwrt # Start openwrt
+3 -5
View File
@@ -28,7 +28,7 @@ Help()
# Process the input options. Add options as needed. #
############################################################
# Get the options
while getopts ":hvrqf" option; do
while getopts ":hvrqs" option; do
case $option in
h) # display Help
Help
@@ -42,10 +42,8 @@ while getopts ":hvrqf" option; do
q) # Quit Qemu
echo -ne '{ "execute": "qmp_capabilities" } { "execute": "quit" }' | nc -w 1 -U /run/qmp-sock
exit;;
f) # Apply factory reset
rm /storage/current_version
rm /storage/rootfs-${OPENWRT_VERSION}.img
echo -ne '{ "execute": "qmp_capabilities" } { "execute": "quit" }' | nc -w 1 -U /run/qmp-sock
s) # Shutdown VM
echo -ne '{ "execute": "qmp_capabilities" } { "execute": "system_powerdown" }' | nc -w 1 -U /run/qmp-sock
exit;;
\?) # Invalid option
echo "Error: Invalid option"
+32
View File
@@ -0,0 +1,32 @@
#!/usr/bin/env bash
set -Eeuo pipefail
trap - ERR
. /run/helpers.sh
if [ ! "$1" = "--file_upload" ] ; then
echo "Error: expected argument --file_upload"
exit 1
fi
CURRENT_VERSION_ROOTFS=`cat /storage/current_version`
# Stop openwrt
echo "****** Stop openwrt ******"
supervisorctl stop openwrt
# Get config
echo "****** Mount $CURRENT_VERSION_ROOTFS ******"
mount /storage/$CURRENT_VERSION_ROOTFS /mnt
echo "****** Restore $2 ******"
cp $2 /mnt/tmp/openwrt_config.tar.gz
chroot /mnt /sbin/sysupgrade -r /tmp/openwrt_config.tar.gz
echo "****** umount $CURRENT_VERSION_ROOTFS ******"
umount /mnt
# Start openwrt again
echo "****** Start openwrt again ******"
supervisorctl start openwrt
+9 -2
View File
@@ -19,8 +19,15 @@ attach_eth_if () {
# * https://serverfault.com/questions/688483/assign-physical-interface-to-docker-exclusively
# * https://medium.com/lucjuggery/a-container-to-access-the-shell-of-the-host-2c7c227c64e9
# * https://developers.redhat.com/blog/2018/10/22/introduction-to-linux-interfaces-for-virtual-networking#
info "Attaching physical Ethernet interface $HOST_IF into container with the name $CONTAINER_IF ..."
# Check if interface exists
if ! nsenter --target 1 --uts --net --ipc --mount ip link show "$HOST_IF" &> /dev/null; then
info "Host Ethernet interface $HOST_IF does not exists. It can be a wrong interface name or the Ethernet interface is already assigend to this container."
return
fi
PID_CONTAINTER=$(nsenter --target 1 --uts --net --ipc --mount docker inspect -f '{{.State.Pid}}' $(cat /etc/hostname))
nsenter --target 1 --uts --net --ipc --mount mkdir -p /var/run/netns
nsenter --target 1 --uts --net --ipc --mount ln -s /proc/$PID_CONTAINTER/ns/net /var/run/netns/$PID_CONTAINTER
@@ -114,6 +121,6 @@ qemu-system-aarch64 -M virt \
$WAN_ARGS \
$USB_ARGS \
-qmp unix:/run/qmp-sock,server=on,wait=off
# -device virtio-net,netdev=qlan1 -netdev user,id=qlan1,net=192.168.1.0/24,hostfwd=tcp::8000-192.168.1.1:80 \
# -blockdev driver=raw,node-name=hd0,cache.direct=on,file.driver=file,file.filename=/var/vm/openwrt-armsr-armv8-generic-ext4-combined.img \
+1
View File
@@ -41,3 +41,4 @@ stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
stderr_logfile=/dev/stderr
stderr_logfile_maxbytes=0
stopasgroup=true