mirror of
https://github.com/openwrt-xiaomi/xmir-patcher.git
synced 2026-09-22 22:57:55 +03:00
Adapt lang_patch.sh for newest routers
This commit is contained in:
+52
-33
@@ -1,55 +1,74 @@
|
||||
#!/bin/sh
|
||||
|
||||
DIR_PATCH=/etc/crontabs/patches
|
||||
|
||||
if [ `ls /tmp/base.*.lmo |wc -l` -eq 0 ]; then
|
||||
return 1
|
||||
fi
|
||||
|
||||
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
|
||||
|
||||
# delete old patch
|
||||
rm -f /etc/rc.lang
|
||||
rm -f /etc/lang_patch.sh
|
||||
|
||||
# global firmware may contain a file "base.en.lmo"
|
||||
[ -f /usr/lib/lua/luci/i18n/base.en.lmo ] && rm -f /tmp/base.en.lmo
|
||||
|
||||
mv -f /tmp/base.*.lmo /etc/
|
||||
mv -f /tmp/lang_patch.sh /etc/
|
||||
chmod +x /etc/lang_patch.sh
|
||||
if [ ! -d $DIR_PATCH ]; then
|
||||
mkdir $DIR_PATCH
|
||||
chown root $DIR_PATCH
|
||||
chmod 0755 $DIR_PATCH
|
||||
fi
|
||||
|
||||
FILE_FOR_EDIT=/etc/init.d/boot
|
||||
NEW_CMD="\[ -f \/etc\/lang_patch.sh \] && sh \/etc\/lang_patch.sh"
|
||||
FILE_PATCHED=1
|
||||
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
|
||||
mv -f /tmp/base.*.lmo $DIR_PATCH/
|
||||
mv -f /tmp/lang_patch.sh $DIR_PATCH/
|
||||
chmod +x $DIR_PATCH/lang_patch.sh
|
||||
|
||||
INSTALL_METHOD=1
|
||||
if [ -e "/usr/lib/os-release" ]; then
|
||||
INSTALL_METHOD=2
|
||||
fi
|
||||
|
||||
FILE_PATCHED=0
|
||||
|
||||
if [ $INSTALL_METHOD == 1 ]; then
|
||||
FILE_PATCHED=1
|
||||
FILE_FOR_EDIT=/etc/init.d/boot
|
||||
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
|
||||
|
||||
# run patch
|
||||
sh /etc/lang_patch.sh
|
||||
|
||||
# delete lang
|
||||
uci -q delete luci.languages.ru
|
||||
uci -q delete luci.languages.en
|
||||
|
||||
# add lang
|
||||
uci set luci.languages.ru=Русский
|
||||
uci set luci.languages.en=English
|
||||
if [ $INSTALL_METHOD == 2 ]; then
|
||||
FILE_FOR_EDIT=/etc/crontabs/root
|
||||
grep -v "/lang_patch.sh" $FILE_FOR_EDIT > $FILE_FOR_EDIT.new
|
||||
echo "*/1 * * * * $DIR_PATCH/lang_patch.sh >/dev/null 2>&1" >> $FILE_FOR_EDIT.new
|
||||
mv $FILE_FOR_EDIT.new $FILE_FOR_EDIT
|
||||
/etc/init.d/cron restart
|
||||
FILE_PATCHED=4
|
||||
fi
|
||||
|
||||
# set main lang
|
||||
uci set luci.main.lang=en
|
||||
#uci commit luci
|
||||
|
||||
# commit luci settings
|
||||
uci commit luci
|
||||
# run patch
|
||||
sh $DIR_PATCH/lang_patch.sh
|
||||
|
||||
# reload luci
|
||||
luci-reload & rm -f /tmp/luci-indexcache & luci-reload
|
||||
|
||||
+28
-2
@@ -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
|
||||
fi
|
||||
|
||||
@@ -6,7 +20,7 @@ mkdir -p /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
|
||||
|
||||
cp /etc/base.*.lmo /usr/lib/lua/luci/i18n
|
||||
cp $DIR_PATCH/base.*.lmo /usr/lib/lua/luci/i18n
|
||||
|
||||
# save original file
|
||||
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
|
||||
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
@@ -1,3 +1,7 @@
|
||||
#!/bin/sh
|
||||
|
||||
DIR_PATCH=/etc/crontabs/patches
|
||||
|
||||
if [ "$(mount| grep '/usr/lib/lua/luci')" != "" ]; then
|
||||
umount -l /usr/lib/lua/luci
|
||||
fi
|
||||
@@ -8,8 +12,15 @@ if [ "$(mount| grep '/usr/share/xiaoqiang')" != "" ]; then
|
||||
fi
|
||||
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/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
|
||||
|
||||
|
||||
+8
-6
@@ -1,19 +1,21 @@
|
||||
#!/bin/sh
|
||||
|
||||
DIR_PATCH=/etc/crontabs/patches
|
||||
|
||||
if [ "$( grep 'ssh_patch.sh' /etc/crontabs/root )" != "" ]; then
|
||||
if [ -e "/tmp/ssh_uninstall.sh" ]; then
|
||||
sh /tmp/ssh_uninstall.sh
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ ! -d /etc/crontabs/patches/ ]; then
|
||||
mkdir /etc/crontabs/patches/
|
||||
chown root /etc/crontabs/patches/
|
||||
chmod 0755 /etc/crontabs/patches/
|
||||
if [ ! -d $DIR_PATCH ]; then
|
||||
mkdir $DIR_PATCH
|
||||
chown root $DIR_PATCH
|
||||
chmod 0755 $DIR_PATCH
|
||||
fi
|
||||
|
||||
mv -f /tmp/ssh_patch.sh /etc/crontabs/patches/
|
||||
chmod +x /etc/crontabs/patches/ssh_patch.sh
|
||||
mv -f /tmp/ssh_patch.sh $DIR_PATCH/
|
||||
chmod +x $DIR_PATCH/ssh_patch.sh
|
||||
|
||||
nvram set ssh_en=1
|
||||
nvram commit
|
||||
|
||||
Reference in New Issue
Block a user