11#! /bin/sh
22
33DIR_PATCH=/etc/crontabs/patches
4+ DIR_BACKUP=$DIR_PATCH /lang_backup
45
5- if [ ` ls /tmp/ base.* .lmo | wc -l` -eq 0 ]; then
6+ if [ ` find /tmp -maxdepth 1 -name ' base.*.lmo' | wc -l` -eq 0 ]; then
67 return 1
78fi
89
9- if [ " $( mount| grep ' /usr/lib/lua/luci' ) " != " " ]; then
10- if [ -e " /tmp/lang_uninstall.sh" ]; then
11- sh /tmp/lang_uninstall.sh
12- fi
13- fi
14-
15- # delete old patch
16- rm -f /etc/rc.lang
17- rm -f /etc/lang_patch.sh
18-
19- # global firmware may contain a file "base.en.lmo"
20- [ -f /usr/lib/lua/luci/i18n/base.en.lmo ] && rm -f /tmp/base.en.lmo
21-
2210if [ ! -d $DIR_PATCH ]; then
23- mkdir $DIR_PATCH
11+ mkdir -p $DIR_PATCH
2412 chown root $DIR_PATCH
2513 chmod 0755 $DIR_PATCH
2614fi
2715
16+ CLEAN_INSTALL=0
17+ if [ ! -d $DIR_BACKUP ]; then
18+ CLEAN_INSTALL=1
19+ mkdir -p $DIR_BACKUP
20+ MAIN_LANG=` uci get luci.main.lang`
21+ echo " $MAIN_LANG " > $DIR_BACKUP /main_lang
22+ fi
23+
24+ if [ $CLEAN_INSTALL = 1 ]; then
25+ NEED_RESTORE_MNT=0
26+ if mount | grep -q ' on /usr/lib/lua/luci' ; then
27+ umount -l /usr/lib/lua/luci
28+ NEED_RESTORE_MNT=1
29+ fi
30+ if [ -f /usr/lib/lua/luci/i18n/base.en.lmo ]; then
31+ # INT firmware may contain a file "base.en.lmo"
32+ echo " 1" > $DIR_BACKUP /skip_base_en
33+ fi
34+ cp -f /usr/lib/lua/luci/view/web/inc/sysinfo.htm $DIR_BACKUP /
35+ cp -f /usr/lib/lua/luci/i18n/base.* .lmo $DIR_BACKUP /
36+ [ $NEED_RESTORE_MNT = 1 ] && mount --bind /tmp/_usr_lib_lua_luci /usr/lib/lua/luci
37+ fi
38+ if [ $CLEAN_INSTALL = 1 ]; then
39+ NEED_RESTORE_MNT=0
40+ if mount | grep -q ' on /usr/share/xiaoqiang' ; then
41+ umount -l /usr/share/xiaoqiang
42+ NEED_RESTORE_MNT=1
43+ fi
44+ if grep -q " option CHANNEL 'stable'" /usr/share/xiaoqiang/xiaoqiang_version ; then
45+ echo ' 1' > $DIR_BACKUP /fw_stable
46+ fi
47+ [ $NEED_RESTORE_MNT = 1 ] && mount --bind /tmp/_usr_share_xiaoqiang /usr/share/xiaoqiang
48+ fi
49+
50+ if [ -f $DIR_BACKUP /skip_base_en ]; then
51+ # INT firmware may contain a file "base.en.lmo"
52+ rm -f /tmp/base.en.lmo
53+ fi
2854mv -f /tmp/base.* .lmo $DIR_PATCH /
2955mv -f /tmp/lang_patch.sh $DIR_PATCH /
3056chmod +x $DIR_PATCH /lang_patch.sh
31- if [ -e " /tmp/lang_patch1.sh" ]; then
32- mv -f /tmp/lang_patch1.sh $DIR_PATCH /
33- chmod +x $DIR_PATCH /lang_patch1.sh
34- fi
3557
36- INSTALL_METHOD=1
37- if [ -e " /usr/lib/os-release" ]; then
38- INSTALL_METHOD=2
58+ INSTALL_METHOD=2
59+ if [ ! -e " /usr/lib/os-release" ]; then
60+ # older routers
61+ INSTALL_METHOD=0
3962fi
4063
4164FILE_PATCHED=0
4265
43- if [ $INSTALL_METHOD == 1 ]; then
66+ if [ $INSTALL_METHOD = 0 ]; then
4467 FILE_PATCHED=1
4568 FILE_FOR_EDIT=/etc/init.d/boot
4669 NEW_CMD=" \[ -f \/etc\/crontabs\/patches\/lang_patch.sh \] && sh \/etc\/crontabs\/patches\/lang_patch.sh"
@@ -60,19 +83,28 @@ if [ $INSTALL_METHOD == 1 ]; then
6083 fi
6184fi
6285
63- if [ $INSTALL_METHOD == 2 ]; then
86+ if [ $INSTALL_METHOD = 1 ]; then
6487 FILE_FOR_EDIT=/etc/crontabs/root
6588 grep -v " /lang_patch.sh" $FILE_FOR_EDIT > $FILE_FOR_EDIT .new
6689 echo " */1 * * * * $DIR_PATCH /lang_patch.sh >/dev/null 2>&1" >> $FILE_FOR_EDIT .new
6790 mv $FILE_FOR_EDIT .new $FILE_FOR_EDIT
6891 /etc/init.d/cron restart
69- FILE_PATCHED=4
92+ FILE_PATCHED=10
93+ fi
94+
95+ if [ $INSTALL_METHOD = 2 ]; then
96+ uci set firewall.auto_lang_patch=include
97+ uci set firewall.auto_lang_patch.type=' script'
98+ uci set firewall.auto_lang_patch.path=" $DIR_PATCH /lang_patch.sh"
99+ uci set firewall.auto_lang_patch.enabled=' 1'
100+ uci commit firewall
101+ FILE_PATCHED=20
70102fi
71103
72104# set main lang
73105uci set luci.main.lang=en
74106# uci commit luci
75107
76108# run patch
77- sh $DIR_PATCH /lang_patch.sh
109+ $DIR_PATCH /lang_patch.sh
78110
0 commit comments