move common files out

This commit is contained in:
jjm2473 2022-05-12 20:02:54 +08:00
parent 44430b3868
commit a8a32bfc85
30 changed files with 399 additions and 180 deletions

View File

@ -12,7 +12,7 @@ include $(INCLUDE_DIR)/version.mk
include $(INCLUDE_DIR)/feeds.mk
PKG_NAME:=base-files
PKG_FLAGS:=nonshared
PKG_FLAGS:=hold essential nonshared
PKG_RELEASE:=$(COMMITCOUNT)
PKG_FILE_DEPENDS:=$(PLATFORM_DIR)/ $(GENERIC_PLATFORM_DIR)/base-files/
@ -37,7 +37,8 @@ endif
define Package/base-files
SECTION:=base
CATEGORY:=Base system
DEPENDS:=+netifd +libc +jsonfilter +SIGNED_PACKAGES:usign +SIGNED_PACKAGES:openwrt-keyring +NAND_SUPPORT:ubi-utils +fstools +fwtool
DEPENDS:=+netifd +libc +jsonfilter +SIGNED_PACKAGES:usign +SIGNED_PACKAGES:openwrt-keyring +NAND_SUPPORT:ubi-utils +fstools +fwtool \
blkid mount-utils e2fsprogs tune2fs resize2fs
TITLE:=Base filesystem for OpenWrt
URL:=http://openwrt.org/
VERSION:=$(PKG_RELEASE)-$(REVISION)
@ -181,6 +182,9 @@ define Package/base-files/install
chmod 0600 $(1)/etc/shadow
chmod 1777 $(1)/tmp
$(LN) /tmp/run $(1)/run
mkdir -p $(1)/ext_overlay
$(call ImageConfigOptions,$(1))
$(call Package/base-files/install-target,$(1))
for conffile in $(1)/etc/config/*; do \

View File

@ -0,0 +1,17 @@
. /lib/upgrade/common.sh
get_overlay_partition()
{
local overlay_dev
export_bootdevice && export_partdevice overlay_dev 3 || {
log "Unable to determine overlay partition"
return 1
}
if [ -z "$overlay_dev" ]; then
log "Unable to determine overlay partition"
return 1
fi
OVERLAY_DEV="/dev/$overlay_dev"
}

View File

@ -106,6 +106,19 @@ kill_remaining() { # [ <signal> [ <loop> ] ]
_v
}
istoreos_pre_upgrade() {
if [ -n "$UPGRADE_BACKUP" ]; then
# reset rom uuid in ext_overlay
if [ -e /ext_overlay/etc ]; then
rm -f /ext_overlay/etc/.extroot-uuid
rm -f /ext_overlay/upper/usr/lib/opkg/.upgrading
sync /ext_overlay
fi
rm -f /overlay/upper/usr/lib/opkg/.upgrading
touch /overlay/upper/usr/lib/opkg/.upgrading && sync /overlay
fi
}
indicate_upgrade
killall -9 telnetd
@ -123,6 +136,8 @@ sleep 1
echo 3 > /proc/sys/vm/drop_caches
[ -n "$IMAGE" ] && istoreos_pre_upgrade
if [ -n "$IMAGE" ] && type 'platform_pre_upgrade' >/dev/null 2>/dev/null; then
platform_pre_upgrade "$IMAGE"
fi

View File

@ -1,3 +1,86 @@
#!/bin/sh
# Copyright (C) 2022 jjm2473@gmail.com
/sbin/jffs2reset $@
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 || return 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 ! 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()
{
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
[ "$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

View File

@ -5,50 +5,47 @@
DEFAULT_OVERLAY_FS="ext4"
OVERLAY_LABEL="etc"
get_overlay_partition_from_kernel_cmdline()
OVERLAY_FS=${DEFAULT_OVERLAY_FS}
OVERLAY_DEV=
log() {
echo "<1>mount_root: $1" >/dev/kmsg
}
inlog() {
$@ >/dev/kmsg 2>&1
}
. /lib/functions/istoreos-boot.sh
validate_overlay_partition()
{
OVERLAY_FS=${DEFAULT_OVERLAY_FS}
for item in `cat /proc/cmdline`; do
case $item in
overlay=*) OVERLAY_DEV=${item:8};;
overlayfs=*) OVERLAY_FS=${item:10};;
esac
done
if [ -z "$OVERLAY_DEV" ]; then
OVERLAY_DEV=`blkid -L $OVERLAY_LABEL | grep /mmcblk0p`
[ -z "$OVERLAY_DEV" ] || echo "overlay dev not define by cmdline, fine $OVERLAY_LABEL got $OVERLAY_DEV"
fi
if [ -z "$OVERLAY_DEV" ]; then
if dd if=/dev/mmcblk0p2 bs=5 count=1 | grep -qF RESET; then
OVERLAY_DEV=/dev/mmcblk0p2
FSTYPE=RESET
echo "overlay not found by cmdline or label, we got resetting $OVERLAY_DEV"
fi
fi
[ -z "$OVERLAY_DEV" ] && return 1
echo "- mount overlayfs -"
log "- mount overlayfs -"
# Check device existence
[ ! -e $OVERLAY_DEV ] && \
echo "overlay: $OVERLAY_DEV not found" && return 1
[ ! -e "$OVERLAY_DEV" ] && \
log "overlay: $OVERLAY_DEV not found" && return 1
# Check filesystem
if [ -z "$FSTYPE" ]; then
if dd if=$OVERLAY_DEV bs=5 count=1 | grep -qF RESET; then
FSTYPE=RESET
else
FSTYPE=`blkid -o value -s TYPE $OVERLAY_DEV`
fi
[ -n "$FSTYPE" ] && return 0
# get filesystem
if dd if="$OVERLAY_DEV" bs=5 count=1 2>/dev/null | grep -qF RESET; then
FSTYPE=RESET
log "overlay: $OVERLAY_DEV marked as RESET, format later"
return 0
elif blkid -o device -t LABEL=$OVERLAY_LABEL "$OVERLAY_DEV" >/dev/null; then
FSTYPE=`blkid -o value -s TYPE $OVERLAY_DEV`
else
FSTYPE=RESET
log "overlay: $OVERLAY_DEV not labeled, format later"
return 0
fi
[ -z "$FSTYPE" ] && \
echo "overlay: no valid filesystem" || \
echo "overlay: filesystem $FSTYPE found"
if [ -z "$FSTYPE" ]; then
log "overlay: no valid filesystem"
else
log "overlay: filesystem $FSTYPE found"
fi
}
format_overlay_partition()
@ -56,22 +53,22 @@ format_overlay_partition()
local RET
[ "$FSTYPE" = "$OVERLAY_FS" ] && return 0
echo "overlay: try to format $OVERLAY_DEV as $OVERLAY_FS partition"
log "overlay: try to format $OVERLAY_DEV as $OVERLAY_FS partition"
case "$OVERLAY_FS" in
ext4)
mkfs.ext4 -q -j -FF -L $OVERLAY_LABEL $OVERLAY_DEV
mkfs.ext4 -q -j -FF -L $OVERLAY_LABEL "$OVERLAY_DEV"
RET=$?
[ $RET -ne 0 ] || tune2fs -o '^user_xattr,^acl' -r 1024 $OVERLAY_DEV
[ $RET -ne 0 ] || tune2fs -o '^user_xattr,^acl' -r 1024 "$OVERLAY_DEV"
;;
*)
echo "overlay: unhandled fs type : $OVERLAY_FS"
log "overlay: unhandled fs type : $OVERLAY_FS"
RET=1
;;
esac
if [ $RET -ne 0 ]; then
echo "overlay: format command failed ret: $RET"
log "overlay: format command failed ret: $RET"
else
echo 3 > /proc/sys/vm/drop_caches
FSTYPE=$OVERLAY_FS
@ -84,9 +81,9 @@ check_overlay_partition()
{
case "$FSTYPE" in
ext4)
fsck.ext4 -y $OVERLAY_DEV
fsck.ext4 -y "$OVERLAY_DEV"
sync
resize2fs $OVERLAY_DEV
resize2fs "$OVERLAY_DEV"
sync
;;
esac
@ -95,13 +92,13 @@ check_overlay_partition()
mount_overlay_partition()
{
local RET
mount -t $OVERLAY_FS $OVERLAY_DEV /overlay
mount -t $OVERLAY_FS "$OVERLAY_DEV" /overlay
RET=$?
[ $RET -ne 0 ] && \
echo "overlay: failed to mount $OVERLAY_DEV as $OVERLAY_FS partition ret: $RET" && return $RET
log "overlay: failed to mount $OVERLAY_DEV as $OVERLAY_FS partition ret: $RET" && return $RET
echo 'overlay: successfully mounted'
log 'overlay: successfully mounted'
}
prepare_primary_overlay()
@ -194,7 +191,7 @@ prepare_mnt()
if mountpoint -q /tmp/extroot/overlay; then
# use ext overlay as upper layer
local newoverlaydir=/tmp/extroot/overlay
if [ `mountpoint -x $OVERLAY_DEV` != `mountpoint -d $newoverlaydir` ] && \
if [ `mountpoint -x "$OVERLAY_DEV"` != `mountpoint -d $newoverlaydir` ] && \
prepare_ext_overlay $newoverlaydir $overlaydir && \
mount --move /tmp/extroot/overlay /ext_overlay; then
lowerdir=$overlaydir/upper:$lowerdir
@ -224,29 +221,31 @@ do_mount_overlayfs()
{
[ ! -e /rom/note ] && return 0
get_overlay_partition_from_kernel_cmdline || return 1
inlog get_overlay_partition || return 1
format_overlay_partition || return 1
inlog validate_overlay_partition || return 1
check_overlay_partition
inlog format_overlay_partition || return 1
mount_overlay_partition || return 1
inlog check_overlay_partition
inlog mount_overlay_partition || return 1
# if we are in recovery mode, just skip pivot_root
if [ -f /.recovery_mode ]; then
rm -f /rom/note
rm -f /rom/note >/dev/null 2>&1
return 0
fi
prepare_primary_overlay
inlog prepare_primary_overlay
prepare_mnt || return 1
inlog prepare_mnt || return 1
pivot_root_to_overlayfs || return 1
inlog pivot_root_to_overlayfs || return 1
clean_extroot >/dev/null 2>&1
mount --make-shared -t tmpfs -o size=4M tmpfs /mnt
inlog mount --make-shared -t tmpfs -o size=4M tmpfs /mnt
return 0
}

View File

@ -0,0 +1,75 @@
include $(TOPDIR)/rules.mk
PKG_NAME:=istoreos-files
PKG_VERSION:=1
PKG_RELEASE:=1
PKG_FLAGS:=hold essential nonshared
PKG_LICENSE:=CC0-1.0
PKG_MAINTAINER:=jjm2473 <jjm2473@gmail.com>
include $(INCLUDE_DIR)/package.mk
define Package/istoreos-files
SECTION:=base
CATEGORY:=Base system
TITLE:=iStoreOS files
MAINTAINER:=jjm2473 <jjm2473@gmail.com>
DEFAULT:=y
HIDDEN:=y
endef
define Package/istoreos-files/description
The iStoreOS.
endef
define Build/Prepare
mkdir -p $(PKG_BUILD_DIR)
endef
define Build/Compile/Default
endef
Build/Compile = $(Build/Compile/Default)
define Package/istoreos-files/install
$(CP) ./files/* $(1)/
endef
define Package/istoreos-files/postinst
#!/bin/sh
HOST_SED="$(subst ${STAGING_DIR_HOST},$${STAGING_DIR_HOST},$(SED))"
HOST_LN="$(subst ${STAGING_DIR_HOST},$${STAGING_DIR_HOST},$(LN))"
[ -n "$${IPKG_INSTROOT}" ] && {
$${HOST_SED} '/^src\/gz openwrt_\(base\|luci\|packages\|routing\|telephony\) /!d' "$${IPKG_INSTROOT}/etc/opkg/distfeeds.conf"
$${HOST_SED} 's/"192.168.1.1"/"192.168.100.1"/' \
"$${IPKG_INSTROOT}/usr/lib/lua/luci/controller/admin/system.lua" \
"$${IPKG_INSTROOT}/usr/lib/lua/luci/controller/admin/ota.lua" \
"$${IPKG_INSTROOT}/etc/board.d/99-default_network"
$${HOST_SED} "s/'192\\.168\\.1\\.1'/'192.168.100.1'/; s/'openwrt\\.lan'/window.location.host/" "$${IPKG_INSTROOT}/www/luci-static/resources/view/system/flash.js"
$${HOST_SED} 's/s\.anonymous = true/s\.anonymous = true\ns\.addremove = true/' "$${IPKG_INSTROOT}/usr/lib/lua/luci/model/cbi/hd_idle.lua"
$${HOST_SED} 's#"/opt"#"/overlay/upper/opt/docker"#' "$${IPKG_INSTROOT}/usr/lib/lua/luci/model/cbi/admin_system/fstab/mount.lua"
$${HOST_LN} /usr/sbin/jffs2reset "$${IPKG_INSTROOT}/sbin/jffs2reset"
$${HOST_SED} '/<link rel="shortcut icon" href="<%=media%>\/favicon.ico">/a <link rel="stylesheet" href="<%=resource%>/easepi/easeicon.css?t=1649313193968">' \
"$${IPKG_INSTROOT}/usr/lib/lua/luci/view/themes/argon/header.htm" \
"$${IPKG_INSTROOT}/usr/lib/lua/luci/view/themes/argon_dark/header.htm" \
"$${IPKG_INSTROOT}/usr/lib/lua/luci/view/themes/argon_light/header.htm" \
"$${IPKG_INSTROOT}/usr/lib/lua/luci/view/themes/argon_dark_purple/header.htm" \
"$${IPKG_INSTROOT}/usr/lib/lua/luci/view/themes/argon_light_green/header.htm"
rm -f "$${IPKG_INSTROOT}/etc/uci-defaults/luci-argon-config"
true
}
endef
$(eval $(call BuildPackage,istoreos-files))

View File

@ -0,0 +1,16 @@
#!/bin/sh
#
# Copyright (C) 2018 OpenWrt.org
#
. /lib/functions/uci-defaults.sh
board_config_update
ucidef_set_hostname "iStoreOS"
ucidef_set_ntpserver "0.cn.pool.ntp.org" "1.cn.pool.ntp.org" "2.cn.pool.ntp.org" "3.cn.pool.ntp.org"
board_config_flush
exit 0

View File

@ -0,0 +1,22 @@
#!/bin/sh /etc/rc.common
# Copyright (C) 2016 OpenWrt.org
START=49
list_langs() {
cd /usr/lib/lua/luci/i18n
ls | sed -e 's/.*\.\([^\.]*\)\.lmo/\1/g' | sort -u
}
boot() {
local lang
local name
for lang in `list_langs`
do
if ! uci get luci.languages.${lang//-/_} >/dev/null 2>&1; then
name=`luci18n2name $lang`
uci set "luci.languages.${lang//-/_}=${name:-$lang}"
fi
done
uci changes luci | grep -Fqm1 luci 2>/dev/null && uci commit luci >/dev/null 2>&1
}

View File

@ -1,5 +1,6 @@
#!/bin/sh /etc/rc.common
# Copyright (C) 2016 OpenWrt.org
# istoreos upgrade post process
# Copyright (C) 2022 jjm2473
START=14

View File

@ -0,0 +1,9 @@
#!/bin/sh /etc/rc.common
# 2022 jjm2473
START=99
boot() {
# tune printk level after success boot, avoid noise in console
echo '4 5 1 7' > /proc/sys/kernel/printk
}

View File

@ -1,12 +1,9 @@
#!/bin/sh
# Copyright (C) 2022 jjm2473
uci -q batch <<-EOF >/dev/null
set system.@system[-1].zonename='Asia/Shanghai'
set system.@system[-1].timezone='CST-8'
add_list system.ntp.server='0.cn.pool.ntp.org'
add_list system.ntp.server='1.cn.pool.ntp.org'
add_list system.ntp.server='2.cn.pool.ntp.org'
add_list system.ntp.server='3.cn.pool.ntp.org'
commit system
EOF

View File

@ -0,0 +1,45 @@
#!/bin/sh
# author: jjm2473
toname() {
local lang_ar="العربية (Arabic)"
local lang_bg="български (Bulgarian)"
local lang_bn="বাংলা (Bengali)"
local lang_ca="Català (Catalan)"
local lang_cs="Čeština (Czech)"
local lang_da="Dansk (Danish)"
local lang_de="Deutsch (German)"
local lang_el="Ελληνικά (Greek)"
local lang_en="English"
local lang_es="Español (Spanish)"
local lang_fi="Suomi (Finnish)"
local lang_fr="Français (French)"
local lang_he="עִבְרִית (Hebrew)"
local lang_hi="हिंदी (Hindi)"
local lang_hu="Magyar (Hungarian)"
local lang_it="Italiano (Italian)"
local lang_ja="日本語 (Japanese)"
local lang_ko="한국어 (Korean)"
local lang_mr="Marāṭhī (Marathi)"
local lang_ms="Bahasa Melayu (Malay)"
local lang_no="Norsk (Norwegian)"
local lang_nl="Nederlands (Dutch)"
local lang_pl="Polski (Polish)"
local lang_pt_br="Português do Brasil (Brazilian Portuguese)"
local lang_pt="Português (Portuguese)"
local lang_ro="Română (Romanian)"
local lang_ru="Русский (Russian)"
local lang_sk="Slovenčina (Slovak)"
local lang_sv="Svenska (Swedish)"
local lang_tr="Türkçe (Turkish)"
local lang_uk="Українська (Ukrainian)"
local lang_vi="Tiếng Việt (Vietnamese)"
local lang_zh_cn="简体中文 (Chinese Simplified)"
local lang_zh_tw="繁體中文 (Chinese Traditional)"
eval "[ -n \"\${lang_$1}\" ] && echo \${lang_$1}"
}
if [ -n "$1" ]; then
toname ${1//-/_}
fi

View File

@ -0,0 +1,10 @@
-- Copyright 2022 jjm2473 <jjm2473@gmail.com>
-- Licensed to the public under the Apache License 2.0.
module("luci.controller.admin.compat", package.seeall)
function action_fatab()
local dsp = require "luci.dispatcher"
luci.http.redirect(dsp.build_url("admin/system/mounts"))
end

View File

@ -0,0 +1,9 @@
{
"admin/system/fstab": {
"action": {
"type": "call",
"module": "luci.controller.admin.compat",
"function": "action_fatab"
}
}
}

View File

@ -1,41 +1,4 @@
define Package/base-files/install-target
chmod 0400 $(1)/etc/public.key
$(LN) /tmp/run $(1)/run
$(INSTALL_DIR) $(1)/ext_overlay
endef
define Package/base-files/postinst
#!/bin/sh
HOST_SED="$(subst ${STAGING_DIR_HOST},$${STAGING_DIR_HOST},$(SED))"
HOST_LN="$(subst ${STAGING_DIR_HOST},$${STAGING_DIR_HOST},$(LN))"
[ -n "$${IPKG_INSTROOT}" ] && {
$${HOST_SED} '/^src\/gz openwrt_\(base\|luci\|packages\|routing\|telephony\) /!d' "$${IPKG_INSTROOT}/etc/opkg/distfeeds.conf"
$${HOST_SED} 's/"192.168.1.1"/"192.168.100.1"/' \
"$${IPKG_INSTROOT}/usr/lib/lua/luci/controller/admin/system.lua" \
"$${IPKG_INSTROOT}/usr/lib/lua/luci/controller/admin/ota.lua" \
"$${IPKG_INSTROOT}/etc/board.d/99-default_network"
$${HOST_SED} "s/'192\\.168\\.1\\.1'/'192.168.100.1'/; s/'openwrt\\.lan'/window.location.host/" "$${IPKG_INSTROOT}/www/luci-static/resources/view/system/flash.js"
$${HOST_SED} 's/s\.anonymous = true/s\.anonymous = true\ns\.addremove = true/' "$${IPKG_INSTROOT}/usr/lib/lua/luci/model/cbi/hd_idle.lua"
$${HOST_SED} 's#"/opt"#"/overlay/upper/opt/docker"#' "$${IPKG_INSTROOT}/usr/lib/lua/luci/model/cbi/admin_system/fstab/mount.lua"
$${HOST_LN} /usr/sbin/jffs2reset "$${IPKG_INSTROOT}/sbin/jffs2reset"
$${HOST_SED} '/<link rel="shortcut icon" href="<%=media%>\/favicon.ico">/a <link rel="stylesheet" href="<%=resource%>/easepi/easeicon.css?t=1649313193968">' \
"$${IPKG_INSTROOT}/usr/lib/lua/luci/view/themes/argon/header.htm" \
"$${IPKG_INSTROOT}/usr/lib/lua/luci/view/themes/argon_dark/header.htm" \
"$${IPKG_INSTROOT}/usr/lib/lua/luci/view/themes/argon_light/header.htm" \
"$${IPKG_INSTROOT}/usr/lib/lua/luci/view/themes/argon_dark_purple/header.htm" \
"$${IPKG_INSTROOT}/usr/lib/lua/luci/view/themes/argon_light_green/header.htm"
rm -f "$${IPKG_INSTROOT}/etc/uci-defaults/luci-argon-config"
true
}
endef

View File

@ -0,0 +1,31 @@
get_overlay_partition()
{
for item in `cat /proc/cmdline`; do
case $item in
overlay=*) OVERLAY_DEV=${item:8};;
overlayfs=*) OVERLAY_FS=${item:10};;
esac
done
if [ -z "$OVERLAY_DEV" ]; then
OVERLAY_DEV=`blkid -L $OVERLAY_LABEL | grep /mmcblk0p`
[ -z "$OVERLAY_DEV" ] || log "overlay dev not define by cmdline, fine $OVERLAY_LABEL got $OVERLAY_DEV"
fi
if [ -z "$OVERLAY_DEV" ]; then
if dd if=/dev/mmcblk0p2 bs=5 count=1 2>/dev/null | grep -qF RESET; then
OVERLAY_DEV=/dev/mmcblk0p2
FSTYPE=RESET
log "overlay not found by cmdline or label, but we found $OVERLAY_DEV marked as RESET, format later"
fi
fi
if [ -z "$OVERLAY_DEV" ]; then
log "Unable to determine overlay partition"
return 1
fi
return 0
}

View File

@ -12,18 +12,6 @@ platform_check_image() {
return 0
}
platform_pre_upgrade() {
if [ -n "$UPGRADE_BACKUP" ]; then
if [ -e /ext_overlay/etc ]; then
rm -f /ext_overlay/etc/.extroot-uuid
rm -f /ext_overlay/upper/usr/lib/opkg/.upgrading
sync /ext_overlay
fi
rm -f /overlay/upper/usr/lib/opkg/.upgrading
touch /overlay/upper/usr/lib/opkg/.upgrading && sync /overlay
fi
}
platform_do_upgrade() {
grep /ext_overlay /proc/mounts > /dev/null && {
/bin/mount -o noatime,remount,ro /ext_overlay

View File

@ -1,65 +0,0 @@
#!/bin/sh
OVERLAY_LABEL="etc"
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()
{
local OVERLAY_DEV=
for item in `cat /proc/cmdline`; do
case $item in
overlay=*) OVERLAY_DEV=${item:8};;
esac
done
if [ -z "$OVERLAY_DEV" ]; then
OVERLAY_DEV=`blkid -L $OVERLAY_LABEL | grep /mmcblk0p`
fi
if [ -z "$OVERLAY_DEV" ]; then
echo "overlay not found by cmdline or label, maybe we are already in resetting?" >&2
return 0
fi
echo "RESET000" | dd of=$OVERLAY_DEV bs=512 count=1 conv=notrunc
echo 3 > /proc/sys/vm/drop_caches
return 0
}
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
if touch /overlay/.reset; then
sync /overlay
else
do_reset_nofs
fi
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