unlockf: Change install and uninstall scripts

This commit is contained in:
remittor
2026-02-21 20:25:29 +03:00
parent 04a789e0ef
commit 0e1bbb42cc
+87 -80
View File
@@ -52,6 +52,7 @@ DEF_FEATURES = {
"map_e": "1", "map_e": "1",
"dslite": "1", "dslite": "1",
"map_e_ocn": "1", "map_e_ocn": "1",
"cpe": "0", # def: 0 # CPE 3G/4G/5G modem
}, },
"wifi": { "wifi": {
"wifi24": "1", "wifi24": "1",
@@ -104,6 +105,7 @@ DEF_FEATURES = {
"game_port": "0", # def: 0 # misc.features.game # misc.wireless.wl_if_count=3 "game_port": "0", # def: 0 # misc.features.game # misc.wireless.wl_if_count=3
"lan_lag": "1", "lan_lag": "1",
"telnet": "0", "telnet": "0",
"wifi_optimize": "0",
}, },
"hardware": { "hardware": {
"usb": "0", "usb": "0",
@@ -170,45 +172,39 @@ with open(FN_lua, 'w', newline = '\n') as file:
unlockf_patch = '''#!/bin/sh unlockf_patch = '''#!/bin/sh
INST_FLAG_FN=/tmp/unlockf_patch.log INST_FLAG_FN=/tmp/unlockf_patch.log
[ -e "$INST_FLAG_FN" ] && return 0 [ -f $INST_FLAG_FN ] && return 0
[ -s $INST_FLAG_FN ] && return 0
DIR_PATCH=/etc/crontabs/patches : > $INST_FLAG_FN
DIR_BACKUP=$DIR_PATCH/unlockf_backup
STOR_DIR=/etc/crontabs/patches/unlockf
TARGET_DIR=/usr/lib/lua/xiaoqiang TARGET_DIR=/usr/lib/lua/xiaoqiang
MIRROR_DIR=/tmp/_usr_lib_lua_xiaoqiang TARGET_FN=XQFeatures.lua
SYNCOBJECT=$MIRROR_DIR.sync TARGET_FILENAME=$TARGET_DIR/$TARGET_FN
TARGET_STOR_ORIG=$STOR_DIR/$TARGET_FN.orig
TARGET_STOR_NEW=$STOR_DIR/$TARGET_FN
if [ ! -f $DIR_PATCH/XQFeatures.lua ; then if mount | grep -q " on $TARGET_FILENAME " ; then
return 0 return 1
fi fi
if [ ! -f $TARGET_FILENAME ]; then
for i in $(seq 1 45); do return 1
mkdir $SYNCOBJECT &> /dev/null && break
sleep 1
done
if ! mount | grep -q " on $TARGET_DIR" ; then
mkdir -p $MIRROR_DIR
cp -rf $TARGET_DIR/* $MIRROR_DIR/
mount --bind $MIRROR_DIR $TARGET_DIR
fi fi
if [ ! -f $TARGET_STOR_NEW ]; then
if [ ! -f $MIRROR_DIR/XQFeatures.lua ]; then return 1
rm -rf $SYNCOBJECT
return 1 # error
fi fi
if [ ! -f $TARGET_STOR_ORIG ]; then
# replace XQFeatures.lua cp -f $TARGET_FILENAME $TARGET_STOR_ORIG
cp -f $DIR_PATCH/XQFeatures.lua $MIRROR_DIR/XQFeatures.lua fi
mount --bind $TARGET_STOR_NEW $TARGET_FILENAME
rm -rf $SYNCOBJECT
### patch misc config ### ### patch misc config ###
uci set misc.features.xmir_unlockf=1 uci set misc.features.xmir_unlockf=1
uci commit misc uci commit misc
echo "unlockf enabled" > /tmp/unlockf_patch.log echo "unlockf enabled" > $INST_FLAG_FN
/etc/init.d/rpcd reload
''' '''
misc_patch = '' misc_patch = ''
for keyname, value in patched_features.items(): for keyname, value in patched_features.items():
@@ -227,57 +223,58 @@ with open(FN_patch, 'w', newline = '\n') as file:
unlockf_install = '''#!/bin/sh unlockf_install = '''#!/bin/sh
INST_FLAG_FN=/tmp/unlockf_patch.log INST_FLAG_FN=/tmp/unlockf_patch.log
DIR_PATCH=/etc/crontabs/patches STOR_DIR=/etc/crontabs/patches/unlockf
DIR_BACKUP=$DIR_PATCH/unlockf_backup
TARGET_DIR=/usr/lib/lua/xiaoqiang TARGET_DIR=/usr/lib/lua/xiaoqiang
MIRROR_DIR=/tmp/_usr_lib_lua_xiaoqiang TARGET_FN=XQFeatures.lua
SYNCOBJECT=$MIRROR_DIR.sync TARGET_FILENAME=$TARGET_DIR/$TARGET_FN
TARGET_STOR_ORIG=$STOR_DIR/$TARGET_FN.orig
TARGET_STOR_NEW=$STOR_DIR/$TARGET_FN
STOR_BACKUP_DIR=$STOR_DIR/backup
if [ ! -f /tmp/XQFeatures.lua ]; then if [ ! -f /tmp/$TARGET_FN ]; then
return 1 return 1
fi fi
if [ ! -d $STOR_DIR ]; then
if [ ! -d $DIR_PATCH ]; then mkdir -p $STOR_DIR
mkdir -p $DIR_PATCH chown root $STOR_DIR
chown root $DIR_PATCH chmod 0755 $STOR_DIR
chmod 0755 $DIR_PATCH
fi fi
CLEAN_INSTALL=0 FIRST_INSTALL=0
if [ ! -d $DIR_BACKUP ]; then if [ ! -d $STOR_BACKUP_DIR ]; then
CLEAN_INSTALL=1 FIRST_INSTALL=1
mkdir -p $DIR_BACKUP mkdir -p $STOR_BACKUP_DIR
if [ -f $DIR_BACKUP/misc ]; then [ -f /etc/config/misc ] && cp -f /etc/config/misc $STOR_BACKUP_DIR/misc
cp -f /etc/config/misc $DIR_BACKUP/misc
fi
fi fi
if [ $CLEAN_INSTALL = 1 ]; then if mount | grep -q " on $TARGET_DIR type tmpfs" ; then
NEED_RESTORE_MNT=0 umount -l $TARGET_DIR
if mount | grep -q " on $TARGET_DIR" ; then fi
umount -l $TARGET_DIR if mount | grep -q " on $TARGET_FILENAME " ; then
NEED_RESTORE_MNT=1 umount -l $TARGET_FILENAME
fi fi
if [ ! -f $DIR_BACKUP/XQFeatures.lua ]; then if [ ! -f $TARGET_STOR_ORIG ]; then
cp -f $TARGET_DIR/XQFeatures.lua $DIR_BACKUP/XQFeatures.lua cp -f $TARGET_FILENAME $TARGET_STOR_ORIG
fi fi
[ $NEED_RESTORE_MNT = 1 ] && mount --bind $MIRROR_DIR $TARGET_DIR mv -f /tmp/$TARGET_FN $TARGET_STOR_NEW
fi mv -f /tmp/unlockf_patch.sh $STOR_DIR/
chmod +x $STOR_DIR/unlockf_patch.sh
mv -f /tmp/XQFeatures.lua $DIR_PATCH/
mv -f /tmp/unlockf_patch.sh $DIR_PATCH/
chmod +x $DIR_PATCH/unlockf_patch.sh
FILE_CRON=/etc/crontabs/root
if [ -f $FILE_CRON ]; then
grep -v "/unlockf_patch.sh" $FILE_CRON > $FILE_CRON.new || echo "" > $FILE_CRON.new
echo "*/1 * * * * $STOR_DIR/unlockf_patch.sh >/dev/null 2>&1" >> $FILE_CRON.new
mv $FILE_CRON.new $FILE_CRON
fi
uci set firewall.auto_unlockf_patch=include uci set firewall.auto_unlockf_patch=include
uci set firewall.auto_unlockf_patch.type='script' uci set firewall.auto_unlockf_patch.type='script'
uci set firewall.auto_unlockf_patch.path="$DIR_PATCH/unlockf_patch.sh" uci set firewall.auto_unlockf_patch.path="$STOR_DIR/unlockf_patch.sh"
uci set firewall.auto_unlockf_patch.enabled='1' uci set firewall.auto_unlockf_patch.enabled='1'
uci commit firewall uci commit firewall
rm -f $INST_FLAG_FN rm -f $INST_FLAG_FN
# run patch # run patch
$DIR_PATCH/unlockf_patch.sh $STOR_DIR/unlockf_patch.sh
luci-reload luci-reload
rm -f /tmp/luci-indexcache rm -f /tmp/luci-indexcache
@@ -289,29 +286,39 @@ with open(FN_install, 'w', newline = '\n') as file:
unlockf_uninstall = '''#!/bin/sh unlockf_uninstall = '''#!/bin/sh
INST_FLAG_FN=/tmp/unlockf_patch.log INST_FLAG_FN=/tmp/unlockf_patch.log
DIR_PATCH=/etc/crontabs/patches STOR_DIR=/etc/crontabs/patches/unlockf
DIR_BACKUP=$DIR_PATCH/unlockf_backup
TARGET_DIR=/usr/lib/lua/xiaoqiang TARGET_DIR=/usr/lib/lua/xiaoqiang
MIRROR_DIR=/tmp/_usr_lib_lua_xiaoqiang TARGET_FN=XQFeatures.lua
SYNCOBJECT=$MIRROR_DIR.sync TARGET_FILENAME=$TARGET_DIR/$TARGET_FN
TARGET_STOR_ORIG=$STOR_DIR/$TARGET_FN.orig
TARGET_STOR_NEW=$STOR_DIR/$TARGET_FN
STOR_BACKUP_DIR=$STOR_DIR/backup
if [ -d $DIR_BACKUP ]; then if [ -d $STOR_BACKUP_DIR ]; then
if [ -d $MIRROR_DIR ]; then [ -s $STOR_BACKUP_DIR/misc ] && cp -f $STOR_BACKUP_DIR/misc /etc/config/misc
cp -f $DIR_BACKUP/XQFeatures.lua $MIRROR_DIR/XQFeatures.lua
fi
cp -f $DIR_BACKUP/misc /etc/config/misc
fi fi
FILE_CRON=/etc/crontabs/root
uci delete firewall.auto_unlockf_patch if grep -q '/unlockf_patch.sh' $FILE_CRON ; then
uci commit firewall grep -v "/unlockf_patch.sh" $FILE_CRON > $FILE_CRON.new
mv $FILE_CRON.new $FILE_CRON
rm -rf $DIR_BACKUP /etc/init.d/cron restart
rm -f $DIR_PATCH/unlockf_patch.sh fi
rm -f $DIR_PATCH/XQFeatures.lua if uci -q get firewall.auto_unlockf_patch ; then
uci delete firewall.auto_unlockf_patch
uci commit firewall
fi
if mount | grep -q " on $TARGET_DIR type tmpfs" ; then
umount -l $TARGET_DIR
fi
if mount | grep -q " on $TARGET_FILENAME " ; then
umount -l $TARGET_FILENAME
fi
rm -rf $STOR_BACKUP_DIR
rm -f $STOR_DIR/unlockf_patch.sh
rm -f $TARGET_STOR_NEW
rm -f $INST_FLAG_FN rm -f $INST_FLAG_FN
rm -rf $SYNCOBJECT
/etc/init.d/rpcd reload
luci-reload luci-reload
rm -f /tmp/luci-indexcache rm -f /tmp/luci-indexcache
luci-reload luci-reload