🎈 Sync 2026-08-24 18:23:48

This commit is contained in:
github-actions[bot]
2026-08-24 18:23:48 +08:00
parent 91bee6a90e
commit 6b8877f5e1
119 changed files with 2501 additions and 2677 deletions
@@ -0,0 +1,98 @@
#!/bin/sh
# Copyright (C) 2022 jjm2473@gmail.com
DEFAULT_OVERLAY_FS="ext4"
OVERLAY_LABEL="etc"
OVERLAY_FS=${DEFAULT_OVERLAY_FS}
OVERLAY_DEV=
log() {
echo "$1" >&2
}
inlog() {
$@ >&2
}
. /lib/functions/istoreos-boot.sh
CONFIRM=n
REBOOT=n
confirm()
{
[ "$1" = "y" ] && return 0
echo "This will erase all settings and remove any installed packages. Are you sure? [N/y]"
read CONFIRM
[ "$CONFIRM" = "y" -o "$CONFIRM" = "Y" ] && return 0
return 1
}
do_reset_nofs()
{
get_overlay_partition || exit 1
if [ -z "$OVERLAY_DEV" ]; then
echo "Unable to determine overlay partition" >&2
return 1
fi
if [ "RESET" = "$FSTYPE" ]; then
echo "Already resetted" >&2
return 1
fi
if [ "DIR" = "$FSTYPE" ]; then
touch /$OVERLAY_DEV/.reset
sync /$OVERLAY_DEV
return 0
fi
# if ! blkid -o device -t LABEL=$OVERLAY_LABEL "$OVERLAY_DEV" >/dev/null; then
# echo "Overlay partition $OVERLAY_DEV not labeled $OVERLAY_LABEL" >&2
# return 1
# fi
echo "RESET000" | dd of="$OVERLAY_DEV" bs=512 count=1 conv=notrunc,sync,fsync 2>/dev/null
echo 3 > /proc/sys/vm/drop_caches
return 0
}
do_reset_ext_overlay()
{
[ -d /ext_overlay ] && mountpoint -q /ext_overlay || return 0
rm -f /ext_overlay/etc/.extroot-uuid
touch /ext_overlay/.reset
sync /ext_overlay
}
do_reset()
{
if [ -f /.recovery_mode ]; then
mount_root || ( echo "/overlay mount failed!" ; exit 1 )
rm -rf /overlay/upper
mkdir /overlay/upper
sync /overlay
else
do_reset_nofs
do_reset_ext_overlay
fi
if [ -f /lib/upgrade/keep.d/grub ]; then
cat /lib/upgrade/keep.d/grub | while read; do
rm -f "$REPLY"
done
fi
[ "$REBOOT" = "y" ] && reboot
exit 0
}
while [[ $# -gt 0 ]]; do
key="$1"
case $key in
-y) CONFIRM=y ;;
-r) REBOOT=y ;;
esac
shift
done
confirm $CONFIRM && do_reset
exit 0
@@ -1,98 +1,3 @@
#!/bin/sh
# Copyright (C) 2022 jjm2473@gmail.com
DEFAULT_OVERLAY_FS="ext4"
OVERLAY_LABEL="etc"
OVERLAY_FS=${DEFAULT_OVERLAY_FS}
OVERLAY_DEV=
log() {
echo "$1" >&2
}
inlog() {
$@ >&2
}
. /lib/functions/istoreos-boot.sh
CONFIRM=n
REBOOT=n
confirm()
{
[ "$1" = "y" ] && return 0
echo "This will erase all settings and remove any installed packages. Are you sure? [N/y]"
read CONFIRM
[ "$CONFIRM" = "y" -o "$CONFIRM" = "Y" ] && return 0
return 1
}
do_reset_nofs()
{
get_overlay_partition || exit 1
if [ -z "$OVERLAY_DEV" ]; then
echo "Unable to determine overlay partition" >&2
return 1
fi
if [ "RESET" = "$FSTYPE" ]; then
echo "Already resetted" >&2
return 1
fi
if [ "DIR" = "$FSTYPE" ]; then
touch /$OVERLAY_DEV/.reset
sync /$OVERLAY_DEV
return 0
fi
# if ! blkid -o device -t LABEL=$OVERLAY_LABEL "$OVERLAY_DEV" >/dev/null; then
# echo "Overlay partition $OVERLAY_DEV not labeled $OVERLAY_LABEL" >&2
# return 1
# fi
echo "RESET000" | dd of="$OVERLAY_DEV" bs=512 count=1 conv=notrunc,sync,fsync 2>/dev/null
echo 3 > /proc/sys/vm/drop_caches
return 0
}
do_reset_ext_overlay()
{
[ -d /ext_overlay ] && mountpoint -q /ext_overlay || return 0
rm -f /ext_overlay/etc/.extroot-uuid
touch /ext_overlay/.reset
sync /ext_overlay
}
do_reset()
{
if [ -f /.recovery_mode ]; then
mount_root || ( echo "/overlay mount failed!" ; exit 1 )
rm -rf /overlay/upper
mkdir /overlay/upper
sync /overlay
else
do_reset_nofs
do_reset_ext_overlay
fi
if [ -f /lib/upgrade/keep.d/grub ]; then
cat /lib/upgrade/keep.d/grub | while read; do
rm -f "$REPLY"
done
fi
[ "$REBOOT" = "y" ] && reboot
exit 0
}
while [[ $# -gt 0 ]]; do
key="$1"
case $key in
-y) CONFIRM=y ;;
-r) REBOOT=y ;;
esac
shift
done
confirm $CONFIRM && do_reset
exit 0
/sbin/factoryreset $@
@@ -8,6 +8,13 @@ OVERLAY_LABEL="etc"
OVERLAY_FS=${DEFAULT_OVERLAY_FS}
OVERLAY_DEV=
APK=false
PKG_BASE=usr/lib/opkg/info
[ -s /etc/apk/arch ] && {
APK=true
PKG_BASE=lib/apk/packages
}
log() {
echo "<1>mount_root: $1" >/dev/kmsg
}
@@ -136,6 +143,28 @@ update_overlay_lower_uuid() {
return 1
}
OPENWRT_RELEASE=""
openwrt_release() {
if [ -z "$OPENWRT_RELEASE" ]; then
OPENWRT_RELEASE=`grep 'DISTRIB_RELEASE=' /etc/openwrt_release 2>/dev/null | sed -E "s/.*='(.+)'.*/\1/"`
[ -z "$OPENWRT_RELEASE" ] && OPENWRT_RELEASE="UNKNOWN"
fi
echo "$OPENWRT_RELEASE"
}
update_overlay_lower_release() {
local realrelease=`openwrt_release`
local lastrelease="NULL"
if [ -f "$1/.rootfs-release" ]; then
lastrelease=`cat "$1/.rootfs-release"`
fi
if [ "$realrelease" != "$lastrelease" ]; then
echo "$realrelease" >"$1/.rootfs-release"
return 0
fi
return 1
}
clean_overlayfs_origin() {
local line
cd "$1"
@@ -172,11 +201,11 @@ clean_overlayfs_redundant_whiteout_marker()
clean_overlayfs_redundant_whiteout_marker_luci()
{
local line
[ -d "$1/upper/usr/lib/lua/luci" ] || return 0
cd "$1/upper/usr/lib/lua"
find luci -xdev -type c -perm 0 -user 0 -group 0 | while read; do
[ -d "$1/upper/usr/lib/lua/luci" ] || [ -d "$1/upper/usr/share/luci/menu.d" ] || return 0
cd "$1/upper"
find usr/lib/lua/luci usr/share/luci/menu.d -xdev -type c -perm 0 -user 0 -group 0 | while read; do
line="$REPLY"
[ ! -e "/usr/lib/lua/$line" -a \( -z "$2" -o ! -e "$2/upper/usr/lib/lua/$line" \) ] && \
[ ! -e "/$line" -a \( -z "$2" -o ! -e "$2/upper/$line" \) ] && \
rm -f "$line"
done
cd - >/dev/null 2>&1
@@ -193,28 +222,38 @@ clean_os_version_files()
nonconf_files_of_pkg() {
local pkgname="$1"
if [ -s /usr/lib/opkg/info/${pkgname}.conffiles ]; then
grep -hvxFf /usr/lib/opkg/info/${pkgname}.conffiles \
/usr/lib/opkg/info/${pkgname}.list
if [ -s /$PKG_BASE/${pkgname}.conffiles ]; then
grep -hvxFf /$PKG_BASE/${pkgname}.conffiles \
/$PKG_BASE/${pkgname}.list
else
cat /usr/lib/opkg/info/${pkgname}.list
cat /$PKG_BASE/${pkgname}.list
fi
}
_pkg_exists() {
local pkgname="$1"
if $APK; then
[ -f "/$PKG_BASE/${pkgname}.list" ] && return 0
else
[ -f "/$PKG_BASE/${pkgname}.control" ] && return 0
fi
return 1
}
clean_pkg_content() {
local overlay="$1"
local pkgname="$2"
local line
if [ -f /usr/lib/opkg/info/${pkgname}.control ]; then
if [ -f /usr/lib/opkg/info/${pkgname}.list ]; then
if _pkg_exists ${pkgname} ; then
if [ -f /$PKG_BASE/${pkgname}.list ]; then
nonconf_files_of_pkg "${pkgname}" | grep -v '^/etc/uci-defaults/' | while read; do
line="$REPLY"
rm -f "$overlay/upper/${line}"
done
rm -f $overlay/upper/usr/lib/opkg/info/${pkgname}.list
rm -f "$overlay/upper/$PKG_BASE/${pkgname}.list"
fi
rm -f $overlay/upper/usr/lib/opkg/info/${pkgname}.*
rm -f "$overlay/upper/$PKG_BASE/${pkgname}.*"
fi
}
@@ -225,10 +264,17 @@ pkg_depends_rec() {
local deps
echo "${pkgname}" | grep -q '^kmod-' && return
_pkg_exists ${pkgname} && [ ! -f /tmp/reset_core_packages/${pkgname} ] || return
touch /tmp/reset_core_packages/${pkgname}
if [ -f /usr/lib/opkg/info/${pkgname}.control -a ! -f /tmp/reset_core_packages/${pkgname} ]; then
if $APK; then
deps=`apk info --installed --recursive -R "${pkgname}" | grep -v 'depends on:' | grep . | sort -u`
for dep in $deps ; do
dep=${dep%%[@=<>~]*}
[ -f /tmp/reset_core_packages/${dep} ] || echo "${dep}" | grep -q '^kmod-' || touch /tmp/reset_core_packages/${dep}
done
else
deps=`grep '^Depends: ' /usr/lib/opkg/info/${pkgname}.control | sed -e 's/^Depends: //' -e 's/ ([^)]*)//g' -e 's/,/ /g'`
touch /tmp/reset_core_packages/${pkgname}
for dep in $deps ; do
pkg_depends_rec "$dep"
done
@@ -254,8 +300,7 @@ list_core_packages()
reset_core_packages()
{
local overlay="$1"
local running_ver=$(grep 'DISTRIB_RELEASE=' /etc/openwrt_release 2>/dev/null | sed -E "s/.*='(.+)'.*/\1/")
[ "v$(cat "$overlay/.upgrading" 2>/dev/null)" = "v$running_ver" ] && return
update_overlay_lower_release "$overlay" || return
local pkg
[ -d /tmp/reset_core_packages ] || list_core_packages
echo "Reset packages in $overlay: `ls /tmp/reset_core_packages/ | xargs echo`" | dd bs=960 2>/dev/null
@@ -267,6 +312,8 @@ reset_core_packages()
clean_kmods()
{
# apk system will clean kmods on isos_upgrade
$APK && return 0
local DUMMY_VERSION=0.0.0-r1
if [ -d "$1/upper/usr/lib/opkg/info" ]; then
local compat=`grep -m1 '^Version: ' /usr/lib/opkg/info/kernel.control | sed 's/^Version: //'`
@@ -320,13 +367,17 @@ prepare_primary_overlay()
prepare_primary_overlay_after_merge()
{
local upgrading=false
update_overlay_lower_uuid /overlay && upgrading=true
if [ -d /overlay/upper ]; then
if update_overlay_lower_uuid /overlay || [ -f /overlay/.upgrading ] ; then
if $upgrading ; then
clean_os_version_files /overlay
reset_core_packages /overlay
touch /overlay/.upgrading
mkdir -p /overlay/upper/etc/uci-defaults
rm -f /overlay/upper/etc/uci-defaults/.upgrading
touch /overlay/upper/etc/uci-defaults/.upgrading
fi
if [ -f /overlay/.upgrading -o -f /overlay/.merged ] ; then
if $upgrading || [ -f /overlay/.merged ] ; then
if is_overlayfs_use_xattr ; then
clean_overlayfs_origin /overlay/upper
clean_overlayfs_redundant_opaque /overlay/upper
@@ -336,13 +387,13 @@ prepare_primary_overlay_after_merge()
clean_overlayfs_redundant_whiteout_marker_luci /overlay
fi
else
update_overlay_lower_uuid /overlay
update_overlay_lower_release "/overlay"
fi
if [ -f /overlay/upper/usr/lib/opkg/.upgrading ]; then
if [ -f /overlay/upper/etc/uci-defaults/.upgrading ]; then
clean_kmods /overlay
fi
rm -f /overlay/.upgrading /overlay/.merged
rm -f /overlay/.merged
mkdir -p /overlay/upper /overlay/work
}
@@ -393,10 +444,13 @@ prepare_ext_overlay()
{
local newoverlaydir=$1
local overlaydir=$2
local upgrading=false
update_overlay_lower_uuid "$newoverlaydir" && upgrading=true
if [ -f "$newoverlaydir/.reset" ]; then
rm -rf "$newoverlaydir/upper"
rm -f "$newoverlaydir/.commit" "$newoverlaydir/.reset"
update_overlay_lower_release "$newoverlaydir"
elif [ -f "$newoverlaydir/.commit" ]; then
if [ -d "$newoverlaydir/upper" ]; then
apply_overlayfs_opaque "$newoverlaydir" "$overlaydir"
@@ -406,28 +460,35 @@ prepare_ext_overlay()
rmdir "$overlaydir/upper/ext_overlay"
rm -rf "$newoverlaydir/upper"
mkdir -m 0755 -p "$newoverlaydir/upper/ext_overlay"
rm -f "$overlaydir/upper/etc/uci-defaults/.upgrading" "$overlaydir/.rootfs-uuid" "$overlaydir/.rootfs-release"
update_overlay_lower_release "$newoverlaydir"
}
rm -f "$newoverlaydir/.commit"
else
prepare_primary_overlay_after_merge
touch "$overlaydir/.clean"
if [ -f "$newoverlaydir/upper/usr/lib/opkg/.upgrading" ]; then
clean_kmods "$newoverlaydir"
fi
if [ -f "$newoverlaydir/.upgrading" ]; then
clean_os_version_files "$newoverlaydir"
reset_core_packages "$newoverlaydir"
is_overlayfs_use_xattr && clean_overlayfs_origin "$newoverlaydir/upper"
fi
if [ -d "$newoverlaydir/upper" -a \( -f "$newoverlaydir/upper/usr/lib/opkg/.upgrading" -o ! -f "$overlaydir/.sandbox" \) ]; then
clean_overlayfs_redundant_whiteout_marker "$newoverlaydir" "$overlaydir"
if [ -d "$newoverlaydir/upper" ]; then
if $upgrading; then
clean_kmods "$newoverlaydir"
clean_os_version_files "$newoverlaydir"
reset_core_packages "$newoverlaydir"
mkdir -p "$newoverlaydir/upper/etc/uci-defaults"
rm -f "$newoverlaydir/upper/etc/uci-defaults/.upgrading"
touch "$newoverlaydir/upper/etc/uci-defaults/.upgrading"
is_overlayfs_use_xattr && clean_overlayfs_origin "$newoverlaydir/upper"
elif [ -c "$newoverlaydir/upper/etc/uci-defaults/.upgrading" -a ! -f "$overlaydir/upper/etc/uci-defaults/.upgrading" ]; then
rm -f "$newoverlaydir/upper/etc/uci-defaults/.upgrading"
fi
if $upgrading || [ ! -f "$overlaydir/.sandbox" ]; then
clean_overlayfs_redundant_whiteout_marker "$newoverlaydir" "$overlaydir"
else
clean_overlayfs_redundant_whiteout_marker_luci "$newoverlaydir" "$overlaydir"
fi
else
clean_overlayfs_redundant_whiteout_marker_luci "$newoverlaydir" "$overlaydir"
update_overlay_lower_release "$newoverlaydir"
fi
fi
rm -f "$newoverlaydir/.upgrading"
( mkdir -m 0755 -p $newoverlaydir/upper/ext_overlay && \
mkdir -m 0755 -p $newoverlaydir/work ) || return 1
@@ -23,6 +23,7 @@ for file in \
/lib/board \
/sbin/ujail \
/usr/lib/opkg/info/luci-app-oaf.control \
/lib/apk/packages/luci-app-oaf.list \
/usr/libexec/fan-control \
/usr/sbin/sandbox
do
@@ -117,6 +117,7 @@ sh -c 'mount --bind /tmp/proconly.txt /proc/$$/mounts && exec mount -o rw,remoun
rm -f /tmp/proconly.txt
# Apk system means that openwrt version is newer than 24.10, there is not such issue on newer openwrt version, so we just check opkg system.
PROCD_VER=`grep -o '^Version: [0-9]*' /rom/usr/lib/opkg/info/procd.control | cut -d' ' -f2`
if [ -n "$PROCD_VER" -a "$PROCD_VER" -lt 2024 ]; then
# workaround procd < 2024 infite loop on resolving rootfs type, e.g. `ubus call system board`