base-files: upgrade: fix initramfs detection
[openwrt/staging/dedeckeh.git] / package / base-files / files / sbin / sysupgrade
index f18143bff42ef6659fb3a0281b19c60a72f125d8..3300d8e1ea559c5e2e696876c5f500a89c4f97e7 100755 (executable)
@@ -127,7 +127,7 @@ list_changed_conffiles() {
        list_conffiles | while read file csum; do
                [ -r "$file" ] || continue
 
-               echo "${csum}  ${file}" | sha256sum -sc - || echo "$file"
+               echo "${csum}  ${file}" | busybox sha256sum -sc - || echo "$file"
        done
 }
 
@@ -216,7 +216,7 @@ include /lib/upgrade
 do_save_conffiles() {
        local conf_tar="$1"
 
-       [ -z "$(rootfs_type)" ] && {
+       [ "$(rootfs_type)" = "tmpfs" ] && {
                echo "Cannot save config while running from ramdisk." >&2
                ask_bool 0 "Abort" && exit
                rm -f "$conf_tar"
@@ -294,7 +294,7 @@ type platform_check_image >/dev/null 2>/dev/null || {
 case "$IMAGE" in
        http://*|\
        https://*)
-               wget -O/tmp/sysupgrade.img "$IMAGE"
+               wget -O/tmp/sysupgrade.img "$IMAGE" || exit 1
                IMAGE=/tmp/sysupgrade.img
                ;;
 esac
@@ -360,19 +360,15 @@ if [ -n "$FAILSAFE" ]; then
        printf '%s\x00%s\x00%s' "$RAM_ROOT" "$IMAGE" "$COMMAND" >/tmp/sysupgrade
        lock -u /tmp/.failsafe
 else
-       force_attr=""
-       [ $FORCE -eq 1 ] && force_attr="\"force\": true,"
-       backup_attr=""
-       [ $SAVE_CONFIG -eq 1 ] && backup_attr="\"backup\": $(json_string $CONF_TAR),"
-       ubus call system sysupgrade "{
-               \"prefix\": $(json_string "$RAM_ROOT"),
-               \"path\": $(json_string "$IMAGE"),
-               $force_attr
-               $backup_attr
-               \"command\": $(json_string "$COMMAND"),
-               \"options\": {
-                       \"save_config\": $SAVE_CONFIG,
-                       \"save_partitions\": $SAVE_PARTITIONS
-               }
-       }"
+       json_init
+       json_add_string prefix "$RAM_ROOT"
+       json_add_string path "$IMAGE"
+       [ $FORCE -eq 1 ] && json_add_boolean force 1
+       [ $SAVE_CONFIG -eq 1 ] && json_add_string backup "$CONF_TAR"
+       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)"
 fi