fix: Check size of downloaded image
This commit is contained in:
parent
2861b65423
commit
cd98d48d8f
1 changed files with 57 additions and 80 deletions
135
src/install.sh
135
src/install.sh
|
|
@ -99,15 +99,13 @@ finishInstall() {
|
||||||
local aborted="$2"
|
local aborted="$2"
|
||||||
|
|
||||||
if [ ! -s "$iso" ] || [ ! -f "$iso" ]; then
|
if [ ! -s "$iso" ] || [ ! -f "$iso" ]; then
|
||||||
error "Failed to find ISO: $iso"
|
error "Failed to find ISO: $iso" && return 1
|
||||||
return 1
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -w "$iso" ] && [[ "$aborted" != [Yy1]* ]]; then
|
if [ -w "$iso" ] && [[ "$aborted" != [Yy1]* ]]; then
|
||||||
# Mark ISO as prepared via magic byte
|
# Mark ISO as prepared via magic byte
|
||||||
if ! printf '\x16' | dd of="$iso" bs=1 seek=0 count=1 conv=notrunc status=none; then
|
if ! printf '\x16' | dd of="$iso" bs=1 seek=0 count=1 conv=notrunc status=none; then
|
||||||
error "Failed to set magic byte!"
|
error "Failed to set magic byte!" && return 1
|
||||||
return 1
|
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
@ -125,17 +123,13 @@ abortInstall() {
|
||||||
|
|
||||||
if [[ "$iso" != "$STORAGE/$BASE" ]]; then
|
if [[ "$iso" != "$STORAGE/$BASE" ]]; then
|
||||||
if ! mv -f "$iso" "$STORAGE/$BASE"; then
|
if ! mv -f "$iso" "$STORAGE/$BASE"; then
|
||||||
error "Failed to move ISO: $iso"
|
error "Failed to move ISO: $iso" && return 1
|
||||||
exit 69
|
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if ! finishInstall "$STORAGE/$BASE" "Y"; then
|
finishInstall "$STORAGE/$BASE" "Y" && return 0
|
||||||
error "Failed to finish installation!"
|
|
||||||
exit 69
|
|
||||||
fi
|
|
||||||
|
|
||||||
return 0
|
return 1
|
||||||
}
|
}
|
||||||
|
|
||||||
startInstall() {
|
startInstall() {
|
||||||
|
|
@ -230,8 +224,7 @@ getESD() {
|
||||||
winCatalog="https://go.microsoft.com/fwlink/?LinkId=841361"
|
winCatalog="https://go.microsoft.com/fwlink/?LinkId=841361"
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
error "Invalid version specified: $VERSION"
|
error "Invalid version specified: $VERSION" && return 1
|
||||||
return 1
|
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
|
|
@ -276,7 +269,7 @@ getESD() {
|
||||||
ESD_URL=$(xmllint --nonet --xpath '//FilePath' "${dir}/esd_edition.xml" | sed -E -e 's/<[\/]?FilePath>//g')
|
ESD_URL=$(xmllint --nonet --xpath '//FilePath' "${dir}/esd_edition.xml" | sed -E -e 's/<[\/]?FilePath>//g')
|
||||||
|
|
||||||
if [ -z "$ESD_URL" ]; then
|
if [ -z "$ESD_URL" ]; then
|
||||||
error "Failed to find ESD url!" && return 1
|
error "Failed to find ESD URL!" && return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
rm -rf "$dir"
|
rm -rf "$dir"
|
||||||
|
|
@ -328,12 +321,15 @@ downloadImage() {
|
||||||
{ wget "$url" -O "$iso" -q --no-check-certificate --show-progress "$progress"; rc=$?; } || :
|
{ wget "$url" -O "$iso" -q --no-check-certificate --show-progress "$progress"; rc=$?; } || :
|
||||||
|
|
||||||
fKill "progress.sh"
|
fKill "progress.sh"
|
||||||
(( rc != 0 )) && error "Failed to download $url , reason: $rc" && exit 60
|
(( rc != 0 )) && error "Failed to download $url , reason: $rc" && return 1
|
||||||
|
|
||||||
[ ! -s "$iso" ] || [ ! -f "$iso" ] && return 1
|
if [ -f "$iso" ]; then
|
||||||
|
if [ $(stat -c%s "$iso") -gt 100000000 ]; then
|
||||||
|
html "Download finished successfully..." && return 0
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
html "Download finished successfully..."
|
error "Failed to download $url" && return 1
|
||||||
return 0
|
|
||||||
}
|
}
|
||||||
|
|
||||||
extractESD() {
|
extractESD() {
|
||||||
|
|
@ -346,22 +342,22 @@ extractESD() {
|
||||||
local msg="Extracting $desc bootdisk..."
|
local msg="Extracting $desc bootdisk..."
|
||||||
info "$msg" && html "$msg"
|
info "$msg" && html "$msg"
|
||||||
|
|
||||||
size=16106127360
|
if [ $(stat -c%s "$iso") -lt 100000000 ]; then
|
||||||
size_gb=$(( (size + 1073741823)/1073741824 ))
|
error "Invalid ESD file: Size is smaller than 100 MB" && return 1
|
||||||
space=$(df --output=avail -B 1 "$TMP" | tail -n 1)
|
|
||||||
space_gb=$(( (space + 1073741823)/1073741824 ))
|
|
||||||
|
|
||||||
if ((size<10000000)); then
|
|
||||||
error "Invalid ESD file: Size is smaller than 10 MB" && exit 62
|
|
||||||
fi
|
|
||||||
|
|
||||||
if (( size > space )); then
|
|
||||||
error "Not enough free space in $STORAGE, have $space_gb GB available but need at least $size_gb GB." && exit 63
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
rm -rf "$dir"
|
rm -rf "$dir"
|
||||||
mkdir -p "$dir"
|
mkdir -p "$dir"
|
||||||
|
|
||||||
|
size=16106127360
|
||||||
|
size_gb=$(( (size + 1073741823)/1073741824 ))
|
||||||
|
space=$(df --output=avail -B 1 "$dir" | tail -n 1)
|
||||||
|
space_gb=$(( (space + 1073741823)/1073741824 ))
|
||||||
|
|
||||||
|
if (( size > space )); then
|
||||||
|
error "Not enough free space in $STORAGE, have $space_gb GB available but need at least $size_gb GB." && return 1
|
||||||
|
fi
|
||||||
|
|
||||||
local esdImageCount
|
local esdImageCount
|
||||||
esdImageCount=$(wimlib-imagex info "${iso}" | awk '/Image Count:/ {print $3}')
|
esdImageCount=$(wimlib-imagex info "${iso}" | awk '/Image Count:/ {print $3}')
|
||||||
|
|
||||||
|
|
@ -402,8 +398,7 @@ extractESD() {
|
||||||
edition="10 pro"
|
edition="10 pro"
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
error "Invalid version specified: $VERSION"
|
error "Invalid version specified: $VERSION" && return 1
|
||||||
return 1
|
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
|
|
@ -417,8 +412,7 @@ extractESD() {
|
||||||
return 0
|
return 0
|
||||||
done
|
done
|
||||||
|
|
||||||
error "Failed to find product in install.wim!"
|
error "Failed to find product in install.wim!" && return 1
|
||||||
return 1
|
|
||||||
}
|
}
|
||||||
|
|
||||||
extractImage() {
|
extractImage() {
|
||||||
|
|
@ -429,12 +423,8 @@ extractImage() {
|
||||||
local size size_gb space space_gb
|
local size size_gb space space_gb
|
||||||
|
|
||||||
if [[ "${iso,,}" == *".esd" ]]; then
|
if [[ "${iso,,}" == *".esd" ]]; then
|
||||||
if ! extractESD "$iso" "$dir"; then
|
extractESD "$iso" "$dir" && return 0
|
||||||
rm -f "$iso"
|
return 1
|
||||||
error "Failed to extract ESD file!"
|
|
||||||
exit 67
|
|
||||||
fi
|
|
||||||
return 0
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ "$EXTERNAL" != [Yy1]* ]] && [ -z "$CUSTOM" ]; then
|
if [[ "$EXTERNAL" != [Yy1]* ]] && [ -z "$CUSTOM" ]; then
|
||||||
|
|
@ -446,25 +436,26 @@ extractImage() {
|
||||||
[ -n "$CUSTOM" ] && msg="Extracting local ISO image..."
|
[ -n "$CUSTOM" ] && msg="Extracting local ISO image..."
|
||||||
info "$msg" && html "$msg"
|
info "$msg" && html "$msg"
|
||||||
|
|
||||||
|
rm -rf "$dir"
|
||||||
|
mkdir -p "$dir"
|
||||||
|
|
||||||
size=$(stat -c%s "$iso")
|
size=$(stat -c%s "$iso")
|
||||||
size_gb=$(( (size + 1073741823)/1073741824 ))
|
size_gb=$(( (size + 1073741823)/1073741824 ))
|
||||||
space=$(df --output=avail -B 1 "$TMP" | tail -n 1)
|
space=$(df --output=avail -B 1 "$dir" | tail -n 1)
|
||||||
space_gb=$(( (space + 1073741823)/1073741824 ))
|
space_gb=$(( (space + 1073741823)/1073741824 ))
|
||||||
|
|
||||||
if ((size<10000000)); then
|
if ((size<100000000)); then
|
||||||
error "Invalid ISO file: Size is smaller than 10 MB" && exit 62
|
error "Invalid ISO file: Size is smaller than 100 MB" && return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if (( size > space )); then
|
if (( size > space )); then
|
||||||
error "Not enough free space in $STORAGE, have $space_gb GB available but need at least $size_gb GB." && exit 63
|
error "Not enough free space in $STORAGE, have $space_gb GB available but need at least $size_gb GB." && return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
rm -rf "$dir"
|
rm -rf "$dir"
|
||||||
|
|
||||||
if ! 7z x "$iso" -o"$dir" > /dev/null; then
|
if ! 7z x "$iso" -o"$dir" > /dev/null; then
|
||||||
rm -f "$iso"
|
error "Failed to extract ISO file: $iso" && return 1
|
||||||
error "Failed to extract ISO file!"
|
|
||||||
exit 66
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
|
|
@ -508,16 +499,14 @@ detectImage() {
|
||||||
src=$(find "$dir" -maxdepth 1 -type d -iname sources | head -n 1)
|
src=$(find "$dir" -maxdepth 1 -type d -iname sources | head -n 1)
|
||||||
|
|
||||||
if [ ! -d "$src" ]; then
|
if [ ! -d "$src" ]; then
|
||||||
warn "failed to locate 'sources' folder in ISO image, $FB"
|
warn "failed to locate 'sources' folder in ISO image, $FB" && return 1
|
||||||
return 0
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
loc=$(find "$src" -maxdepth 1 -type f -iname install.wim | head -n 1)
|
loc=$(find "$src" -maxdepth 1 -type f -iname install.wim | head -n 1)
|
||||||
[ ! -f "$loc" ] && loc=$(find "$src" -maxdepth 1 -type f -iname install.esd | head -n 1)
|
[ ! -f "$loc" ] && loc=$(find "$src" -maxdepth 1 -type f -iname install.esd | head -n 1)
|
||||||
|
|
||||||
if [ ! -f "$loc" ]; then
|
if [ ! -f "$loc" ]; then
|
||||||
warn "failed to locate 'install.wim' or 'install.esd' in ISO image, $FB"
|
warn "failed to locate 'install.wim' or 'install.esd' in ISO image, $FB" && return 1
|
||||||
return 0
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
tag="DISPLAYNAME"
|
tag="DISPLAYNAME"
|
||||||
|
|
@ -535,8 +524,7 @@ detectImage() {
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -z "$DETECTED" ]; then
|
if [ -z "$DETECTED" ]; then
|
||||||
warn "failed to determine Windows version from string '$name', $FB"
|
warn "failed to determine Windows version from string '$name', $FB" && return 0
|
||||||
return 0
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
desc=$(printVersion "$DETECTED")
|
desc=$(printVersion "$DETECTED")
|
||||||
|
|
@ -585,16 +573,14 @@ updateImage() {
|
||||||
src=$(find "$dir" -maxdepth 1 -type d -iname sources | head -n 1)
|
src=$(find "$dir" -maxdepth 1 -type d -iname sources | head -n 1)
|
||||||
|
|
||||||
if [ ! -d "$src" ]; then
|
if [ ! -d "$src" ]; then
|
||||||
warn "failed to locate 'sources' folder in ISO image, $FB"
|
warn "failed to locate 'sources' folder in ISO image, $FB" && return 1
|
||||||
return 1
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
loc=$(find "$src" -maxdepth 1 -type f -iname boot.wim | head -n 1)
|
loc=$(find "$src" -maxdepth 1 -type f -iname boot.wim | head -n 1)
|
||||||
[ ! -f "$loc" ] && loc=$(find "$src" -maxdepth 1 -type f -iname boot.esd | head -n 1)
|
[ ! -f "$loc" ] && loc=$(find "$src" -maxdepth 1 -type f -iname boot.esd | head -n 1)
|
||||||
|
|
||||||
if [ ! -f "$loc" ]; then
|
if [ ! -f "$loc" ]; then
|
||||||
warn "failed to locate 'boot.wim' or 'boot.esd' in ISO image, $FB"
|
warn "failed to locate 'boot.wim' or 'boot.esd' in ISO image, $FB" && return 1
|
||||||
return 1
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
info "Adding XML file for automatic installation..."
|
info "Adding XML file for automatic installation..."
|
||||||
|
|
@ -607,8 +593,7 @@ updateImage() {
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if ! wimlib-imagex update "$loc" "$index" --command "add $asset /autounattend.xml" > /dev/null; then
|
if ! wimlib-imagex update "$loc" "$index" --command "add $asset /autounattend.xml" > /dev/null; then
|
||||||
warn "failed to add XML to ISO image, $FB"
|
warn "failed to add XML to ISO image, $FB" && return 1
|
||||||
return 1
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
|
|
@ -638,14 +623,13 @@ buildImage() {
|
||||||
space_gb=$(( (space + 1073741823)/1073741824 ))
|
space_gb=$(( (space + 1073741823)/1073741824 ))
|
||||||
|
|
||||||
if (( size > space )); then
|
if (( size > space )); then
|
||||||
error "Not enough free space in $STORAGE, have $space_gb GB available but need at least $size_gb GB."
|
error "Not enough free space in $STORAGE, have $space_gb GB available but need at least $size_gb GB." && return 1
|
||||||
return 1
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if ! genisoimage -o "$out" -b "$ETFS" -no-emul-boot -c "$cat" -iso-level 4 -J -l -D -N -joliet-long -relaxed-filenames -V "$label" \
|
if ! genisoimage -o "$out" -b "$ETFS" -no-emul-boot -c "$cat" -iso-level 4 -J -l -D -N -joliet-long -relaxed-filenames -V "$label" \
|
||||||
-udf -boot-info-table -eltorito-alt-boot -eltorito-boot "$EFISYS" -no-emul-boot -allow-limited-size -quiet "$dir" 2> "$log"; then
|
-udf -boot-info-table -eltorito-alt-boot -eltorito-boot "$EFISYS" -no-emul-boot -allow-limited-size -quiet "$dir" 2> "$log"; then
|
||||||
[ -s "$log" ] && echo "$(<"$log")"
|
[ -s "$log" ] && echo "$(<"$log")"
|
||||||
return 1
|
error "Failed to build image!" && return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
local error=""
|
local error=""
|
||||||
|
|
@ -655,8 +639,7 @@ buildImage() {
|
||||||
[[ "$error" != "$hide" ]] && echo "$error"
|
[[ "$error" != "$hide" ]] && echo "$error"
|
||||||
|
|
||||||
if [ -f "$STORAGE/$BASE" ]; then
|
if [ -f "$STORAGE/$BASE" ]; then
|
||||||
error "File $STORAGE/$BASE does already exist?!"
|
error "File $STORAGE/$BASE does already exist?!" && return 1
|
||||||
return 1
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
mv "$out" "$STORAGE/$BASE"
|
mv "$out" "$STORAGE/$BASE"
|
||||||
|
|
@ -678,39 +661,35 @@ bootWindows() {
|
||||||
######################################
|
######################################
|
||||||
|
|
||||||
if ! startInstall; then
|
if ! startInstall; then
|
||||||
if ! bootWindows; then
|
bootWindows && return 0
|
||||||
error "Failed to boot Windows!"
|
|
||||||
exit 68
|
exit 68
|
||||||
fi
|
|
||||||
return 0
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ ! -s "$ISO" ] || [ ! -f "$ISO" ]; then
|
if [ ! -s "$ISO" ] || [ ! -f "$ISO" ]; then
|
||||||
rm -f "$ISO"
|
|
||||||
if ! downloadImage "$ISO" "$VERSION"; then
|
if ! downloadImage "$ISO" "$VERSION"; then
|
||||||
error "Failed to download $VERSION"
|
rm -f "$ISO"
|
||||||
exit 61
|
exit 61
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if ! extractImage "$ISO" "$DIR"; then
|
if ! extractImage "$ISO" "$DIR"; then
|
||||||
abortInstall "$ISO"
|
rm -f "$ISO"
|
||||||
return 0
|
exit 62
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if ! detectImage "$DIR"; then
|
if ! detectImage "$DIR"; then
|
||||||
abortInstall "$ISO"
|
abortInstall "$ISO" && return 0
|
||||||
return 0
|
exit 60
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if ! prepareImage "$ISO" "$DIR"; then
|
if ! prepareImage "$ISO" "$DIR"; then
|
||||||
abortInstall "$ISO"
|
abortInstall "$ISO" && return 0
|
||||||
return 0
|
exit 60
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if ! updateImage "$ISO" "$DIR" "$XML"; then
|
if ! updateImage "$ISO" "$DIR" "$XML"; then
|
||||||
abortInstall "$ISO"
|
abortInstall "$ISO" && return 0
|
||||||
return 0
|
exit 60
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if ! rm -f "$ISO" 2> /dev/null; then
|
if ! rm -f "$ISO" 2> /dev/null; then
|
||||||
|
|
@ -720,12 +699,10 @@ if ! rm -f "$ISO" 2> /dev/null; then
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if ! buildImage "$DIR"; then
|
if ! buildImage "$DIR"; then
|
||||||
error "Failed to build image!"
|
|
||||||
exit 65
|
exit 65
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if ! finishInstall "$STORAGE/$BASE" "N"; then
|
if ! finishInstall "$STORAGE/$BASE" "N"; then
|
||||||
error "Failed to finish installation!"
|
|
||||||
exit 69
|
exit 69
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue