Skip to content
Snippets Groups Projects
Commit 3a1782a9 authored by Kenneth Johansson's avatar Kenneth Johansson
Browse files

iop ssh_upgrade: ask before starting flash.

Printout what options is going to be used and ask if its ok before
burning image.
parent 4f37f221
Branches
Tags
1 merge request!465iop: ssh_upgrade: Move script from iopsys feed
# this is a developer helper script to install firmware on a remote host with SSH
function usagee {
echo "usage: $0 iopupgrade -h <host> -f <file> "
function upd_usage {
echo "usage: $0 iopupgrade -t <host> -f <file> [opts] "
echo ""
echo " Default host is 192.168.1.1"
echo " Default firmware file is the newest one found"
echo " Default is to not keep configuration"
echo "opts:"
echo ""
echo " -i Interactive use, Allows to select firmware file"
echo " -n Do not do the final reboot of the target board"
echo " -c Keep configuration"
echo " -x Force install even if firmware is not for this board"
echo " -b Force install of bootloader regardless of version installed"
}
function set_config_string {
eval `grep $1 .config`
}
function upd_ask_ok {
echo "Will Continue with the following settings"
echo "-----------------------------------------"
printf "%20s: %s\n" "Firmare file" "$upd_fw_base"
printf "%20s: %s\n" "Host ip" "$upd_host"
printf "%20s: " "Reboot"; if [ "$upd_noreboot" == "0" ] ;then printf "Yes\n" ;else printf "No\n";fi
printf "%20s: " "Keep config"; if [ "$upd_keepconf" == "1" ] ;then printf "Yes\n" ;else printf "No\n";fi
printf "%20s: " "Force bootloader"; if [ "$upd_forceboot" == "1" ] ;then printf "Yes\n" ;else printf "No\n";fi
printf "%20s: " "Force image upgrade"; if [ "$upd_forceimage" == "1" ] ;then printf "Yes\n" ;else printf "No\n";fi
echo "-----------------------------------------"
echo -n "Continue? [Y/n]:"
read answer
case $answer in
n|N)
return 1;;
y|Y|*)
return 0;;
esac
}
function ssh_upgrade {
upd_noreboot=0
upd_forceboot=0
upd_keepconf=0
upd_forceimage=0
upd_fw_base=""
upd_fw=""
upd_host="192.168.1.1"
set_config_string CONFIG_TARGET_BOARD
firmwares=$(cd bin/targets/$CONFIG_TARGET_BOARD/generic/; ls -t *[0-9].y[3])
echo "--------------"
for latest in $firmwares
do
#echo "firmware $latest"
break
while getopts "f:hnxt:" opt; do
case $opt in
n)
upd_noreboot=1
;;
x)
upd_forceimage=1
;;
b)
upd_forceboot=1
;;
c)
upd_keepconf=1
upd_keepconf=0 # not yet supported
;;
v)
verbose=$OPTARG
;;
f)
upd_fw=$OPTARG
;;
t)
upd_host=$OPTARG
;;
h)
upd_usage
exit 1
;;
\?)
echo "Invalid option: -$OPTARG" >&2
exit 1
;;
esac
done
echo "latest firmware is $latest"
firmware="bin/targets/$CONFIG_TARGET_BOARD/generic/$latest"
if [ ! -f $firmware ]
if [ -n "upd_fw" ]
then
upd_fw_base=$(basename $upd_fw);
else
set_config_string CONFIG_TARGET_BOARD
firmwares=$(cd bin/targets/$CONFIG_TARGET_BOARD/generic/; ls -t *[0-9].y[3])
for upd_fw_base in $firmwares
do
#echo "firmware $upd_fw"
break
done
upd_fw="bin/targets/$CONFIG_TARGET_BOARD/generic/$upd_fw_base"
fi
if ! upd_ask_ok
then
echo "Aborting"
exit 1
fi
if [ ! -f $upd_fw ]
then
echo "firmware file $firmware do not exist"
exit 1
fi
file_size_kb=`du -k "$firmware" | cut -f1`
file_size_kb=`du -k "$upd_fw" | cut -f1`
cat $firmware | pv -s ${file_size_kb}k | ssh root@192.168.1.1 iopu
exit 0
echo "--------------"
if [ -z "$1" ] ; then
usagee
echo "Error: host required"
exit 1
fi
if [ -z "$2" ] ; then
usagee
echo "Error: firmware filename required"
exit 1
fi
if [ ! -e $2 ] ; then
usagee
echo "Error: firmware file does not exist"
exit 1
fi
IMAGE=`basename $2`
echo "sysupgrade host: $1 with file $IMAGE"
[ "$2" ] && [ -e "$2" ] && scp $2 root@$1:/tmp/ && ssh -o ConnectTimeout=60 root@$1 "sysupgrade -v $3 /tmp/$IMAGE" && echo "sysupgrade done!"
cat $upd_fw | pv -s ${file_size_kb}k | ssh root@192.168.1.1 iopu
exit 0
}
register_command "ssh_upgrade" "-h <host> <file> [opts] Install firmware on remote host with SSH"
register_command "ssh_upgrade" "-h <host> -f <file> [opts] Install firmware on remote host with SSH"
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment