mirror of
https://github.com/AlbrechtL/openwrt-docker.git
synced 2026-10-30 00:10:26 +00:00
spit run_openwrt.sh in multiple shell scripts.
This commit is contained in:
+1
-1
@@ -14,7 +14,7 @@ services:
|
||||
# If WAN interface is not specified the Docker network
|
||||
# In this case a port forwarding from port OpenWrt 80 to port 8000 is available
|
||||
#WAN_IF: "enx00e04c0407a6"
|
||||
#LAN_IF: "enx00e04d68033f"
|
||||
LAN_IF: "enx00e04d68033f"
|
||||
|
||||
# USB passthrough
|
||||
# Format <vendorID>:<productID> like 'lsusb' is given
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
#!/usr/bin/env bash
|
||||
set -Eeuo pipefail
|
||||
|
||||
info () { printf "%b%s%b" "\E[1;34m❯ \E[1;36m" "$1" "\E[0m\n"; }
|
||||
error () { printf "%b%s%b" "\E[1;31m❯ " "ERROR: $1" "\E[0m\n" >&2; }
|
||||
warn () { printf "%b%s%b" "\E[1;31m❯ " "Warning: $1" "\E[0m\n" >&2; }
|
||||
|
||||
trap 'error "Status $? while: $BASH_COMMAND (line $LINENO/$BASH_LINENO)"' ERR
|
||||
|
||||
# Docker environment variables
|
||||
: "${CPU_COUNT:=""}" # Physical LAN interface name
|
||||
: "${WAN_IF:=""}" # Physical WAN interface name
|
||||
: "${LAN_IF:=""}" # Physical LAN interface name
|
||||
: "${USB_VID_1:=""}" # USB vendor ID
|
||||
: "${USB_PID_1:=""}" # USB product ID
|
||||
: "${IS_U_OS_APP:=""}" # By default this container is not a u-OS app
|
||||
: "${DEBUG:="N"}" # Disable debugging
|
||||
+16
-36
@@ -1,42 +1,18 @@
|
||||
#!/usr/bin/env bash
|
||||
set -Eeuo pipefail
|
||||
|
||||
info () { printf "%b%s%b" "\E[1;34m❯ \E[1;36m" "$1" "\E[0m\n"; }
|
||||
error () { printf "%b%s%b" "\E[1;31m❯ " "ERROR: $1" "\E[0m\n" >&2; }
|
||||
warn () { printf "%b%s%b" "\E[1;31m❯ " "Warning: $1" "\E[0m\n" >&2; }
|
||||
. /run/helpers.sh
|
||||
|
||||
trap 'error "Status $? while: $BASH_COMMAND (line $LINENO/$BASH_LINENO)"' ERR
|
||||
|
||||
[ ! -f "/run/entry.sh" ] && error "Script must run inside Docker container!" && exit 11
|
||||
[ ! -f "/run/init_container.sh" ] && error "Script must run inside Docker container!" && exit 11
|
||||
[ "$(id -u)" -ne "0" ] && error "Script must be executed with root privileges." && exit 12
|
||||
|
||||
APP="OpenWrt"
|
||||
SUPPORT="https://github.com/AlbrechtL/openwrt-docker-arm64-build"
|
||||
|
||||
echo "❯ Starting $APP for Docker v$(</run/version)..."
|
||||
echo "❯ For support visit $SUPPORT"
|
||||
echo
|
||||
|
||||
# Docker environment variables
|
||||
|
||||
: "${CPU_COUNT:=""}" # Physical LAN interface name
|
||||
: "${WAN_IF:=""}" # Physical WAN interface name
|
||||
: "${LAN_IF:=""}" # Physical LAN interface name
|
||||
: "${USB_VID_1:=""}" # USB vendor ID
|
||||
: "${USB_PID_1:=""}" # USB product ID
|
||||
: "${IS_U_OS_APP:=""}" # By default this container is not a u-OS app
|
||||
: "${DEBUG:="N"}" # Disable debugging
|
||||
|
||||
# Helper variables
|
||||
|
||||
STORAGE="/storage"
|
||||
INFO="/run/shm/msg.html"
|
||||
PAGE="/run/shm/index.html"
|
||||
TEMPLATE="/var/www/index.html"
|
||||
FOOTER1="$APP for Docker v$(</run/version)"
|
||||
FOOTER2="<a href='$SUPPORT'>$SUPPORT</a>"
|
||||
|
||||
KERNEL=$(uname -r | cut -b 1)
|
||||
MINOR=$(uname -r | cut -d '.' -f2)
|
||||
ARCH=$(uname -m)
|
||||
VERS=$(qemu-system-aarch64 --version | head -n 1 | cut -d '(' -f 1)
|
||||
|
||||
# Check system
|
||||
if [ ! -d "/dev/shm" ]; then
|
||||
@@ -46,6 +22,7 @@ else
|
||||
fi
|
||||
|
||||
# Check folder
|
||||
STORAGE="/storage"
|
||||
if [ ! -d "$STORAGE" ]; then
|
||||
error "Storage folder ($STORAGE) not found!" && exit 13
|
||||
fi
|
||||
@@ -59,11 +36,8 @@ else
|
||||
cp -f /var/www/nginx.conf.u-os-app /etc/nginx/http.d/web.conf
|
||||
fi
|
||||
|
||||
# Start webserver
|
||||
cp -r /var/www/* /run/shm
|
||||
supervisorctl start nginx
|
||||
|
||||
# ******* script-server handeling *******
|
||||
# ******* script-server handling *******
|
||||
# Ugly hack to enable iframe usage
|
||||
sed -i "s/'X-Frame-Options', 'DENY'/ \
|
||||
'X-Frame-Options', 'ALLOWALL'/g" \
|
||||
@@ -73,7 +47,13 @@ sed -i "s/'X-Frame-Options', 'DENY'/ \
|
||||
cp -f /usr/share/script-server/conf/logging.json /var/script-server/logging.json
|
||||
|
||||
# Start script-server
|
||||
/var/lib/script-server-env/bin/python \
|
||||
/usr/share/script-server/launcher.py -d /var/script-server > /var/log/script-server.log &
|
||||
supervisorctl start script-server
|
||||
|
||||
return 0
|
||||
|
||||
# ******* nginx handling *******
|
||||
cp -r /var/www/* /run/shm
|
||||
supervisorctl start nginx # Start webserver
|
||||
|
||||
|
||||
# ******* OpenWrt handling *******
|
||||
supervisorctl start openwrt # Start webserver
|
||||
@@ -0,0 +1,30 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -Eeuo pipefail
|
||||
trap - ERR
|
||||
|
||||
. /run/helpers.sh
|
||||
|
||||
# Check if rootfs is in volume
|
||||
FILE=/storage/rootfs-${OPENWRT_VERSION}.img
|
||||
if [ -f "$FILE" ]; then
|
||||
info "$FILE exists. Nothing to do."
|
||||
else
|
||||
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
|
||||
|
||||
info "Inject some additional files into the image"
|
||||
mount /storage/rootfs-${OPENWRT_VERSION}.img /mnt
|
||||
# mount -o offset=$((512*262656)) /storage/disk.img /mnt # combined image ext4 partition starts at offset 262656
|
||||
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
|
||||
@@ -0,0 +1,80 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -Eeuo pipefail
|
||||
trap - ERR
|
||||
|
||||
. /run/helpers.sh
|
||||
|
||||
# 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
|
||||
|
||||
info "Boot previous $OLD_VERSION_ROOTFS to get config"
|
||||
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
|
||||
|
||||
info "Boot current rootfs-${OPENWRT_VERSION}.img to install config"
|
||||
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
|
||||
else
|
||||
info "rootfs-${OPENWRT_VERSION}.img is up to date. Nothing to do."
|
||||
fi
|
||||
+7
-107
@@ -2,10 +2,13 @@
|
||||
|
||||
# Based on https://github.com/qemus/qemu-docker
|
||||
set -Eeuo pipefail
|
||||
trap - ERR
|
||||
|
||||
. /run/helpers.sh
|
||||
. /run/install_openwrt_rootfs.sh
|
||||
. /run/migrate_openwrt_rootfs.sh
|
||||
|
||||
APP="OpenWrt"
|
||||
SUPPORT="https://github.com/AlbrechtL/openwrt-docker-arm64-build"
|
||||
VERS=$(qemu-system-aarch64 --version | head -n 1 | cut -d '(' -f 1)
|
||||
|
||||
attach_eth_if () {
|
||||
HOST_IF=$1
|
||||
@@ -39,36 +42,6 @@ attach_eth_if () {
|
||||
#ip link set $QEMU_IF up
|
||||
}
|
||||
|
||||
cd /run
|
||||
|
||||
# Initialize system
|
||||
. reset.sh
|
||||
|
||||
trap - ERR
|
||||
|
||||
# Check if rootfs is in volume
|
||||
FILE=/storage/rootfs-${OPENWRT_VERSION}.img
|
||||
if [ -f "$FILE" ]; then
|
||||
info "$FILE exists. Nothing to do."
|
||||
else
|
||||
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
|
||||
|
||||
info "Inject some additional files into the image"
|
||||
mount /storage/rootfs-${OPENWRT_VERSION}.img /mnt
|
||||
# mount -o offset=$((512*262656)) /storage/disk.img /mnt # combined image ext4 partition starts at offset 262656
|
||||
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
|
||||
|
||||
# Check KVM
|
||||
info "Checking for KVM ..."
|
||||
@@ -119,87 +92,14 @@ else
|
||||
USB_ARGS="-device usb-host,vendorid=0x$USB_VID_1,productid=0x$USB_PID_1"
|
||||
fi
|
||||
|
||||
# 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
|
||||
|
||||
info "Boot previous $OLD_VERSION_ROOTFS to get config"
|
||||
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
|
||||
|
||||
info "Boot current rootfs-${OPENWRT_VERSION}.img to install config"
|
||||
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
|
||||
|
||||
|
||||
info "Booting image using $VERS..."
|
||||
|
||||
# See qemu command if debug is enabled
|
||||
[[ "$DEBUG" == [Yy1]* ]] && set -x
|
||||
|
||||
#************************ FINAL BOOTING ************************
|
||||
|
||||
info "Booting image using $VERS..."
|
||||
exec qemu-system-aarch64 -M virt \
|
||||
qemu-system-aarch64 -M virt \
|
||||
-m 128 \
|
||||
-nodefaults \
|
||||
$CPU_ARGS -smp $CPU_COUNT \
|
||||
|
||||
+16
-1
@@ -13,7 +13,7 @@ file = /var/run/supervisord.sock
|
||||
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface
|
||||
|
||||
[program:init]
|
||||
command=/run/entry.sh
|
||||
command=/run/init_container.sh
|
||||
process_name=%(program_name)s
|
||||
autostart=true
|
||||
autorestart=false
|
||||
@@ -26,3 +26,18 @@ stderr_logfile_maxbytes=0
|
||||
command=nginx
|
||||
process_name=%(program_name)s
|
||||
autostart=false
|
||||
|
||||
[program:script-server]
|
||||
command=/var/lib/script-server-env/bin/python /usr/share/script-server/launcher.py -d /var/script-server
|
||||
process_name=%(program_name)s
|
||||
autostart=false
|
||||
|
||||
[program:openwrt]
|
||||
command=/run/run_openwrt.sh
|
||||
process_name=%(program_name)s
|
||||
autostart=false
|
||||
autorestart=false
|
||||
stdout_logfile=/dev/stdout
|
||||
stdout_logfile_maxbytes=0
|
||||
stderr_logfile=/dev/stderr
|
||||
stderr_logfile_maxbytes=0
|
||||
|
||||
Reference in New Issue
Block a user