Compare commits

...

1 Commits

Author SHA1 Message Date
Alex Oprea
25653cc2d5 iup: refactor function handle_provisioning() 2017-04-11 19:28:49 +02:00

View File

@@ -181,23 +181,25 @@ handle_provisioning() {
local url local url
local tftpfile local tftpfile
local host local host
local md5
local defaultreset local defaultreset
local pack local deckey
local packname
local number=$RANDOM
local retry=1 local retry=1
local number
local incsleep=$SLEEP local incsleep=$SLEEP
local number=$RANDOM
let "number %= $RANGE" let "number %= $RANGE"
if [[ ! -e $IUPTEMP ]]; then
mkdir $IUPTEMP mkdir -p $IUPTEMP
fi
touch $IUPCONFFILES touch $IUPCONFFILES
config_get_bool enabled "$config" enabled "$default" config_get_bool enabled "$config" enabled "$default"
config_get_bool defaultreset "$config" defaultreset config_get_bool defaultreset "$config" defaultreset
config_get deckey "$config" deckey config_get deckey "$config" deckey
if [ "$enabled" -eq 1 ]; then
if [ "$enabled" -ne "1" ]; then
return
fi
# get the url
if [ "$config" == "iup" ]; then if [ "$config" == "iup" ]; then
v "Using url received in dhcp options" v "Using url received in dhcp options"
config_get url "$config" urliup config_get url "$config" urliup
@@ -207,17 +209,17 @@ handle_provisioning() {
url=${url//\$MAC/$MAC} url=${url//\$MAC/$MAC}
v "Downloading from url \"$url\"" v "Downloading from url \"$url\""
while [ $retry -le $RETRYSTOP ] # download the file
do while [ $retry -le $RETRYSTOP ]; do
if [ ${url%%:*} == "tftp" ]; then if [ ${url%%:*} == "tftp" ]; then
tftpfile=${url#*\/\/} tftpfile=${url#*\/\/}
host=${tftpfile%%\/*} host=${tftpfile%%\/*}
tftpfile=${tftpfile#*\/} tftpfile=${tftpfile#*\/}
/usr/bin/tftp -l $IUPCONFFILES -r "$tftpfile" -g "$host" /usr/bin/tftp -l $IUPCONFFILES -r "$tftpfile" -g "$host"
else else
get_image "$url" "cat" > $IUPCONFFILES get_image "$url" "cat" > $IUPCONFFILES
fi fi
if [ -s $IUPCONFFILES ]; then if [ -s $IUPCONFFILES ]; then
v "Download finished" v "Download finished"
retry=$((RETRYSTOP + 1)) retry=$((RETRYSTOP + 1))
@@ -228,20 +230,24 @@ handle_provisioning() {
retry=$((retry+1)) retry=$((retry+1))
fi fi
done done
fi
if [ ! -s "$IUPCONFFILES" ] && [ "$enabled" -eq 1 ]; then if [ ! -s "$IUPCONFFILES" ] ; then
echo "File not Found" echo "File not Found"
reboot="off" reboot="off"
CONF=0 CONF=0
else return
handle_Downloaded_file $deckey
fi fi
handle_Downloaded_file $deckey
} }
handle_Downloaded_file() handle_Downloaded_file()
{ {
local DECKEY local DECKEY
local KEY local KEY
local md5
local pack
local packname
[ -n "$1" ] && DECKEY=$(echo $1 | tr -d '\n' | hexdump -e '16/1 "%02x"') [ -n "$1" ] && DECKEY=$(echo $1 | tr -d '\n' | hexdump -e '16/1 "%02x"')
KEY=${DECKEY:-$DESKEY} KEY=${DECKEY:-$DESKEY}
local img_type local img_type