Add direct web panel installer
This commit is contained in:
1 parent
04aa336add
commit
59979e9dba
9 files changed
+704
-108
No files matched your search
@@ -0,0 +1,6 @@
|
||||
config backup 'main'
|
||||
option output_dir '/tmp'
|
||||
option include_overlay '1'
|
||||
option include_rom '0'
|
||||
option include_raw_mtd '0'
|
||||
option keep_days '0'
|
||||
@@ -0,0 +1,665 @@
|
||||
#!/bin/sh
|
||||
|
||||
VERSION="1.0.0"
|
||||
FORMAT="owrt-full-backup-v1"
|
||||
DEFAULT_OUTPUT_DIR="/tmp"
|
||||
WORKDIR=""
|
||||
|
||||
log() {
|
||||
printf '%s\n' "$*" >&2
|
||||
}
|
||||
|
||||
warn() {
|
||||
printf 'WARNING: %s\n' "$*" >&2
|
||||
}
|
||||
|
||||
die() {
|
||||
printf 'ERROR: %s\n' "$*" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
cleanup() {
|
||||
if [ -n "$WORKDIR" ] && [ -d "$WORKDIR" ]; then
|
||||
rm -rf "$WORKDIR"
|
||||
fi
|
||||
}
|
||||
|
||||
trap cleanup EXIT INT TERM
|
||||
|
||||
usage() {
|
||||
cat <<'EOF'
|
||||
Usage:
|
||||
owrt-full-backup create [options]
|
||||
owrt-full-backup restore <archive.tar.gz> [options]
|
||||
owrt-full-backup inspect <archive.tar.gz>
|
||||
owrt-full-backup help
|
||||
|
||||
Create options:
|
||||
-o, --output-dir DIR Directory for the final backup archive
|
||||
-n, --name NAME Archive base name without .tar.gz
|
||||
--no-overlay Do not include /overlay/upper snapshot
|
||||
--include-rom Include read-only /rom rootfs snapshot
|
||||
--firmware-image FILE Copy a sysupgrade image into the backup
|
||||
--include-raw-mtd Also dump /dev/mtd* partitions into the backup
|
||||
|
||||
Restore options:
|
||||
--yes Do not ask for confirmation
|
||||
--no-configs Do not restore sysupgrade config backup
|
||||
--no-packages Do not reinstall packages from the saved list
|
||||
--overlay Restore /overlay/upper snapshot to /
|
||||
--flash-firmware Flash firmware image from the archive with sysupgrade
|
||||
|
||||
Examples:
|
||||
owrt-full-backup create -o /mnt/usb
|
||||
owrt-full-backup create -o /mnt/usb --firmware-image /tmp/openwrt.bin
|
||||
owrt-full-backup restore /mnt/usb/router-backup.tar.gz --yes
|
||||
EOF
|
||||
}
|
||||
|
||||
need_cmd() {
|
||||
command -v "$1" >/dev/null 2>&1 || die "required command not found: $1"
|
||||
}
|
||||
|
||||
make_workdir() {
|
||||
local base
|
||||
base="${TMPDIR:-/tmp}"
|
||||
WORKDIR="$(mktemp -d "$base/owrt-full-backup.XXXXXX" 2>/dev/null || true)"
|
||||
if [ -z "$WORKDIR" ] || [ ! -d "$WORKDIR" ]; then
|
||||
WORKDIR="$base/owrt-full-backup.$$"
|
||||
mkdir -p "$WORKDIR" || die "cannot create temporary directory: $WORKDIR"
|
||||
fi
|
||||
}
|
||||
|
||||
uci_get() {
|
||||
local key default value
|
||||
key="$1"
|
||||
default="$2"
|
||||
if command -v uci >/dev/null 2>&1; then
|
||||
value="$(uci -q get "fullbackup.main.$key" 2>/dev/null || true)"
|
||||
if [ -n "$value" ]; then
|
||||
printf '%s' "$value"
|
||||
return
|
||||
fi
|
||||
fi
|
||||
printf '%s' "$default"
|
||||
}
|
||||
|
||||
copy_if_exists() {
|
||||
local src dst
|
||||
src="$1"
|
||||
dst="$2"
|
||||
if [ -e "$src" ]; then
|
||||
cp -p "$src" "$dst" 2>/dev/null || cp "$src" "$dst" 2>/dev/null || true
|
||||
fi
|
||||
}
|
||||
|
||||
sanitize() {
|
||||
printf '%s' "$1" | tr -cs 'A-Za-z0-9._-' '_'
|
||||
}
|
||||
|
||||
hostname_safe() {
|
||||
local name
|
||||
name="$(hostname 2>/dev/null || printf 'openwrt')"
|
||||
sanitize "$name"
|
||||
}
|
||||
|
||||
board_name() {
|
||||
if [ -r /tmp/sysinfo/board_name ]; then
|
||||
cat /tmp/sysinfo/board_name
|
||||
return
|
||||
fi
|
||||
|
||||
if [ -r /etc/openwrt_release ]; then
|
||||
(
|
||||
. /etc/openwrt_release 2>/dev/null
|
||||
printf '%s' "${DISTRIB_TARGET:-openwrt}"
|
||||
)
|
||||
return
|
||||
fi
|
||||
|
||||
printf 'openwrt'
|
||||
}
|
||||
|
||||
release_text() {
|
||||
if [ -r /etc/openwrt_release ]; then
|
||||
(
|
||||
. /etc/openwrt_release 2>/dev/null
|
||||
printf '%s %s' "${DISTRIB_ID:-OpenWrt}" "${DISTRIB_RELEASE:-unknown}"
|
||||
)
|
||||
return
|
||||
fi
|
||||
|
||||
printf 'OpenWrt unknown'
|
||||
}
|
||||
|
||||
write_command_output() {
|
||||
local out
|
||||
out="$1"
|
||||
shift
|
||||
"$@" >"$out" 2>"$out.err" || true
|
||||
if [ ! -s "$out.err" ]; then
|
||||
rm -f "$out.err"
|
||||
fi
|
||||
}
|
||||
|
||||
validate_tar_paths() {
|
||||
local archive label
|
||||
archive="$1"
|
||||
label="$2"
|
||||
|
||||
if tar -tzf "$archive" | grep -Eq '(^/|(^|/)\.\.(/|$))'; then
|
||||
die "$label contains unsafe paths"
|
||||
fi
|
||||
}
|
||||
|
||||
create_metadata() {
|
||||
local meta packages firmware
|
||||
meta="$WORKDIR/meta"
|
||||
packages="$WORKDIR/packages"
|
||||
firmware="$WORKDIR/firmware"
|
||||
mkdir -p "$meta" "$packages" "$firmware"
|
||||
|
||||
cat >"$WORKDIR/MANIFEST" <<EOF
|
||||
format=$FORMAT
|
||||
tool_version=$VERSION
|
||||
created_at_utc=$(date -u '+%Y-%m-%dT%H:%M:%SZ' 2>/dev/null || date)
|
||||
hostname=$(hostname 2>/dev/null || printf 'openwrt')
|
||||
board=$(board_name)
|
||||
release=$(release_text)
|
||||
kernel=$(uname -a 2>/dev/null || true)
|
||||
EOF
|
||||
|
||||
copy_if_exists /etc/openwrt_release "$meta/openwrt_release"
|
||||
copy_if_exists /etc/openwrt_version "$meta/openwrt_version"
|
||||
copy_if_exists /etc/board.json "$meta/board.json"
|
||||
copy_if_exists /etc/sysupgrade.conf "$meta/sysupgrade.conf"
|
||||
copy_if_exists /proc/mtd "$meta/proc-mtd.txt"
|
||||
copy_if_exists /proc/partitions "$meta/proc-partitions.txt"
|
||||
|
||||
write_command_output "$meta/uname.txt" uname -a
|
||||
write_command_output "$meta/mounts.txt" mount
|
||||
write_command_output "$meta/df-h.txt" df -h
|
||||
|
||||
if command -v ubus >/dev/null 2>&1; then
|
||||
write_command_output "$meta/system-board.json" ubus call system board
|
||||
fi
|
||||
|
||||
if command -v uci >/dev/null 2>&1; then
|
||||
write_command_output "$meta/uci-show.txt" uci show
|
||||
fi
|
||||
|
||||
if command -v opkg >/dev/null 2>&1; then
|
||||
write_command_output "$packages/installed.txt" opkg list-installed
|
||||
write_command_output "$packages/print-architecture.txt" opkg print-architecture
|
||||
write_command_output "$packages/changed-conffiles.txt" opkg list-changed-conffiles
|
||||
copy_if_exists /usr/lib/opkg/status "$packages/opkg-status"
|
||||
else
|
||||
printf 'opkg was not available on this system.\n' >"$packages/installed.txt"
|
||||
fi
|
||||
|
||||
cat >"$firmware/README.txt" <<'EOF'
|
||||
OpenWrt usually does not keep the original sysupgrade image on the router.
|
||||
Use --firmware-image /path/to/openwrt-sysupgrade.bin when creating a backup
|
||||
if you want the restore archive to include a flashable firmware image.
|
||||
|
||||
Raw MTD dumps can be added with --include-raw-mtd, but they are hardware and
|
||||
partition-layout specific. Flashing raw MTD dumps on a different device or a
|
||||
different layout can permanently break the router.
|
||||
EOF
|
||||
}
|
||||
|
||||
create_sysupgrade_backup() {
|
||||
if command -v sysupgrade >/dev/null 2>&1; then
|
||||
if sysupgrade -b "$WORKDIR/config-backup.tar.gz" >/dev/null 2>"$WORKDIR/meta/sysupgrade-backup.err"; then
|
||||
rm -f "$WORKDIR/meta/sysupgrade-backup.err"
|
||||
else
|
||||
warn "sysupgrade config backup failed; falling back to /etc tar snapshot"
|
||||
tar -czf "$WORKDIR/config-backup.tar.gz" -C / etc 2>"$WORKDIR/meta/etc-backup.err" || die "cannot create config backup"
|
||||
fi
|
||||
sysupgrade -l >"$WORKDIR/meta/sysupgrade-file-list.txt" 2>/dev/null || true
|
||||
else
|
||||
warn "sysupgrade command not found; using /etc tar snapshot"
|
||||
tar -czf "$WORKDIR/config-backup.tar.gz" -C / etc 2>"$WORKDIR/meta/etc-backup.err" || die "cannot create config backup"
|
||||
fi
|
||||
}
|
||||
|
||||
create_overlay_snapshot() {
|
||||
if [ ! -d /overlay/upper ]; then
|
||||
printf 'No /overlay/upper directory was found on this system.\n' >"$WORKDIR/overlay-upper.README.txt"
|
||||
return
|
||||
fi
|
||||
|
||||
if tar -czf "$WORKDIR/overlay-upper.tar.gz" -C /overlay/upper . 2>"$WORKDIR/meta/overlay-upper.err"; then
|
||||
rm -f "$WORKDIR/meta/overlay-upper.err"
|
||||
else
|
||||
warn "overlay snapshot failed; backup will continue without it"
|
||||
rm -f "$WORKDIR/overlay-upper.tar.gz"
|
||||
fi
|
||||
}
|
||||
|
||||
create_rom_snapshot() {
|
||||
if [ ! -d /rom ]; then
|
||||
printf 'No /rom directory was found on this system.\n' >"$WORKDIR/rom-rootfs.README.txt"
|
||||
return
|
||||
fi
|
||||
|
||||
if tar -czf "$WORKDIR/rom-rootfs.tar.gz" -C /rom . 2>"$WORKDIR/meta/rom-rootfs.err"; then
|
||||
rm -f "$WORKDIR/meta/rom-rootfs.err"
|
||||
else
|
||||
warn "ROM rootfs snapshot failed; backup will continue without it"
|
||||
rm -f "$WORKDIR/rom-rootfs.tar.gz"
|
||||
fi
|
||||
}
|
||||
|
||||
copy_firmware_image() {
|
||||
local image base
|
||||
image="$1"
|
||||
[ -n "$image" ] || return
|
||||
[ -r "$image" ] || die "firmware image is not readable: $image"
|
||||
|
||||
base="$(basename "$image")"
|
||||
mkdir -p "$WORKDIR/firmware"
|
||||
cp "$image" "$WORKDIR/firmware/$base" || die "cannot copy firmware image"
|
||||
if command -v sha256sum >/dev/null 2>&1; then
|
||||
(
|
||||
cd "$WORKDIR/firmware" && sha256sum "$base" >"$base.sha256"
|
||||
) || true
|
||||
fi
|
||||
printf '%s\n' "$base" >"$WORKDIR/firmware/IMAGE"
|
||||
}
|
||||
|
||||
dump_raw_mtd() {
|
||||
local raw line dev name safe
|
||||
if [ ! -r /proc/mtd ]; then
|
||||
warn "/proc/mtd is not available; raw MTD dump skipped"
|
||||
return
|
||||
fi
|
||||
|
||||
raw="$WORKDIR/raw-mtd"
|
||||
mkdir -p "$raw"
|
||||
cp /proc/mtd "$raw/proc-mtd.txt" 2>/dev/null || true
|
||||
|
||||
while IFS= read -r line; do
|
||||
case "$line" in
|
||||
mtd*:*)
|
||||
dev="${line%%:*}"
|
||||
name="$(printf '%s\n' "$line" | sed 's/.*"\(.*\)".*/\1/')"
|
||||
safe="$(sanitize "$name")"
|
||||
if [ -e "/dev/$dev" ]; then
|
||||
log "Dumping /dev/$dev ($name)"
|
||||
dd if="/dev/$dev" of="$raw/$dev-$safe.bin" bs=64k 2>"$raw/$dev-$safe.dd.log" || warn "failed to dump /dev/$dev"
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
done </proc/mtd
|
||||
}
|
||||
|
||||
prune_old_backups() {
|
||||
local output_dir keep_days
|
||||
output_dir="$1"
|
||||
keep_days="$2"
|
||||
|
||||
case "$keep_days" in
|
||||
''|0) return ;;
|
||||
esac
|
||||
|
||||
case "$keep_days" in
|
||||
*[!0-9]*)
|
||||
warn "keep_days must be a number; cleanup skipped"
|
||||
return
|
||||
;;
|
||||
esac
|
||||
|
||||
find "$output_dir" -type f -name '*-owrt-full-backup.tar.gz' -mtime "+$keep_days" -exec rm -f {} \; 2>/dev/null || true
|
||||
find "$output_dir" -type f -name '*-owrt-full-backup.tar.gz.sha256' -mtime "+$keep_days" -exec rm -f {} \; 2>/dev/null || true
|
||||
}
|
||||
|
||||
cmd_create() {
|
||||
local output_dir name include_overlay include_rom include_raw_mtd firmware_image timestamp host board archive keep_days
|
||||
output_dir="$(uci_get output_dir "$DEFAULT_OUTPUT_DIR")"
|
||||
include_overlay="$(uci_get include_overlay 1)"
|
||||
include_rom="$(uci_get include_rom 0)"
|
||||
include_raw_mtd="$(uci_get include_raw_mtd 0)"
|
||||
keep_days="$(uci_get keep_days 0)"
|
||||
name=""
|
||||
firmware_image=""
|
||||
|
||||
while [ $# -gt 0 ]; do
|
||||
case "$1" in
|
||||
-o|--output-dir)
|
||||
[ $# -ge 2 ] || die "$1 requires a directory"
|
||||
output_dir="$2"
|
||||
shift 2
|
||||
;;
|
||||
-n|--name)
|
||||
[ $# -ge 2 ] || die "$1 requires a name"
|
||||
name="$2"
|
||||
shift 2
|
||||
;;
|
||||
--no-overlay)
|
||||
include_overlay=0
|
||||
shift
|
||||
;;
|
||||
--include-rom)
|
||||
include_rom=1
|
||||
shift
|
||||
;;
|
||||
--firmware-image)
|
||||
[ $# -ge 2 ] || die "$1 requires a file"
|
||||
firmware_image="$2"
|
||||
shift 2
|
||||
;;
|
||||
--include-raw-mtd)
|
||||
include_raw_mtd=1
|
||||
shift
|
||||
;;
|
||||
-h|--help)
|
||||
usage
|
||||
exit 0
|
||||
;;
|
||||
*)
|
||||
die "unknown create option: $1"
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
need_cmd tar
|
||||
need_cmd gzip
|
||||
mkdir -p "$output_dir" || die "cannot create output directory: $output_dir"
|
||||
make_workdir
|
||||
|
||||
timestamp="$(date '+%Y%m%d-%H%M%S' 2>/dev/null || date '+%s')"
|
||||
host="$(hostname_safe)"
|
||||
board="$(sanitize "$(board_name)")"
|
||||
if [ -z "$name" ]; then
|
||||
name="$host-$board-$timestamp-owrt-full-backup"
|
||||
fi
|
||||
archive="$output_dir/$name.tar.gz"
|
||||
|
||||
log "Creating backup workspace"
|
||||
create_metadata
|
||||
create_sysupgrade_backup
|
||||
|
||||
if [ "$include_overlay" = "1" ]; then
|
||||
log "Adding overlay snapshot"
|
||||
create_overlay_snapshot
|
||||
else
|
||||
printf 'Overlay snapshot disabled by option.\n' >"$WORKDIR/overlay-upper.README.txt"
|
||||
fi
|
||||
|
||||
if [ "$include_rom" = "1" ]; then
|
||||
log "Adding ROM rootfs snapshot"
|
||||
create_rom_snapshot
|
||||
else
|
||||
printf 'ROM rootfs snapshot disabled by option.\n' >"$WORKDIR/rom-rootfs.README.txt"
|
||||
fi
|
||||
|
||||
copy_firmware_image "$firmware_image"
|
||||
|
||||
if [ "$include_raw_mtd" = "1" ]; then
|
||||
warn "raw MTD dumps are device-specific and can be very large"
|
||||
dump_raw_mtd
|
||||
fi
|
||||
|
||||
if tar -czf "$archive" -C "$WORKDIR" .; then
|
||||
:
|
||||
else
|
||||
die "cannot create archive: $archive"
|
||||
fi
|
||||
|
||||
if command -v sha256sum >/dev/null 2>&1; then
|
||||
sha256sum "$archive" >"$archive.sha256" 2>/dev/null || true
|
||||
fi
|
||||
|
||||
prune_old_backups "$output_dir" "$keep_days"
|
||||
log "Backup created: $archive"
|
||||
if [ -f "$archive.sha256" ]; then
|
||||
log "Checksum created: $archive.sha256"
|
||||
fi
|
||||
}
|
||||
|
||||
extract_archive() {
|
||||
local archive
|
||||
archive="$1"
|
||||
[ -r "$archive" ] || die "archive is not readable: $archive"
|
||||
need_cmd tar
|
||||
need_cmd gzip
|
||||
validate_tar_paths "$archive" "archive"
|
||||
make_workdir
|
||||
tar -xzf "$archive" -C "$WORKDIR" || die "cannot extract archive"
|
||||
[ -r "$WORKDIR/MANIFEST" ] || die "archive does not contain MANIFEST"
|
||||
grep -q "^format=$FORMAT" "$WORKDIR/MANIFEST" || die "unsupported backup format"
|
||||
}
|
||||
|
||||
show_manifest_summary() {
|
||||
local count
|
||||
if [ -r "$WORKDIR/MANIFEST" ]; then
|
||||
sed -n '1,40p' "$WORKDIR/MANIFEST"
|
||||
fi
|
||||
|
||||
if [ -r "$WORKDIR/packages/installed.txt" ]; then
|
||||
count="$(grep -c ' - ' "$WORKDIR/packages/installed.txt" 2>/dev/null)"
|
||||
[ -n "$count" ] || count=0
|
||||
printf 'installed_packages_count=%s\n' "$count"
|
||||
fi
|
||||
|
||||
if [ -r "$WORKDIR/firmware/IMAGE" ]; then
|
||||
printf 'firmware_image=%s\n' "$(cat "$WORKDIR/firmware/IMAGE")"
|
||||
else
|
||||
printf 'firmware_image=not_included\n'
|
||||
fi
|
||||
|
||||
if [ -r "$WORKDIR/overlay-upper.tar.gz" ]; then
|
||||
printf 'overlay_snapshot=included\n'
|
||||
else
|
||||
printf 'overlay_snapshot=not_included\n'
|
||||
fi
|
||||
|
||||
if [ -r "$WORKDIR/rom-rootfs.tar.gz" ]; then
|
||||
printf 'rom_rootfs_snapshot=included\n'
|
||||
else
|
||||
printf 'rom_rootfs_snapshot=not_included\n'
|
||||
fi
|
||||
|
||||
if [ -d "$WORKDIR/raw-mtd" ]; then
|
||||
printf 'raw_mtd=included\n'
|
||||
else
|
||||
printf 'raw_mtd=not_included\n'
|
||||
fi
|
||||
}
|
||||
|
||||
confirm_restore() {
|
||||
local yes answer
|
||||
yes="$1"
|
||||
if [ "$yes" = "1" ]; then
|
||||
return
|
||||
fi
|
||||
|
||||
printf 'This will change files on this OpenWrt device. Type "yes" to continue: ' >&2
|
||||
read -r answer
|
||||
[ "$answer" = "yes" ] || die "restore cancelled"
|
||||
}
|
||||
|
||||
restore_configs() {
|
||||
if [ ! -r "$WORKDIR/config-backup.tar.gz" ]; then
|
||||
warn "config-backup.tar.gz not found; config restore skipped"
|
||||
return
|
||||
fi
|
||||
|
||||
log "Restoring config backup"
|
||||
validate_tar_paths "$WORKDIR/config-backup.tar.gz" "config backup"
|
||||
tar -xzpf "$WORKDIR/config-backup.tar.gz" -C / || die "config restore failed"
|
||||
}
|
||||
|
||||
restore_packages() {
|
||||
local installed line pkg failed
|
||||
installed="$WORKDIR/packages/installed.txt"
|
||||
[ -r "$installed" ] || {
|
||||
warn "package list not found; package restore skipped"
|
||||
return
|
||||
}
|
||||
|
||||
if ! command -v opkg >/dev/null 2>&1; then
|
||||
warn "opkg not found; package restore skipped"
|
||||
return
|
||||
fi
|
||||
|
||||
log "Updating package lists"
|
||||
opkg update || warn "opkg update failed; package install will still be attempted"
|
||||
|
||||
failed=0
|
||||
while IFS= read -r line; do
|
||||
case "$line" in
|
||||
*' - '*)
|
||||
pkg="${line%% - *}"
|
||||
;;
|
||||
*)
|
||||
continue
|
||||
;;
|
||||
esac
|
||||
|
||||
if opkg status "$pkg" 2>/dev/null | grep -q '^Status:.* installed'; then
|
||||
continue
|
||||
fi
|
||||
|
||||
log "Installing package: $pkg"
|
||||
if ! opkg install "$pkg"; then
|
||||
warn "failed to install package: $pkg"
|
||||
failed=1
|
||||
fi
|
||||
done <"$installed"
|
||||
|
||||
if [ "$failed" = "1" ]; then
|
||||
warn "some packages could not be installed; check feed compatibility for this OpenWrt version"
|
||||
fi
|
||||
}
|
||||
|
||||
restore_overlay() {
|
||||
if [ ! -r "$WORKDIR/overlay-upper.tar.gz" ]; then
|
||||
warn "overlay snapshot not found; overlay restore skipped"
|
||||
return
|
||||
fi
|
||||
|
||||
warn "overlay restore is best used on the same device and same OpenWrt release"
|
||||
log "Restoring overlay snapshot to /"
|
||||
validate_tar_paths "$WORKDIR/overlay-upper.tar.gz" "overlay snapshot"
|
||||
tar -xzpf "$WORKDIR/overlay-upper.tar.gz" -C / || die "overlay restore failed"
|
||||
}
|
||||
|
||||
flash_firmware() {
|
||||
local image_name image_path
|
||||
[ -r "$WORKDIR/firmware/IMAGE" ] || die "archive does not contain a firmware image"
|
||||
image_name="$(cat "$WORKDIR/firmware/IMAGE")"
|
||||
case "$image_name" in
|
||||
*/*|../*|*/../*|..)
|
||||
die "firmware image name is unsafe"
|
||||
;;
|
||||
esac
|
||||
image_path="$WORKDIR/firmware/$image_name"
|
||||
[ -r "$image_path" ] || die "firmware image listed in archive is missing: $image_name"
|
||||
command -v sysupgrade >/dev/null 2>&1 || die "sysupgrade command not found"
|
||||
|
||||
warn "sysupgrade will flash firmware and reboot the device"
|
||||
sysupgrade "$image_path"
|
||||
}
|
||||
|
||||
cmd_restore() {
|
||||
local archive yes do_configs do_packages do_overlay do_flash
|
||||
[ $# -ge 1 ] || die "restore requires an archive path"
|
||||
archive="$1"
|
||||
shift
|
||||
|
||||
yes=0
|
||||
do_configs=1
|
||||
do_packages=1
|
||||
do_overlay=0
|
||||
do_flash=0
|
||||
|
||||
while [ $# -gt 0 ]; do
|
||||
case "$1" in
|
||||
--yes)
|
||||
yes=1
|
||||
shift
|
||||
;;
|
||||
--no-configs)
|
||||
do_configs=0
|
||||
shift
|
||||
;;
|
||||
--no-packages)
|
||||
do_packages=0
|
||||
shift
|
||||
;;
|
||||
--overlay)
|
||||
do_overlay=1
|
||||
shift
|
||||
;;
|
||||
--flash-firmware)
|
||||
do_flash=1
|
||||
shift
|
||||
;;
|
||||
-h|--help)
|
||||
usage
|
||||
exit 0
|
||||
;;
|
||||
*)
|
||||
die "unknown restore option: $1"
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
extract_archive "$archive"
|
||||
show_manifest_summary >&2
|
||||
confirm_restore "$yes"
|
||||
|
||||
if [ "$do_flash" = "1" ]; then
|
||||
flash_firmware
|
||||
return
|
||||
fi
|
||||
|
||||
if [ "$do_configs" = "1" ]; then
|
||||
restore_configs
|
||||
fi
|
||||
|
||||
if [ "$do_packages" = "1" ]; then
|
||||
restore_packages
|
||||
fi
|
||||
|
||||
if [ "$do_overlay" = "1" ]; then
|
||||
restore_overlay
|
||||
fi
|
||||
|
||||
log "Restore finished. Reboot is recommended."
|
||||
}
|
||||
|
||||
cmd_inspect() {
|
||||
[ $# -ge 1 ] || die "inspect requires an archive path"
|
||||
extract_archive "$1"
|
||||
show_manifest_summary
|
||||
}
|
||||
|
||||
main() {
|
||||
local cmd
|
||||
cmd="${1:-help}"
|
||||
case "$cmd" in
|
||||
create)
|
||||
shift
|
||||
cmd_create "$@"
|
||||
;;
|
||||
restore)
|
||||
shift
|
||||
cmd_restore "$@"
|
||||
;;
|
||||
inspect)
|
||||
shift
|
||||
cmd_inspect "$@"
|
||||
;;
|
||||
help|-h|--help)
|
||||
usage
|
||||
;;
|
||||
*)
|
||||
die "unknown command: $cmd"
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
main "$@"
|
||||
@@ -0,0 +1,483 @@
|
||||
#!/bin/sh
|
||||
|
||||
BACKEND="${BACKEND:-/usr/sbin/owrt-full-backup}"
|
||||
KEY_FILE="${KEY_FILE:-/etc/owrt-full-backup/web.key}"
|
||||
PARAMS_FILE="${TMPDIR:-/tmp}/owrt-full-backup-cgi.$$"
|
||||
RESULT_FILE=""
|
||||
RESULT_TITLE=""
|
||||
RESULT_CODE=""
|
||||
PROJECT_URL="${PROJECT_URL:-https://github.com/kzolotarev95/openwrt-full-backup}"
|
||||
RAW_URL="${RAW_URL:-https://raw.githubusercontent.com/kzolotarev95/openwrt-full-backup/main}"
|
||||
|
||||
cleanup() {
|
||||
rm -f "$PARAMS_FILE"
|
||||
if [ -n "$RESULT_FILE" ]; then
|
||||
rm -f "$RESULT_FILE"
|
||||
fi
|
||||
}
|
||||
|
||||
trap cleanup EXIT INT TERM
|
||||
|
||||
html_escape() {
|
||||
sed 's/&/\&/g; s/</\</g; s/>/\>/g; s/"/\"/g'
|
||||
}
|
||||
|
||||
h() {
|
||||
printf '%s' "$1" | html_escape
|
||||
}
|
||||
|
||||
url_decode() {
|
||||
local data
|
||||
data="$(printf '%s' "$1" | sed 's/+/ /g; s/%/\\x/g')"
|
||||
printf '%b' "$data"
|
||||
}
|
||||
|
||||
parse_params() {
|
||||
local data old_ifs pair key value
|
||||
data="$1"
|
||||
old_ifs="$IFS"
|
||||
IFS='&'
|
||||
for pair in $data; do
|
||||
key="${pair%%=*}"
|
||||
value="${pair#*=}"
|
||||
[ "$pair" = "$key" ] && value=""
|
||||
key="$(url_decode "$key" | tr -d '\r\n\t')"
|
||||
value="$(url_decode "$value" | tr '\r\n\t' ' ')"
|
||||
[ -n "$key" ] && printf '%s\t%s\n' "$key" "$value" >>"$PARAMS_FILE"
|
||||
done
|
||||
IFS="$old_ifs"
|
||||
}
|
||||
|
||||
param() {
|
||||
awk -F ' ' -v k="$1" '$1 == k { print $2; exit }' "$PARAMS_FILE"
|
||||
}
|
||||
|
||||
has_param() {
|
||||
awk -F ' ' -v k="$1" '$1 == k { found = 1 } END { exit(found ? 0 : 1) }' "$PARAMS_FILE"
|
||||
}
|
||||
|
||||
read_request() {
|
||||
local post_data
|
||||
: >"$PARAMS_FILE"
|
||||
parse_params "${QUERY_STRING:-}"
|
||||
if [ "${REQUEST_METHOD:-GET}" = "POST" ] && [ -n "${CONTENT_LENGTH:-}" ]; then
|
||||
post_data="$(dd bs=1 count="$CONTENT_LENGTH" 2>/dev/null)"
|
||||
parse_params "$post_data"
|
||||
fi
|
||||
}
|
||||
|
||||
config_get() {
|
||||
local key default value
|
||||
key="$1"
|
||||
default="$2"
|
||||
if command -v uci >/dev/null 2>&1; then
|
||||
value="$(uci -q get "fullbackup.main.$key" 2>/dev/null || true)"
|
||||
[ -n "$value" ] && {
|
||||
printf '%s' "$value"
|
||||
return
|
||||
}
|
||||
fi
|
||||
printf '%s' "$default"
|
||||
}
|
||||
|
||||
web_key() {
|
||||
cat "$KEY_FILE" 2>/dev/null
|
||||
}
|
||||
|
||||
self_url() {
|
||||
printf '%s' "${SCRIPT_NAME:-/cgi-bin/owrt-full-backup}"
|
||||
}
|
||||
|
||||
authorized() {
|
||||
local expected supplied
|
||||
expected="$(web_key)"
|
||||
supplied="$(param key)"
|
||||
[ -n "$expected" ] && [ "$supplied" = "$expected" ]
|
||||
}
|
||||
|
||||
http_html() {
|
||||
printf 'Content-Type: text/html; charset=utf-8\r\n\r\n'
|
||||
}
|
||||
|
||||
http_unauthorized() {
|
||||
http_html
|
||||
cat <<'EOF'
|
||||
<!doctype html><html><head><meta charset="utf-8"><title>OpenWrt Full Backup</title></head>
|
||||
<body><h1>Access denied</h1><p>Open the panel with the secret key printed by install.sh.</p></body></html>
|
||||
EOF
|
||||
}
|
||||
|
||||
valid_abs_path() {
|
||||
case "$1" in
|
||||
/*) ;;
|
||||
*) return 1 ;;
|
||||
esac
|
||||
printf '%s' "$1" | grep -Eq '^/[A-Za-z0-9._/-]+$'
|
||||
}
|
||||
|
||||
download_file() {
|
||||
local file base
|
||||
file="$(param file)"
|
||||
valid_abs_path "$file" || {
|
||||
http_html
|
||||
printf '<p>Bad file path.</p>'
|
||||
exit 0
|
||||
}
|
||||
case "$file" in
|
||||
*.tar.gz|*.tar.gz.sha256) ;;
|
||||
*) http_html; printf '<p>Only backup archives and checksums can be downloaded.</p>'; exit 0 ;;
|
||||
esac
|
||||
[ -f "$file" ] || {
|
||||
http_html
|
||||
printf '<p>File not found.</p>'
|
||||
exit 0
|
||||
}
|
||||
base="$(basename "$file")"
|
||||
case "$file" in
|
||||
*.sha256) printf 'Content-Type: text/plain\r\n' ;;
|
||||
*) printf 'Content-Type: application/gzip\r\n' ;;
|
||||
esac
|
||||
printf 'Content-Disposition: attachment; filename="%s"\r\n\r\n' "$base"
|
||||
cat "$file"
|
||||
exit 0
|
||||
}
|
||||
|
||||
run_backend() {
|
||||
RESULT_TITLE="$1"
|
||||
shift
|
||||
RESULT_FILE="${TMPDIR:-/tmp}/owrt-full-backup-result.$$"
|
||||
if [ ! -x "$BACKEND" ]; then
|
||||
RESULT_CODE=127
|
||||
printf 'Backend is not installed: %s\n' "$BACKEND" >"$RESULT_FILE"
|
||||
return
|
||||
fi
|
||||
"$BACKEND" "$@" >"$RESULT_FILE" 2>&1
|
||||
RESULT_CODE="$?"
|
||||
}
|
||||
|
||||
handle_create() {
|
||||
local output_dir name firmware
|
||||
output_dir="$(param output_dir)"
|
||||
name="$(param name)"
|
||||
firmware="$(param firmware_image)"
|
||||
[ -n "$output_dir" ] || output_dir="$(config_get output_dir /tmp)"
|
||||
valid_abs_path "$output_dir" || {
|
||||
RESULT_TITLE="Create backup"
|
||||
RESULT_CODE=2
|
||||
RESULT_FILE="${TMPDIR:-/tmp}/owrt-full-backup-result.$$"
|
||||
printf 'Bad output directory. Use an absolute path, for example /mnt/usb.\n' >"$RESULT_FILE"
|
||||
return
|
||||
}
|
||||
|
||||
set -- create -o "$output_dir"
|
||||
[ -n "$name" ] && set -- "$@" -n "$name"
|
||||
has_param include_overlay || set -- "$@" --no-overlay
|
||||
has_param include_rom && set -- "$@" --include-rom
|
||||
has_param include_raw_mtd && set -- "$@" --include-raw-mtd
|
||||
[ -n "$firmware" ] && set -- "$@" --firmware-image "$firmware"
|
||||
run_backend "Create backup" "$@"
|
||||
}
|
||||
|
||||
handle_inspect() {
|
||||
local archive
|
||||
archive="$(param archive)"
|
||||
valid_abs_path "$archive" || {
|
||||
RESULT_TITLE="Inspect backup"
|
||||
RESULT_CODE=2
|
||||
RESULT_FILE="${TMPDIR:-/tmp}/owrt-full-backup-result.$$"
|
||||
printf 'Bad archive path.\n' >"$RESULT_FILE"
|
||||
return
|
||||
}
|
||||
run_backend "Inspect backup" inspect "$archive"
|
||||
}
|
||||
|
||||
handle_restore() {
|
||||
local archive confirm
|
||||
archive="$(param archive)"
|
||||
confirm="$(param confirm)"
|
||||
if [ "$confirm" != "RESTORE" ]; then
|
||||
RESULT_TITLE="Restore backup"
|
||||
RESULT_CODE=2
|
||||
RESULT_FILE="${TMPDIR:-/tmp}/owrt-full-backup-result.$$"
|
||||
printf 'Type RESTORE to confirm restore.\n' >"$RESULT_FILE"
|
||||
return
|
||||
fi
|
||||
valid_abs_path "$archive" || {
|
||||
RESULT_TITLE="Restore backup"
|
||||
RESULT_CODE=2
|
||||
RESULT_FILE="${TMPDIR:-/tmp}/owrt-full-backup-result.$$"
|
||||
printf 'Bad archive path.\n' >"$RESULT_FILE"
|
||||
return
|
||||
}
|
||||
|
||||
set -- restore "$archive" --yes
|
||||
has_param restore_configs || set -- "$@" --no-configs
|
||||
has_param restore_packages || set -- "$@" --no-packages
|
||||
has_param restore_overlay && set -- "$@" --overlay
|
||||
has_param flash_firmware && set -- "$@" --flash-firmware
|
||||
run_backend "Restore backup" "$@"
|
||||
}
|
||||
|
||||
handle_save_defaults() {
|
||||
local output_dir include_overlay include_rom include_raw_mtd keep_days
|
||||
RESULT_TITLE="Save defaults"
|
||||
RESULT_CODE=0
|
||||
RESULT_FILE="${TMPDIR:-/tmp}/owrt-full-backup-result.$$"
|
||||
output_dir="$(param default_output_dir)"
|
||||
keep_days="$(param keep_days)"
|
||||
valid_abs_path "$output_dir" || {
|
||||
RESULT_CODE=2
|
||||
printf 'Bad output directory.\n' >"$RESULT_FILE"
|
||||
return
|
||||
}
|
||||
case "$keep_days" in ''|*[!0-9]*) keep_days=0 ;; esac
|
||||
has_param default_include_overlay && include_overlay=1 || include_overlay=0
|
||||
has_param default_include_rom && include_rom=1 || include_rom=0
|
||||
has_param default_include_raw_mtd && include_raw_mtd=1 || include_raw_mtd=0
|
||||
|
||||
if command -v uci >/dev/null 2>&1; then
|
||||
uci -q batch <<EOF >"$RESULT_FILE" 2>&1
|
||||
set fullbackup.main=backup
|
||||
set fullbackup.main.output_dir='$output_dir'
|
||||
set fullbackup.main.include_overlay='$include_overlay'
|
||||
set fullbackup.main.include_rom='$include_rom'
|
||||
set fullbackup.main.include_raw_mtd='$include_raw_mtd'
|
||||
set fullbackup.main.keep_days='$keep_days'
|
||||
commit fullbackup
|
||||
EOF
|
||||
RESULT_CODE="$?"
|
||||
[ "$RESULT_CODE" = "0" ] && printf 'Defaults saved.\n' >>"$RESULT_FILE"
|
||||
else
|
||||
RESULT_CODE=127
|
||||
printf 'uci command not found.\n' >"$RESULT_FILE"
|
||||
fi
|
||||
}
|
||||
|
||||
handle_action() {
|
||||
local action
|
||||
action="$(param action)"
|
||||
case "$action" in
|
||||
create) handle_create ;;
|
||||
inspect) handle_inspect ;;
|
||||
restore) handle_restore ;;
|
||||
save_defaults) handle_save_defaults ;;
|
||||
esac
|
||||
}
|
||||
|
||||
system_value() {
|
||||
case "$1" in
|
||||
host) hostname 2>/dev/null || printf 'openwrt' ;;
|
||||
release)
|
||||
if [ -r /etc/openwrt_release ]; then
|
||||
. /etc/openwrt_release 2>/dev/null
|
||||
printf '%s %s' "${DISTRIB_ID:-OpenWrt}" "${DISTRIB_RELEASE:-unknown}"
|
||||
else
|
||||
printf 'OpenWrt unknown'
|
||||
fi
|
||||
;;
|
||||
board)
|
||||
if [ -r /tmp/sysinfo/board_name ]; then
|
||||
cat /tmp/sysinfo/board_name
|
||||
else
|
||||
printf 'unknown'
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
checkbox_attr() {
|
||||
[ "$1" = "1" ] && printf ' checked'
|
||||
}
|
||||
|
||||
backup_rows() {
|
||||
local dir key file base size mtime
|
||||
dir="$(config_get output_dir /tmp)"
|
||||
key="$(h "$(param key)")"
|
||||
[ -d "$dir" ] || {
|
||||
printf '<tr><td colspan="4">Output directory does not exist.</td></tr>'
|
||||
return
|
||||
}
|
||||
for file in "$dir"/*-owrt-full-backup.tar.gz; do
|
||||
[ -f "$file" ] || continue
|
||||
base="$(basename "$file")"
|
||||
size="$(ls -lh "$file" 2>/dev/null | awk '{print $5}')"
|
||||
mtime="$(ls -l "$file" 2>/dev/null | awk '{print $6" "$7" "$8}')"
|
||||
printf '<tr><td><code>%s</code></td><td>%s</td><td>%s</td><td><a href="%s?key=%s&action=download&file=%s">download</a></td></tr>' \
|
||||
"$(h "$base")" "$(h "$size")" "$(h "$mtime")" "$(self_url)" "$key" "$(h "$file")"
|
||||
done
|
||||
}
|
||||
|
||||
page() {
|
||||
local key output_dir include_overlay include_rom include_raw_mtd keep_days
|
||||
key="$(h "$(param key)")"
|
||||
output_dir="$(config_get output_dir /tmp)"
|
||||
include_overlay="$(config_get include_overlay 1)"
|
||||
include_rom="$(config_get include_rom 0)"
|
||||
include_raw_mtd="$(config_get include_raw_mtd 0)"
|
||||
keep_days="$(config_get keep_days 0)"
|
||||
|
||||
http_html
|
||||
cat <<EOF
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<title>OpenWrt Full Backup</title>
|
||||
<style>
|
||||
:root { color-scheme: light dark; --bg: #f6f7f9; --panel: #fff; --text: #15181c; --muted: #667085; --line: #d9dee7; --accent: #1769e0; --bad: #b42318; --ok: #067647; }
|
||||
@media (prefers-color-scheme: dark) { :root { --bg: #111418; --panel: #181d23; --text: #eef2f6; --muted: #a6b0bf; --line: #2d3642; --accent: #6aa4ff; --bad: #ff9b91; --ok: #7ee0a3; } }
|
||||
* { box-sizing: border-box; }
|
||||
body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.45 system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; }
|
||||
header { background: var(--panel); border-bottom: 1px solid var(--line); padding: 18px 20px; }
|
||||
main { max-width: 1180px; margin: 0 auto; padding: 18px; display: grid; gap: 14px; }
|
||||
h1 { margin: 0; font-size: 22px; }
|
||||
h2 { margin: 0 0 12px; font-size: 16px; }
|
||||
p { margin: 6px 0; color: var(--muted); }
|
||||
.grid { display: grid; gap: 14px; grid-template-columns: repeat(12, 1fr); }
|
||||
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 14px; }
|
||||
.span4 { grid-column: span 4; }
|
||||
.span6 { grid-column: span 6; }
|
||||
.span8 { grid-column: span 8; }
|
||||
.span12 { grid-column: span 12; }
|
||||
label { display: block; margin: 9px 0 4px; font-weight: 600; }
|
||||
input[type=text], input[type=number] { width: 100%; border: 1px solid var(--line); border-radius: 6px; background: transparent; color: var(--text); padding: 9px; }
|
||||
.checks label { font-weight: 500; display: flex; gap: 8px; align-items: center; margin: 8px 0; }
|
||||
button, .button { display: inline-flex; align-items: center; justify-content: center; min-height: 36px; border: 0; border-radius: 6px; background: var(--accent); color: #fff; padding: 8px 12px; text-decoration: none; font-weight: 700; cursor: pointer; }
|
||||
.danger { background: var(--bad); }
|
||||
.muted { color: var(--muted); }
|
||||
code, pre { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
|
||||
pre { overflow: auto; background: rgba(127,127,127,.12); border-radius: 6px; padding: 10px; }
|
||||
table { width: 100%; border-collapse: collapse; }
|
||||
td, th { border-bottom: 1px solid var(--line); padding: 8px 6px; text-align: left; vertical-align: top; }
|
||||
.status { display: flex; flex-wrap: wrap; gap: 8px; }
|
||||
.pill { border: 1px solid var(--line); border-radius: 999px; padding: 5px 9px; color: var(--muted); }
|
||||
@media (max-width: 820px) { .span4, .span6, .span8, .span12 { grid-column: 1 / -1; } main { padding: 12px; } }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<header>
|
||||
<h1>OpenWrt Full Backup</h1>
|
||||
<p>Direct web panel, no IPK build required. Keep this URL secret.</p>
|
||||
</header>
|
||||
<main>
|
||||
EOF
|
||||
|
||||
if [ -n "$RESULT_FILE" ]; then
|
||||
printf '<section class="panel span12"><h2>%s</h2><p>Exit code: %s</p><pre>' "$(h "$RESULT_TITLE")" "$(h "$RESULT_CODE")"
|
||||
html_escape <"$RESULT_FILE"
|
||||
printf '</pre></section>'
|
||||
fi
|
||||
|
||||
cat <<EOF
|
||||
<section class="grid">
|
||||
<div class="panel span4">
|
||||
<h2>Device</h2>
|
||||
<div class="status">
|
||||
<span class="pill">Host: $(h "$(system_value host)")</span>
|
||||
<span class="pill">Release: $(h "$(system_value release)")</span>
|
||||
<span class="pill">Board: $(h "$(system_value board)")</span>
|
||||
</div>
|
||||
<pre>$(df -h 2>/dev/null | html_escape)</pre>
|
||||
</div>
|
||||
|
||||
<form class="panel span8" method="post" action="$(self_url)">
|
||||
<h2>Create backup</h2>
|
||||
<input type="hidden" name="key" value="$key">
|
||||
<input type="hidden" name="action" value="create">
|
||||
<label>Output directory</label>
|
||||
<input type="text" name="output_dir" value="$(h "$output_dir")">
|
||||
<label>Archive name</label>
|
||||
<input type="text" name="name" placeholder="auto name">
|
||||
<label>Firmware image path</label>
|
||||
<input type="text" name="firmware_image" placeholder="/tmp/openwrt-sysupgrade.bin">
|
||||
<div class="checks">
|
||||
<label><input type="checkbox" name="include_overlay" value="1"$(checkbox_attr "$include_overlay")> include /overlay/upper</label>
|
||||
<label><input type="checkbox" name="include_rom" value="1"$(checkbox_attr "$include_rom")> include /rom rootfs snapshot</label>
|
||||
<label><input type="checkbox" name="include_raw_mtd" value="1"$(checkbox_attr "$include_raw_mtd")> include raw MTD dumps</label>
|
||||
</div>
|
||||
<button type="submit">Create backup</button>
|
||||
</form>
|
||||
|
||||
<div class="panel span12">
|
||||
<h2>Backups in $(h "$output_dir")</h2>
|
||||
<table><thead><tr><th>File</th><th>Size</th><th>Date</th><th>Action</th></tr></thead><tbody>
|
||||
$(backup_rows)
|
||||
</tbody></table>
|
||||
</div>
|
||||
|
||||
<form class="panel span6" method="post" action="$(self_url)">
|
||||
<h2>Inspect archive</h2>
|
||||
<input type="hidden" name="key" value="$key">
|
||||
<input type="hidden" name="action" value="inspect">
|
||||
<label>Archive path</label>
|
||||
<input type="text" name="archive" placeholder="/mnt/usb/router-owrt-full-backup.tar.gz">
|
||||
<button type="submit">Inspect</button>
|
||||
</form>
|
||||
|
||||
<form class="panel span6" method="post" action="$(self_url)">
|
||||
<h2>Restore archive</h2>
|
||||
<input type="hidden" name="key" value="$key">
|
||||
<input type="hidden" name="action" value="restore">
|
||||
<label>Archive path</label>
|
||||
<input type="text" name="archive" placeholder="/mnt/usb/router-owrt-full-backup.tar.gz">
|
||||
<div class="checks">
|
||||
<label><input type="checkbox" name="restore_configs" value="1" checked> restore configs</label>
|
||||
<label><input type="checkbox" name="restore_packages" value="1"> reinstall package list</label>
|
||||
<label><input type="checkbox" name="restore_overlay" value="1"> restore overlay snapshot</label>
|
||||
<label><input type="checkbox" name="flash_firmware" value="1"> flash firmware image and reboot</label>
|
||||
</div>
|
||||
<label>Type RESTORE</label>
|
||||
<input type="text" name="confirm" autocomplete="off">
|
||||
<button class="danger" type="submit">Run restore</button>
|
||||
</form>
|
||||
|
||||
<form class="panel span6" method="post" action="$(self_url)">
|
||||
<h2>Defaults</h2>
|
||||
<input type="hidden" name="key" value="$key">
|
||||
<input type="hidden" name="action" value="save_defaults">
|
||||
<label>Default output directory</label>
|
||||
<input type="text" name="default_output_dir" value="$(h "$output_dir")">
|
||||
<label>Keep days, 0 disables cleanup</label>
|
||||
<input type="number" min="0" name="keep_days" value="$(h "$keep_days")">
|
||||
<div class="checks">
|
||||
<label><input type="checkbox" name="default_include_overlay" value="1"$(checkbox_attr "$include_overlay")> include overlay by default</label>
|
||||
<label><input type="checkbox" name="default_include_rom" value="1"$(checkbox_attr "$include_rom")> include ROM by default</label>
|
||||
<label><input type="checkbox" name="default_include_raw_mtd" value="1"$(checkbox_attr "$include_raw_mtd")> include raw MTD by default</label>
|
||||
</div>
|
||||
<button type="submit">Save defaults</button>
|
||||
</form>
|
||||
|
||||
<div class="panel span6">
|
||||
<h2>Git install / remove</h2>
|
||||
<p>Clone install:</p>
|
||||
<pre>git clone $(h "$PROJECT_URL").git
|
||||
cd openwrt-full-backup
|
||||
sh install.sh</pre>
|
||||
<p>One-line install:</p>
|
||||
<pre>wget -O - $(h "$RAW_URL")/install.sh | sh</pre>
|
||||
<p>Remove:</p>
|
||||
<pre>wget -O - $(h "$RAW_URL")/uninstall.sh | sh</pre>
|
||||
</div>
|
||||
</section>
|
||||
</main>
|
||||
</body>
|
||||
</html>
|
||||
EOF
|
||||
}
|
||||
|
||||
read_request
|
||||
if ! authorized; then
|
||||
http_unauthorized
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if [ "$(param action)" = "download" ]; then
|
||||
download_file
|
||||
fi
|
||||
|
||||
if [ "${REQUEST_METHOD:-GET}" = "POST" ]; then
|
||||
handle_action
|
||||
fi
|
||||
|
||||
page
|
||||
Reference in new issue
Block a user