5 Commits
Author SHA1 Message Date
ValdikSS 86bfabe76f Check that ISO file and device exist 2018-05-27 12:37:16 +03:00
ValdikSS 1821638f34 Set partition label as ISO label. Fixes #4 2018-05-27 12:36:46 +03:00
ValdikSS 208609e09c Fix detection of install.wim > 4GiB 2018-05-07 19:23:56 +03:00
ValdikSS 618f507a0a Handle relative paths before running pkexec
Fixes #1
2018-05-05 02:33:06 +03:00
ValdikSS b2977a144b README update 2018-05-01 13:57:44 +03:00
2 changed files with 41 additions and 7 deletions
+2
View File
@@ -21,6 +21,8 @@ Download latest [portable AppImage version](https://github.com/ValdikSS/windows2
The program prints removable storage list if no arguments supplied. The program prints removable storage list if no arguments supplied.
If you don't want to use AppImage, you'll need to install all dependencies and download [uefi-ntfs.img](https://github.com/pbatard/rufus/tree/master/res/uefi) from Rufus project.
### BIOS Boot ### BIOS Boot
BIOS Boot (Legacy Boot/UEFI-CSM) uses stock Windows 7 MBR and NTFS bootloader, courtesy of [ms-sys](http://ms-sys.sourceforge.net/) project. BIOS Boot (Legacy Boot/UEFI-CSM) uses stock Windows 7 MBR and NTFS bootloader, courtesy of [ms-sys](http://ms-sys.sourceforge.net/) project.
+39 -7
View File
@@ -24,6 +24,20 @@ function check_requirements() {
done done
} }
function check_iso_and_device() {
if [ ! -f "$1" ]
then
echo "${bold} == ERROR: ISO file not found! ==${normal}"
exit 106
fi
if [ ! -b "$2" ]
then
echo "${bold} == ERROR: Device file not found! ==${normal}"
exit 107
fi
}
function list_removable_drives() { function list_removable_drives() {
lsblk -d -I 8 -o RM,NAME,SIZE,MODEL | \ lsblk -d -I 8 -o RM,NAME,SIZE,MODEL | \
awk '($1 == 1) {print "/dev/" substr($0, index($0, $2))}' awk '($1 == 1) {print "/dev/" substr($0, index($0, $2))}'
@@ -39,8 +53,12 @@ function format_drive() {
fi fi
} }
function get_iso_name() {
7z l "$1" | awk '/Comment = / {print $3; exit 0}'
}
function check_installwim_gt4gib() { function check_installwim_gt4gib() {
7z l "$1" | awk '($6 ~ /install.wim/) {if ($4 > 429496296) {exit 1}; exit}' 7z l "$1" | awk '($6 ~ /install.wim/) {if ($4 > 4294967296) {exit 0}; exit 1}'
} }
function create_partitions() { function create_partitions() {
@@ -140,13 +158,23 @@ if [[ "$EUID" == "0" ]];
then then
dev="$1" dev="$1"
isopath="$2" isopath="$2"
isolabel=""
labeltype="$3" labeltype="$3"
uefimode= uefimode=
[[ "$labeltype" == "gpt" ]] && uefimode=1 [[ "$labeltype" == "gpt" ]] && uefimode=1
[[ "$labeltype" == "gptntfs" ]] && uefimode=1 [[ "$labeltype" == "gptntfs" ]] && uefimode=1
partpath="$(mktemp -d /run/windows2usb.XXXXXXXXXX)"
check_requirements check_requirements
check_iso_and_device "$isopath" "$dev"
isolabel="$(get_iso_name "$isopath")"
if [ $? -ne 0 ]
then
isolabel=""
fi
echo "${bold} == Working with ISO $isolabel ==${normal}"
partpath="$(mktemp -d /run/windows2usb.XXXXXXXXXX)"
trap sigint_handler INT EXIT trap sigint_handler INT EXIT
# MBR # MBR
@@ -157,7 +185,7 @@ then
echo "${bold} == Creating NTFS partition ==${normal}" echo "${bold} == Creating NTFS partition ==${normal}"
create_partitions "dos" "$dev" create_partitions "dos" "$dev"
mkfs.ntfs -f "$(get_dev_partition_num "${dev}" "1")" mkfs.ntfs -L "$isolabel" -f "$(get_dev_partition_num "${dev}" "1")"
echo "${bold} == Writing bootloader ==${normal}" echo "${bold} == Writing bootloader ==${normal}"
ms-sys -7 "${dev}" ms-sys -7 "${dev}"
@@ -182,7 +210,7 @@ then
echo "${bold} == Creating UEFI FAT partition ==${normal}" echo "${bold} == Creating UEFI FAT partition ==${normal}"
create_partitions "gpt" "$dev" create_partitions "gpt" "$dev"
mkfs.vfat "$(get_dev_partition_num "${dev}" "1")" mkfs.vfat -n "${isolabel:0:11}" "$(get_dev_partition_num "${dev}" "1")"
echo "${bold} == Mounting data partition ==${normal}" echo "${bold} == Mounting data partition ==${normal}"
mount "$(get_dev_partition_num "${dev}" "1")" "$partpath" mount "$(get_dev_partition_num "${dev}" "1")" "$partpath"
@@ -196,7 +224,7 @@ then
echo "${bold} == Creating UEFI FAT and Microsoft NTFS partitions ==${normal}" echo "${bold} == Creating UEFI FAT and Microsoft NTFS partitions ==${normal}"
create_partitions "gptntfs" "$dev" create_partitions "gptntfs" "$dev"
write_uefintfs "$(get_dev_partition_num "${dev}" "1")" write_uefintfs "$(get_dev_partition_num "${dev}" "1")"
mkfs.ntfs -f "$(get_dev_partition_num "${dev}" "2")" mkfs.ntfs -L "$isolabel" -f "$(get_dev_partition_num "${dev}" "2")"
echo "${bold} == Mounting data partition ==${normal}" echo "${bold} == Mounting data partition ==${normal}"
mount "$(get_dev_partition_num "${dev}" "2")" "$partpath" mount "$(get_dev_partition_num "${dev}" "2")" "$partpath"
@@ -226,12 +254,16 @@ else
if [[ "$APPIMAGE" ]]; if [[ "$APPIMAGE" ]];
then then
scriptpath="$APPIMAGE" scriptpath="$APPIMAGE"
fi; fi
[ -f "$1" ] && PARAM1="$(readlink -f -- "$1")" || PARAM1="$1"
[ -f "$2" ] && PARAM2="$(readlink -f -- "$2")" || PARAM2="$2"
shift; shift;
privescs=(pkexec sudo) privescs=(pkexec sudo)
for privesc in ${privescs[*]}; do for privesc in ${privescs[*]}; do
if command -v "$privesc" > /dev/null; then if command -v "$privesc" > /dev/null; then
"$privesc" "$scriptpath" "$@" "$privesc" "$scriptpath" "$PARAM1" "$PARAM2" "$@"
exit exit
fi fi
done done