Adapt lang_patch.sh for newest routers

This commit is contained in:
remittor
2022-09-17 16:47:04 +03:00
parent e74eb9569c
commit af9bd42e0b
4 changed files with 100 additions and 42 deletions
+52 -33
View File
@@ -1,55 +1,74 @@
#!/bin/sh
DIR_PATCH=/etc/crontabs/patches
if [ `ls /tmp/base.*.lmo |wc -l` -eq 0 ]; then if [ `ls /tmp/base.*.lmo |wc -l` -eq 0 ]; then
return 1 return 1
fi fi
if [ "$(mount| grep '/usr/lib/lua/luci')" != "" ]; then if [ "$(mount| grep '/usr/lib/lua/luci')" != "" ]; then
sh /tmp/lang_uninstall.sh if [ -e "/tmp/lang_uninstall.sh" ]; then
sh /tmp/lang_uninstall.sh
fi
fi fi
# delete old patch # delete old patch
rm -f /etc/rc.lang rm -f /etc/rc.lang
rm -f /etc/lang_patch.sh
# global firmware may contain a file "base.en.lmo" # global firmware may contain a file "base.en.lmo"
[ -f /usr/lib/lua/luci/i18n/base.en.lmo ] && rm -f /tmp/base.en.lmo [ -f /usr/lib/lua/luci/i18n/base.en.lmo ] && rm -f /tmp/base.en.lmo
mv -f /tmp/base.*.lmo /etc/ if [ ! -d $DIR_PATCH ]; then
mv -f /tmp/lang_patch.sh /etc/ mkdir $DIR_PATCH
chmod +x /etc/lang_patch.sh chown root $DIR_PATCH
chmod 0755 $DIR_PATCH
fi
FILE_FOR_EDIT=/etc/init.d/boot mv -f /tmp/base.*.lmo $DIR_PATCH/
NEW_CMD="\[ -f \/etc\/lang_patch.sh \] && sh \/etc\/lang_patch.sh" mv -f /tmp/lang_patch.sh $DIR_PATCH/
FILE_PATCHED=1 chmod +x $DIR_PATCH/lang_patch.sh
HAVE_PATCH=$(grep 'lang_patch.sh' $FILE_FOR_EDIT)
if [ -z "$HAVE_PATCH" ]; then INSTALL_METHOD=1
FILE_PATCHED=0 if [ -e "/usr/lib/os-release" ]; then
UCI_CFG=$(grep 'apply_uci_config' $FILE_FOR_EDIT) INSTALL_METHOD=2
if [ -n "$UCI_CFG" ]; then fi
sed -i "/apply_uci_config$/i$NEW_CMD" $FILE_FOR_EDIT
FILE_PATCHED=2 FILE_PATCHED=0
fi
UCI_DEF=$(grep 'uci_apply_defaults' $FILE_FOR_EDIT) if [ $INSTALL_METHOD == 1 ]; then
if [ -n "$UCI_DEF" -a $FILE_PATCHED == 0 ]; then FILE_PATCHED=1
sed -i "/uci_apply_defaults$/i$NEW_CMD" $FILE_FOR_EDIT FILE_FOR_EDIT=/etc/init.d/boot
FILE_PATCHED=3 NEW_CMD="\[ -f \/etc\/crontabs\/patches\/lang_patch.sh \] && sh \/etc\/crontabs\/patches\/lang_patch.sh"
HAVE_PATCH=$(grep '/lang_patch.sh' $FILE_FOR_EDIT)
if [ -z "$HAVE_PATCH" ]; then
FILE_PATCHED=0
UCI_CFG=$(grep 'apply_uci_config' $FILE_FOR_EDIT)
if [ -n "$UCI_CFG" ]; then
sed -i "/apply_uci_config$/i$NEW_CMD" $FILE_FOR_EDIT
FILE_PATCHED=2
fi
UCI_DEF=$(grep 'uci_apply_defaults' $FILE_FOR_EDIT)
if [ -n "$UCI_DEF" -a $FILE_PATCHED == 0 ]; then
sed -i "/uci_apply_defaults$/i$NEW_CMD" $FILE_FOR_EDIT
FILE_PATCHED=3
fi
fi fi
fi fi
# run patch if [ $INSTALL_METHOD == 2 ]; then
sh /etc/lang_patch.sh FILE_FOR_EDIT=/etc/crontabs/root
grep -v "/lang_patch.sh" $FILE_FOR_EDIT > $FILE_FOR_EDIT.new
# delete lang echo "*/1 * * * * $DIR_PATCH/lang_patch.sh >/dev/null 2>&1" >> $FILE_FOR_EDIT.new
uci -q delete luci.languages.ru mv $FILE_FOR_EDIT.new $FILE_FOR_EDIT
uci -q delete luci.languages.en /etc/init.d/cron restart
FILE_PATCHED=4
# add lang fi
uci set luci.languages.ru=Русский
uci set luci.languages.en=English
# set main lang # set main lang
uci set luci.main.lang=en uci set luci.main.lang=en
#uci commit luci
# commit luci settings # run patch
uci commit luci sh $DIR_PATCH/lang_patch.sh
# reload luci
luci-reload & rm -f /tmp/luci-indexcache & luci-reload
+28 -2
View File
@@ -1,4 +1,18 @@
if [ `ls /etc/base.*.lmo |wc -l` -eq 0 ]; then #!/bin/sh
[ -e "/tmp/lang_patch.log" ] && return 0
DIR_PATCH=/etc/crontabs/patches
if [ `ls $DIR_PATCH/base.*.lmo |wc -l` -eq 0 ]; then
return 0
fi
#if [ -e "/etc/xiaoqiang_version" ]; then
# return 0
#fi
if [ -e "/usr/lib/lua/luci/i18n/base.en.lmo" ]; then
return 0 return 0
fi fi
@@ -6,7 +20,7 @@ mkdir -p /tmp/_usr_lib_lua_luci
cp -rf /usr/lib/lua/luci/* /tmp/_usr_lib_lua_luci/ cp -rf /usr/lib/lua/luci/* /tmp/_usr_lib_lua_luci/
mount --bind /tmp/_usr_lib_lua_luci /usr/lib/lua/luci mount --bind /tmp/_usr_lib_lua_luci /usr/lib/lua/luci
cp /etc/base.*.lmo /usr/lib/lua/luci/i18n cp $DIR_PATCH/base.*.lmo /usr/lib/lua/luci/i18n
# save original file # save original file
cp -f /usr/share/xiaoqiang/xiaoqiang_version /etc/xiaoqiang_version cp -f /usr/share/xiaoqiang/xiaoqiang_version /etc/xiaoqiang_version
@@ -20,3 +34,15 @@ sed -i 's/ and features\["system"\]\["i18n"\] == "1" //' /usr/lib/lua/luci/view/
# unlock change luci.main.lang # unlock change luci.main.lang
sed -i "s/option CHANNEL 'stable'/option CHANNEL 'release'/g" /usr/share/xiaoqiang/xiaoqiang_version sed -i "s/option CHANNEL 'stable'/option CHANNEL 'release'/g" /usr/share/xiaoqiang/xiaoqiang_version
echo "lang patched" > /tmp/lang_patch.log
MAIN_LANG=$( uci -q get luci.main.lang )
[ "$MAIN_LANG" == "" ] && uci set luci.main.lang=en
uci set luci.languages.ru=Русский
uci set luci.languages.en=English
uci commit luci
# reload luci
luci-reload & rm -f /tmp/luci-indexcache & luci-reload
+12 -1
View File
@@ -1,3 +1,7 @@
#!/bin/sh
DIR_PATCH=/etc/crontabs/patches
if [ "$(mount| grep '/usr/lib/lua/luci')" != "" ]; then if [ "$(mount| grep '/usr/lib/lua/luci')" != "" ]; then
umount -l /usr/lib/lua/luci umount -l /usr/lib/lua/luci
fi fi
@@ -8,8 +12,15 @@ if [ "$(mount| grep '/usr/share/xiaoqiang')" != "" ]; then
fi fi
rm -rf /tmp/_usr_share_xiaoqiang rm -rf /tmp/_usr_share_xiaoqiang
grep -v "/lang_patch.sh" /etc/crontabs/root > /etc/crontabs/root.new
mv /etc/crontabs/root.new /etc/crontabs/root
/etc/init.d/cron restart
rm -f /etc/rc.lang rm -f /etc/rc.lang
rm -f /etc/lang_patch.sh rm -f /etc/lang_patch.sh
rm -f /etc/base.*.lmo rm -f $DIR_PATCH/lang_patch.sh
rm -f $DIR_PATCH/base.*.lmo
rm -f /tmp/lang_patch.log
luci-reload & rm -f /tmp/luci-indexcache & luci-reload luci-reload & rm -f /tmp/luci-indexcache & luci-reload
+8 -6
View File
@@ -1,19 +1,21 @@
#!/bin/sh #!/bin/sh
DIR_PATCH=/etc/crontabs/patches
if [ "$( grep 'ssh_patch.sh' /etc/crontabs/root )" != "" ]; then if [ "$( grep 'ssh_patch.sh' /etc/crontabs/root )" != "" ]; then
if [ -e "/tmp/ssh_uninstall.sh" ]; then if [ -e "/tmp/ssh_uninstall.sh" ]; then
sh /tmp/ssh_uninstall.sh sh /tmp/ssh_uninstall.sh
fi fi
fi fi
if [ ! -d /etc/crontabs/patches/ ]; then if [ ! -d $DIR_PATCH ]; then
mkdir /etc/crontabs/patches/ mkdir $DIR_PATCH
chown root /etc/crontabs/patches/ chown root $DIR_PATCH
chmod 0755 /etc/crontabs/patches/ chmod 0755 $DIR_PATCH
fi fi
mv -f /tmp/ssh_patch.sh /etc/crontabs/patches/ mv -f /tmp/ssh_patch.sh $DIR_PATCH/
chmod +x /etc/crontabs/patches/ssh_patch.sh chmod +x $DIR_PATCH/ssh_patch.sh
nvram set ssh_en=1 nvram set ssh_en=1
nvram commit nvram commit