download() stop script if 404

This commit is contained in:
Yorick Barbanneau 2017-10-03 13:50:06 +02:00
parent 9ef4d922f5
commit 8a62ce69df

105
init.sh
View file

@ -94,87 +94,94 @@ process_args() {
}
usage() {
cat << EOF
cat << EOF
USAGE: ${0} [-a architecture] [-b]
-a | --arch Select CPU Architecture amd64 | i386 CPU
-b | --bios Create a bios bott compatible key
-d | --device Device_block USB key to write
--debian-version Choose Debian Version to download
--repo Repo directory (defaukt is ./repo)
--temp Temp directory (default is ./tmp)
-v | --version Show version
-a | --arch Select CPU Architecture amd64 | i386 CPU
-b | --bios Create a bios bott compatible key
-d | --device Device_block USB key to write
--debian-version Choose Debian Version to download
--repo Repo directory (defaukt is ./repo)
--temp Temp directory (default is ./tmp)
-v | --version Show version
${0} initialize an usb key for Debian automatic install with preseed and a partman recipe.
EOF
}
show_version () {
printf "%s %s 2016-2017 ephase@xieme-art.org\n" "$APP_NAME" "$VERSION"
printf "%s %s 2016-2017 ephase@xieme-art.org\n" "$APP_NAME" "$VERSION"
}
download (){
#Download function
# $1 : filename
# $2 : url
# $3 : 1 if abort download if file exist
printf "Downloading %s : " "$1"
#Download function
# $1 : filename
# $2 : url
# $3 : 1 if abort download if file exist
printf "Downloading %s : " "$1"
http_response=$(wget --spider --server-response $2/$1 2>&1 | grep HTTP/ | tail -1 | awk ' { printf $2 }')
if [ $http_response -eq 200 ]
then
wget -c --progress=dot $2/$1 2>&1 | grep --line-buffered "[0-9]\{1,3\}%" -o | awk '{printf ("\b\b\b\b%4s", $1)}'
if [ $? -eq 0 ]
if [ $? -eq 0 ]
then
printf " \b\b\b\b\b done\n "
else
printf " error, exiting.\n"
exit 1
fi
else
printf "Error 404 : file not found, exiting\n"
exit 1
fi
}
process_conf_file (){
for p in `cat $1 | grep '^[^#].*'`
do
var=`echo "$p" | awk -F"=" '{print $1}'`
param=`echo "$p" | awk -F"=" '{print $2}'`
eval $var=$param
done
for p in `cat $1 | grep '^[^#].*'`
do
var=`echo "$p" | awk -F"=" '{print $1}'`
param=`echo "$p" | awk -F"=" '{print $2}'`
eval $var=$param
done
}
create_dir(){
# $1 directory to create
if [ ! -d $1 ]
# $1 directory to create
if [ ! -d $1 ]
then
mkdir -p $1
else
if [[ $2 == 1 ]]
then
mkdir -p $1
else
if [[ $2 == 1 ]]
then
rm -rf $1
create_dir $1
fi
rm -rf $1
create_dir $1
fi
fi
}
# unmount if device is mounted
umount_device (){
local mounted_part=$(mount | grep "${1}[0-9]" | awk '{print $3}')
if [ ! -z mounted_part ]
then
for part in $mounted_part
do
if [ -d $part ]
then
printf "Unmount %s\n " "$part"
umount $part --recursive
fi
done
fi
local mounted_part=$(mount | grep "${1}[0-9]" | awk '{print $3}')
if [ ! -z mounted_part ]
then
for part in $mounted_part
do
if [ -d $part ]
then
printf "Unmount %s\n " "$part"
umount $part --recursive
fi
done
fi
}
efi_create_key_structure () {
parted -s $1 mklabel gpt mkpart EFS fat32 1MiB 128MiB set 1 boot on mkpart debian fat32 128MiB 100%
sleep 2
mkfs.vfat ${1}1 -n efi &> /dev/null
mkfs.vfat ${1}2 -n debian &> /dev/null
mount ${1}2 $2
create_dir $2/efi
mount ${1}1 $2/efi
parted -s $1 mklabel gpt mkpart EFS fat32 1MiB 128MiB set 1 boot on mkpart debian fat32 128MiB 100%
sleep 2
mkfs.vfat ${1}1 -n efi &> /dev/null
mkfs.vfat ${1}2 -n debian &> /dev/null
mount ${1}2 $2
create_dir $2/efi
mount ${1}1 $2/efi
}
bios_create_key_structure() {