@@ -44,26 +44,54 @@ log_error() {
44
44
}
45
45
46
46
usage () {
47
- echo " Usage: $0 [fota|ota] [--dry-run]"
47
+ echo " Usage: $0 [fota|ota] [--dry-run] [--reset] "
48
48
exit 1
49
49
}
50
50
51
- DRY_RUN=0
52
-
53
- if [ " $# " -eq 0 ]; then
54
- usage
55
- fi
56
-
57
- MODE=" $1 "
51
+ version_greater () {
52
+ printf ' %s\n%s\n' " $1 " " $2 " | sort -V | head -n 1 | grep -q " ^$2 $"
53
+ }
58
54
59
- if [ " $# " -eq 2 ]; then
60
- if [ " $2 " = " --dry-run" ]; then
61
- DRY_RUN=1
62
- log_info " Dry-run mode activated. No destructive operations will be executed."
55
+ check_and_update_compat_version () {
56
+ REQUIRED_VERSION=" $1 "
57
+ CURRENT_VERSION=$( uci get system.@system[0].compat_version 2> /dev/null || echo " 0.0" )
58
+
59
+ if version_greater " $REQUIRED_VERSION " " $CURRENT_VERSION " ; then
60
+ log_info " Updating compat_version from $CURRENT_VERSION to $REQUIRED_VERSION ..."
61
+ uci set system.@system[0].compat_version=" $REQUIRED_VERSION "
62
+ uci commit system
63
+ log_success " compat_version updated to $REQUIRED_VERSION ."
63
64
else
64
- usage
65
+ log_info " Current compat_version ( $CURRENT_VERSION ) is already compatible or greater. "
65
66
fi
66
- elif [ " $# " -gt 2 ]; then
67
+ }
68
+
69
+ MODE=" "
70
+ DRY_RUN=0
71
+ RESET=0
72
+
73
+ while [ " $# " -gt 0 ]; do
74
+ case " $1 " in
75
+ fota|ota)
76
+ if [ -n " $MODE " ]; then
77
+ usage
78
+ fi
79
+ MODE=" $1 "
80
+ ;;
81
+ --dry-run)
82
+ DRY_RUN=1
83
+ ;;
84
+ --reset)
85
+ RESET=1
86
+ ;;
87
+ * )
88
+ usage
89
+ ;;
90
+ esac
91
+ shift
92
+ done
93
+
94
+ if [ -z " $MODE " ]; then
67
95
usage
68
96
fi
69
97
@@ -144,7 +172,7 @@ if [ "$MODE" = "fota" ]; then
144
172
prefix=" \033[1;36mDownloading $filename ...\033[0m"
145
173
asset_url=$( echo " $RELEASES_JSON " | jq -r " .[$index ].assets[] | select(.name==\" $filename \" ) | .browser_download_url" )
146
174
[ -z " $asset_url " ] || [ " $asset_url " = " null" ] && { log_error " Asset $filename not found for release $RELEASE_TAG ." ; exit 1; }
147
-
175
+
148
176
if [ " $DRY_RUN " -eq 1 ]; then
149
177
printf " %b\n" " $prefix "
150
178
log_info " DRY-RUN: Simulated download of $filename from $asset_url "
@@ -247,13 +275,21 @@ if echo "$SYSUPGRADE_LOG" | grep -q "The device is supported, but the config is
247
275
fi
248
276
fi
249
277
278
+ if [ " $RESET " -eq 1 ]; then
279
+ log_info " Starting sysupgrade without preserving configuration..."
280
+ sysupgrade_cmd=" sysupgrade -n"
281
+ else
282
+ log_info " Starting sysupgrade with configuration preserved..."
283
+ sysupgrade_cmd=" sysupgrade"
284
+ fi
285
+
250
286
log_info " Starting sysupgrade with file $SYSUPGRADE_IMG ..."
251
287
sleep 2
252
288
if [ " $DRY_RUN " -eq 1 ]; then
253
289
log_info " DRY-RUN: Simulated sysupgrade execution with $SYSUPGRADE_IMG ."
254
290
SYSUPGRADE_OUTPUT=" Simulated sysupgrade - closing"
255
291
else
256
- SYSUPGRADE_OUTPUT=$( sysupgrade " $SYSUPGRADE_IMG " 2>&1 )
292
+ SYSUPGRADE_OUTPUT=$( $sysupgrade_cmd " $SYSUPGRADE_IMG " 2>&1 )
257
293
fi
258
294
259
295
if echo " $SYSUPGRADE_OUTPUT " | grep -iq " closing" ; then
0 commit comments