-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathubnt_erx_migrate.sh
executable file
·101 lines (77 loc) · 2.67 KB
/
ubnt_erx_migrate.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#!/bin/sh
. /lib/functions.sh
include /lib/upgrade
. /usr/share/libubox/jshn.sh
export VERBOSE=1
BOARD="$(board_name | sed 's/,/_/g')"
if [ ! -d /etc/ssl/certs/ ]; then
WGET_OPTS="--no-check-certificate"
fi
RC="24.10.0-rc7"
SITE="https://downloads.openwrt.org/releases/${RC}/targets/ramips/mt7621/"
SNAPSITE="https://downloads.openwrt.org/releases/24.10-SNAPSHOT/targets/ramips/mt7621/"
if [ -n "$SNAPSHOT" ]; then
SITE=${SNAPSITE}
fi
SITE=${TESTSITE:-$SITE}
PATTERN="${BOARD}-squashfs-sysupgrade.bin"
FILE=$(wget ${WGET_OPTS} -qO- "$SITE" | grep -o 'href="[^"]*' | sed 's/href="//' | grep "$PATTERN" | head -n 1)
tar_file="/tmp/sysupgrade.img"
confirm_migration() {
case "$(board_name)" in
ubnt,edgerouter-x|\
ubnt,edgerouter-x-sfp)
compat=$(uci -q get system.@system[0].compat_version)
if [ "$compat" != "1.1" ]; then
echo "Incompatible compat version $compat" >&2
exit 1
fi
;;
*)
echo "Incompatible board $(board_name)" >&2
exit 1
;;
esac
echo -e "\033[0;31mWARNING:\033[0m This script will migrate your OpenWrt system to a new layout as"
echo "required for the linux 6.6 kernel. This process will erase all your current settings."
echo "It is recommended to back up your system before proceeding."
echo ""
read -p "Do you want to proceed with the migration? (y/n)" confirm
if [ "$confirm" != "y" ]; then
echo "Migration canceled."
exit 0
fi
}
download_image(){
echo "Downloading $SITE/$FILE"
wget ${WGET_OPTS} -qO "$tar_file" "$SITE/$FILE"
sha256=$(wget ${WGET_OPTS} -qO- "$SITE/sha256sums" | grep "$PATTERN" | cut -d ' ' -f1)
sha256local=$(sha256sum "$tar_file" | cut -d ' ' -f1)
if [ "$sha256" != "$sha256local" ]; then
echo "Downloaded image checksum mismatch" >&2
exit 1
fi
board_dir=$( (tar tf "$tar_file" | grep -m 1 '^sysupgrade-.*/$') 2> /dev/null)
export board_dir="${board_dir%/}"
tar xC /tmp -f "$tar_file" 2> /dev/null
if [ ! -f /tmp/$board_dir/kernel ] || [ ! -f /tmp/$board_dir/root ]; then
echo "Invalid image file" >&2
exit 1
fi
}
confirm_migration
download_image
install_bin /sbin/upgraded
v "Commencing upgrade. Closing all shell sessions and rebooting."
RAM_ROOT="/tmp/root"
COMMAND="sh /tmp/ubnt_erx_stage2.sh"
SAVE_PARTITIONS=0
json_init
json_add_string prefix "$RAM_ROOT"
json_add_string path "$tar_file"
json_add_boolean force 1
json_add_string command "$COMMAND"
json_add_object options
json_add_int save_partitions "$SAVE_PARTITIONS"
json_close_object
ubus call system sysupgrade "$(json_dump)"