Compare commits
No commits in common. "91956a3c776edec7499dbde3c88a8763cd77c263" and "e2f41eb862b714a80d789a163d22fb7e9e1ae0fa" have entirely different histories.
91956a3c77
...
e2f41eb862
1 changed files with 79 additions and 84 deletions
161
init.sh
161
init.sh
|
@ -124,13 +124,10 @@ download (){
|
||||||
# $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"
|
||||||
local url
|
http_response=$(wget --spider --server-response $2/$1 2>&1 | grep HTTP/ | tail -1 | awk ' { printf $2 }')
|
||||||
local http_response
|
if [ $http_response -eq 200 ]
|
||||||
url="$2/$1"
|
|
||||||
http_response=$(wget --spider --server-response "$url" 2>&1 | grep HTTP/ | tail -1 | awk ' { printf $2 }')
|
|
||||||
if [ "$http_response" -eq 200 ]
|
|
||||||
then
|
then
|
||||||
wget -c --progress=dot "$url" 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 "
|
||||||
|
@ -145,81 +142,79 @@ fi
|
||||||
}
|
}
|
||||||
|
|
||||||
process_conf_file (){
|
process_conf_file (){
|
||||||
while read -r p
|
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 < <( cat "$1" | grep '^[^#].*')
|
done
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
create_dir(){
|
create_dir(){
|
||||||
# $1 directory to create
|
# $1 directory to create
|
||||||
if [ ! -d "$1" ]
|
if [ ! -d $1 ]
|
||||||
|
then
|
||||||
|
mkdir -p $1
|
||||||
|
else
|
||||||
|
if [[ $2 == 1 ]]
|
||||||
then
|
then
|
||||||
mkdir -p "$1"
|
rm -rf $1
|
||||||
else
|
create_dir $1
|
||||||
if [ -n "$2" ] && [ "$2" -eq 1 ]
|
|
||||||
then
|
|
||||||
rm -rf "$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=""
|
local mounted_part=$(mount | grep "${1}[0-9]" | awk '{print $3}')
|
||||||
mounted_part=$(mount | grep "${1}[0-9]" | awk '{print $3}')
|
if [ ! "$mounted_part" == "" ]
|
||||||
if [ ! "$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
|
||||||
sync
|
sync
|
||||||
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() {
|
||||||
parted -s "$1" mklabel msdos mkpart primary fat32 1MiB 100% set 1 boot on
|
parted -s $1 mklabel msdos mkpart primary fat32 1MiB 100% set 1 boot on
|
||||||
sleep 2
|
sleep 2
|
||||||
mkfs.vfat "${1}1" -n debian &> /dev/null
|
mkfs.vfat ${1}1 -n debian &> /dev/null
|
||||||
mount "${1}1" "$2"
|
mount ${1}1 $2
|
||||||
}
|
}
|
||||||
|
|
||||||
#Stop script if syslinux is not installed
|
#Stop script if syslinux is not installed
|
||||||
if [ -z "$SYSLINUX_EXE" ]
|
if [ -z $SYSLINUX_EXE ]
|
||||||
then
|
then
|
||||||
printf "Syslinux not found, script can't continue.\n"
|
printf "Syslinux not found, script can't continue.\n"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -z "$PARTED_EXE" ]
|
if [ -z $PARTED_EXE ]
|
||||||
then
|
then
|
||||||
printf "Parted not found, script can't continue.\n"
|
printf "Parted not found, script can't continue.\n"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
process_args "$@"
|
process_args $@
|
||||||
process_conf_file "$conf_file"
|
process_conf_file $conf_file
|
||||||
if [[ ! -d "$syslinux_mbr_bl_folder" || ! -d "$syslinux_efi_bl_folder" || ! -d "$syslinux_modules_folder" ]]
|
if [[ ! -d $syslinux_mbr_bl_folder || ! -d $syslinux_efi_bl_folder || ! -d $syslinux_modules_folder ]]
|
||||||
then
|
then
|
||||||
printf "Bad folder configuration in %s\n" "$conf_file"
|
printf "Bad folder configuration in %s\n" "$conf_file"
|
||||||
exit 1
|
exit 1
|
||||||
|
@ -240,64 +235,64 @@ repo_path="$repo_dir/$debian_arch/$debian_version"
|
||||||
printf "Downloading Debian files\n---\n"
|
printf "Downloading Debian files\n---\n"
|
||||||
|
|
||||||
# Création du répertoire temporaire
|
# Création du répertoire temporaire
|
||||||
create_dir "$repo_path"
|
create_dir $repo_path
|
||||||
cd "$repo_path"
|
cd $repo_path
|
||||||
|
|
||||||
download "$iso_file" "$iso_url" 1
|
download $iso_file $iso_url 1
|
||||||
for file in "vmlinuz" "initrd.gz"
|
for file in "vmlinuz" "initrd.gz"
|
||||||
do
|
do
|
||||||
download "$file" "$bootfiles_Debian" 1
|
download $file $bootfiles_Debian 1
|
||||||
done
|
done
|
||||||
cd "$current_dir"
|
cd $current_dir
|
||||||
|
|
||||||
if [ -z "$device" ]
|
if [ -z $device ]
|
||||||
then
|
then
|
||||||
printf "No destination device specified, USB key will not be created.\n"
|
printf "No destination device specified, USB key will not be created.\n"
|
||||||
fi
|
fi
|
||||||
create_dir "$tmp_dir" 1
|
create_dir $tmp_dir 1
|
||||||
cp "$repo_path/$iso_file" "$tmp_dir"
|
cp $repo_path/$iso_file $tmp_dir
|
||||||
# Copy wanted syslinux file from archive
|
# Copy wanted syslinux file from archive
|
||||||
|
|
||||||
case $boot_type in
|
case $boot_type in
|
||||||
efi64)
|
efi64)
|
||||||
syslinux_folder=${tmp_dir}/efi/EFI/boot
|
syslinux_folder=${tmp_dir}/efi/EFI/boot
|
||||||
create_dir "$syslinux_folder"
|
create_dir $syslinux_folder
|
||||||
cp -T "$syslinux_efi_bl_folder/$boot_type/syslinux.efi" "$syslinux_folder/bootx64.efi" &> /dev/null
|
cp -T $syslinux_efi_bl_folder/$boot_type/syslinux.efi $syslinux_folder/bootx64.efi &> /dev/null
|
||||||
for file in $SYSLINUX_EFI_FILES
|
for file in $SYSLINUX_EFI_FILES
|
||||||
do
|
do
|
||||||
printf "copying %s \n" "$file"
|
printf "copying %s \n" "$file"
|
||||||
cp "$syslinux_modules_folder/$boot_type/$file" "$syslinux_folder"
|
cp $syslinux_modules_folder/$boot_type/$file $syslinux_folder
|
||||||
done
|
done
|
||||||
cp "$repo_path"/{vmlinuz,initrd.gz} "$tmp_dir/efi"
|
cp $repo_path/{vmlinuz,initrd.gz} $tmp_dir/efi
|
||||||
cp -R syslinux/syslinux.cfg "$syslinux_folder" &> /dev/null
|
cp -R syslinux/syslinux.cfg $syslinux_folder &> /dev/null
|
||||||
|
|
||||||
;;
|
;;
|
||||||
bios)
|
bios)
|
||||||
syslinux_folder=${tmp_dir}/syslinux
|
syslinux_folder=${tmp_dir}/syslinux
|
||||||
create_dir "$syslinux_folder"
|
create_dir $syslinux_folder
|
||||||
for file in $SYSLINUX_BIOS_FILES
|
for file in $SYSLINUX_BIOS_FILES
|
||||||
do
|
do
|
||||||
printf "copying %s\n" "$file"
|
prin tf "copying %s\n" "$file"
|
||||||
cp "$syslinux_modules_folder/$boot_type/$file" "$syslinux_folder"
|
cp $syslinux_modules_folder/$boot_type/$file $syslinux_folder
|
||||||
done
|
done
|
||||||
cp "$repo_path"/{vmlinuz,initrd.gz} "$tmp_dir"
|
cp $repo_path/{vmlinuz,initrd.gz} $tmp_dir
|
||||||
cp -R syslinux "$tmp_dir" &> /dev/null
|
cp -R syslinux $tmp_dir &> /dev/null
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
for file in $SYSLINUX_FILES
|
for file in $SYSLINUX_FILES
|
||||||
do
|
do
|
||||||
printf "copying %s\n" "$file"
|
printf "copying %s\n" "$file"
|
||||||
cp "$syslinux_modules_folder/$boot_type/$file" "$syslinux_folder"
|
cp $syslinux_modules_folder/$boot_type/$file $syslinux_folder
|
||||||
done
|
done
|
||||||
|
|
||||||
echo Copying configurations files
|
echo Copying configurations files
|
||||||
create_dir "$tmp_dir/partman_recipes"
|
create_dir $tmp_dir/partman_recipes
|
||||||
cp -R partman_recipes "$tmp_dir" &> /dev/null
|
cp -R partman_recipes $tmp_dir &> /dev/null
|
||||||
create_dir "$tmp_dir/preseeds"
|
create_dir $tmp_dir/preseeds
|
||||||
cp -R preseeds "$tmp_dir" &> /dev/null
|
cp -R preseeds $tmp_dir &> /dev/null
|
||||||
|
|
||||||
if [ -n "$device" ]
|
if [ ! -z $device ]
|
||||||
then
|
then
|
||||||
printf "Partitionning and formating %s\n" "$device"
|
printf "Partitionning and formating %s\n" "$device"
|
||||||
read -p "[WARNING] Disk $device will be erased continue [Y/N]? " -n 1 -r
|
read -p "[WARNING] Disk $device will be erased continue [Y/N]? " -n 1 -r
|
||||||
|
@ -306,31 +301,31 @@ then
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
printf "\n\n"
|
printf "\n\n"
|
||||||
umount_device "$device"
|
umount_device $device
|
||||||
create_dir "$key_mountpoint"
|
create_dir $key_mountpoint
|
||||||
#dd if=/dev/zero of=${dest} bs=512 count=1 conv=notrunc &> /dev/null
|
#dd if=/dev/zero of=${dest} bs=512 count=1 conv=notrunc &> /dev/null
|
||||||
case "$boot_type" in
|
case $boot_type in
|
||||||
"efi64")
|
"efi64")
|
||||||
efi_create_key_structure "$device" "$key_mountpoint"
|
efi_create_key_structure $device $key_mountpoint
|
||||||
;;
|
;;
|
||||||
"bios")
|
"bios")
|
||||||
bios_create_key_structure "$device" "$key_mountpoint"
|
bios_create_key_structure $device $key_mountpoint
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
printf "copying all file to USB drive\n"
|
printf "copying all file to USB drive\n"
|
||||||
cp -R "$tmp_dir"/* "$key_mountpoint"
|
cp -R $tmp_dir/* $key_mountpoint
|
||||||
umount_device "$device"
|
umount_device $device
|
||||||
sleep 5
|
sleep 5
|
||||||
# Make key bootable if bios.
|
# Make key bootable if bios.
|
||||||
if [ "$boot_type" = "bios" ]
|
if [ $boot_type = "bios" ]
|
||||||
then
|
then
|
||||||
# In this mode, we need to write syslinux MBR.
|
# In this mode, we need to write syslinux MBR.
|
||||||
printf "Writing syslinux mbr.ini to %s\n" "$device"
|
printf "Writing syslinux mbr.ini to %s\n" "$device"
|
||||||
dd bs=440 count=1 conv=notrunc if="$syslinux_mbr_bl_folder"/mbr.bin of="$device"
|
dd bs=440 count=1 conv=notrunc if=$syslinux_mbr_bl_folder/mbr.bin of=$device
|
||||||
sleep 2
|
sleep 2
|
||||||
"$SYSLINUX_EXE" --directory /syslinux --install "${device}1"
|
$SYSLINUX_EXE --directory /syslinux --install ${device}1
|
||||||
fi
|
fi
|
||||||
rm -rf "$tmp_dir"
|
rm -rf $TMP_DIR
|
||||||
printf "\nBootable USB key created\n"
|
printf "\nBootable USB key created\n"
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
Reference in a new issue