83448e5ace5f2f7dd5bbd1af2226608d77fb8766
[openwrt/openwrt.git] / target / linux / mvebu / base-files / lib / preinit / 81_linksys_syscfg
1 #
2 # Copyright (C) 2014-2016 OpenWrt.org
3 # Copyright (C) 2016 LEDE-Project.org
4 #
5
6 preinit_mount_syscfg() {
7 . /lib/functions.sh
8 . /lib/upgrade/common.sh
9
10 case $(board_name) in
11 linksys,caiman|linksys,cobra|linksys,mamba|linksys,rango|linksys,shelby|linksys,venom)
12 needs_recovery=0
13 syscfg_part=$(grep syscfg /proc/mtd |cut -c4)
14 ubiattach -m $syscfg_part || needs_recovery=1
15 if [ $needs_recovery -eq 1 ]
16 then
17 echo "ubifs syscfg partition is damaged, reformatting"
18 ubidetach -m $syscfg_part
19 ubiformat -y -O 2048 -q /dev/mtd$syscfg_part
20 ubiattach -m $syscfg_part
21 ubimkvol /dev/ubi1 -n 0 -N syscfg -t dynamic --maxavsize
22 fi
23 mkdir /tmp/syscfg
24 mount -t ubifs ubi1:syscfg /tmp/syscfg
25 [ -f "/tmp/syscfg/$BACKUP_FILE" ] && {
26 echo "- config restore -"
27 cd /
28 mv "/tmp/syscfg/$BACKUP_FILE" /tmp
29 tar xzf "/tmp/$BACKUP_FILE"
30 rm -f "/tmp/$BACKUP_FILE"
31 sync
32 }
33 ;;
34 esac
35 }
36
37 boot_hook_add preinit_main preinit_mount_syscfg