download() stop script if 404
This commit is contained in:
parent
9ef4d922f5
commit
8a62ce69df
1 changed files with 58 additions and 51 deletions
109
init.sh
109
init.sh
|
@ -94,87 +94,94 @@ process_args() {
|
||||||
}
|
}
|
||||||
|
|
||||||
usage() {
|
usage() {
|
||||||
cat << EOF
|
cat << EOF
|
||||||
USAGE: ${0} [-a architecture] [-b]
|
USAGE: ${0} [-a architecture] [-b]
|
||||||
-a | --arch Select CPU Architecture amd64 | i386 CPU
|
-a | --arch Select CPU Architecture amd64 | i386 CPU
|
||||||
-b | --bios Create a bios bott compatible key
|
-b | --bios Create a bios bott compatible key
|
||||||
-d | --device Device_block USB key to write
|
-d | --device Device_block USB key to write
|
||||||
--debian-version Choose Debian Version to download
|
--debian-version Choose Debian Version to download
|
||||||
--repo Repo directory (defaukt is ./repo)
|
--repo Repo directory (defaukt is ./repo)
|
||||||
--temp Temp directory (default is ./tmp)
|
--temp Temp directory (default is ./tmp)
|
||||||
-v | --version Show version
|
-v | --version Show version
|
||||||
|
|
||||||
${0} initialize an usb key for Debian automatic install with preseed and a partman recipe.
|
${0} initialize an usb key for Debian automatic install with preseed and a partman recipe.
|
||||||
EOF
|
EOF
|
||||||
}
|
}
|
||||||
|
|
||||||
show_version () {
|
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 (){
|
||||||
#Download function
|
#Download function
|
||||||
# $1 : filename
|
# $1 : filename
|
||||||
# $2 : url
|
# $2 : url
|
||||||
# $3 : 1 if abort download if file exist
|
# $3 : 1 if abort download if file exist
|
||||||
printf "Downloading %s : " "$1"
|
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)}'
|
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
|
then
|
||||||
printf " \b\b\b\b\b done\n "
|
printf " \b\b\b\b\b done\n "
|
||||||
else
|
else
|
||||||
printf " error, exiting.\n"
|
printf " error, exiting.\n"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
else
|
||||||
|
printf "Error 404 : file not found, exiting\n"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
process_conf_file (){
|
process_conf_file (){
|
||||||
for p in `cat $1 | grep '^[^#].*'`
|
for p in `cat $1 | grep '^[^#].*'`
|
||||||
do
|
do
|
||||||
var=`echo "$p" | awk -F"=" '{print $1}'`
|
var=`echo "$p" | awk -F"=" '{print $1}'`
|
||||||
param=`echo "$p" | awk -F"=" '{print $2}'`
|
param=`echo "$p" | awk -F"=" '{print $2}'`
|
||||||
eval $var=$param
|
eval $var=$param
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
create_dir(){
|
create_dir(){
|
||||||
# $1 directory to create
|
# $1 directory to create
|
||||||
if [ ! -d $1 ]
|
if [ ! -d $1 ]
|
||||||
then
|
then
|
||||||
mkdir -p $1
|
mkdir -p $1
|
||||||
else
|
else
|
||||||
if [[ $2 == 1 ]]
|
if [[ $2 == 1 ]]
|
||||||
then
|
then
|
||||||
rm -rf $1
|
rm -rf $1
|
||||||
create_dir $1
|
create_dir $1
|
||||||
fi
|
|
||||||
fi
|
fi
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# unmount if device is mounted
|
# unmount if device is mounted
|
||||||
umount_device (){
|
umount_device (){
|
||||||
local mounted_part=$(mount | grep "${1}[0-9]" | awk '{print $3}')
|
local mounted_part=$(mount | grep "${1}[0-9]" | awk '{print $3}')
|
||||||
if [ ! -z mounted_part ]
|
if [ ! -z mounted_part ]
|
||||||
then
|
then
|
||||||
for part in $mounted_part
|
for part in $mounted_part
|
||||||
do
|
do
|
||||||
if [ -d $part ]
|
if [ -d $part ]
|
||||||
then
|
then
|
||||||
printf "Unmount %s\n " "$part"
|
printf "Unmount %s\n " "$part"
|
||||||
umount $part --recursive
|
umount $part --recursive
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
efi_create_key_structure () {
|
efi_create_key_structure () {
|
||||||
parted -s $1 mklabel gpt mkpart EFS fat32 1MiB 128MiB set 1 boot on mkpart debian fat32 128MiB 100%
|
parted -s $1 mklabel gpt mkpart EFS fat32 1MiB 128MiB set 1 boot on mkpart debian fat32 128MiB 100%
|
||||||
sleep 2
|
sleep 2
|
||||||
mkfs.vfat ${1}1 -n efi &> /dev/null
|
mkfs.vfat ${1}1 -n efi &> /dev/null
|
||||||
mkfs.vfat ${1}2 -n debian &> /dev/null
|
mkfs.vfat ${1}2 -n debian &> /dev/null
|
||||||
mount ${1}2 $2
|
mount ${1}2 $2
|
||||||
create_dir $2/efi
|
create_dir $2/efi
|
||||||
mount ${1}1 $2/efi
|
mount ${1}1 $2/efi
|
||||||
}
|
}
|
||||||
|
|
||||||
bios_create_key_structure() {
|
bios_create_key_structure() {
|
||||||
|
|
Reference in a new issue