[LEDE-DEV] [PATCH] base-files: sysupgrade. Added the ability to use URL as source

adron at yapic.net adron at yapic.net
Wed Jul 6 06:40:12 PDT 2016


From: Sergey Sergeev <adron at yapic.net>

scp uls(like this scp://adron@192.168.88.6:lede/lede-ar71xx-mikrotik-NAND-512b-squashfs-sysupgrade.bin)
  is supported too. And you also can specify custom ssh port(...8.88.6:22110:lede...)

Signed-off-by: Sergey Sergeev <adron at yapic.net>
---
 package/base-files/files/sbin/sysupgrade | 39 ++++++++++++++++++++++++++++++++
 1 file changed, 39 insertions(+)

diff --git a/package/base-files/files/sbin/sysupgrade b/package/base-files/files/sbin/sysupgrade
index 2f441f8..834cc3a 100755
--- a/package/base-files/files/sbin/sysupgrade
+++ b/package/base-files/files/sbin/sysupgrade
@@ -135,6 +135,45 @@ sysupgrade_image_check="platform_check_image"
 
 include /lib/upgrade
 
+download_if_URL(){
+	local url="$1"
+	local url_repl_file="/tmp/sysupgrade-URL.bin"
+	local cmd
+
+	case "$url" in
+		scp://*)
+			local scp_url="${url#scp://}"
+			local custom_port=$scp_url
+			scp_url=${scp_url/:[[:digit:]]*:/:} # chomp custom ssh port
+			# if custom ssh port is specified
+			if [ "$custom_port" != "$scp_url" ]; then
+				custom_port=${custom_port#*:}
+				custom_port=${custom_port%%:*}
+			else
+				custom_port=""
+			fi
+			cmd="scp"
+			[ -n "$custom_port" ] && cmd="$cmd -P $custom_port"
+			cmd="$cmd \"$scp_url\" $url_repl_file"
+			;;
+		*://*) cmd="wget \"$url\" -O$url_repl_file" ;;
+		*) return 0 ;;
+	esac
+
+	eval "$cmd" || {
+		echo "download process is failed! ret = $?"
+		echo "cmd: $cmd"
+		rm -f $url_repl_file
+		return 1
+	}
+
+	ARGV=${ARGV/"$url"/"$url_repl_file"}
+	return 0
+}
+
+# if URL was specified then download image file from network
+download_if_URL "$ARGV" || exit 1
+
 [ "$1" = "nand" ] && nand_upgrade_stage2 $@
 
 do_save_conffiles() {
-- 
1.9.1




More information about the Lede-dev mailing list