make_win_usb: Test if passed args exists in the system.

This commit is contained in:
Jeremy Gardais 2015-11-17 22:06:17 +01:00
parent b502997d5e
commit bcd72aaffd
1 changed files with 16 additions and 8 deletions

View File

@ -2,25 +2,33 @@
# Source: http://admincloud.net/116/creer-une-cle-usb-bootable-de-windows-sous-linux/ # Source: http://admincloud.net/116/creer-une-cle-usb-bootable-de-windows-sous-linux/
WIN_HDD="${1}" WIN_USB="${1}"
WIN_USB_MNT_PATH=/mnt/USBW7/ WIN_USB_MNT_PATH=/mnt/USBW7/
WIN_ISO_FILE="${2}" WIN_ISO_FILE="${2}"
WIN_ISO_MNT_PATH=/mnt/WIN7/ WIN_ISO_MNT_PATH=/mnt/WIN7/
# Test if args exists
for file in "${WIN_USB}" "${WIN_ISO_FILE}"; do
if [ ! -e "${file}" ]; then
printf '%b' "${file} doesn't exists. Please check your args.\n"
exit 1
fi
done
# Empty MBR # Empty MBR
sudo dd if=/dev/zero of=${WIN_HDD} bs=446 count=1 sudo dd if=/dev/zero of=${WIN_USB} bs=446 count=1
# Ensure to have a MS-DOS partition table # Ensure to have a MS-DOS partition table
sudo parted ${WIN_HDD} mklabel msdos sudo parted ${WIN_USB} mklabel msdos
# Create one big partition with "boot" flag then format in NFTS # Create one big partition with "boot" flag then format in NFTS
sudo parted ${WIN_HDD} mkpart primary 0% 100MS-partition table sudo parted ${WIN_USB} mkpart primary 0% 100MS-partition table
sudo parted ${WIN_HDD} set 1 boot on sudo parted ${WIN_USB} set 1 boot on
sudo mkfs.ntfs ${WIN_HDD}1 --fast --no-indexing sudo mkfs.ntfs ${WIN_USB}1 --fast --no-indexing
# Mount USB key # Mount USB key
sudo mkdir -p -- "${WIN_USB_MNT_PATH}" sudo mkdir -p -- "${WIN_USB_MNT_PATH}"
sudo mount ${WIN_HDD}1 "${WIN_USB_MNT_PATH}" sudo mount ${WIN_USB}1 "${WIN_USB_MNT_PATH}"
# Mount ISO file # Mount ISO file
sudo mkdir -p -- "${WIN_ISO_MNT_PATH}" sudo mkdir -p -- "${WIN_ISO_MNT_PATH}"
@ -54,6 +62,6 @@ if [ ! $(command -v ms-sys) ]; then
fi fi
# For Win 7/8 # For Win 7/8
sudo ms-sys --mbr7 "${WIN_HDD}" sudo ms-sys --mbr7 "${WIN_USB}"
exit 0 exit 0