Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Verify files are not empty #65

Merged
merged 3 commits into from
Apr 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
FROM scratch
COPY --from=qemux/qemu-arm:1.09 / /
COPY --from=qemux/qemu-arm:1.10 / /

ARG DEBCONF_NOWARNINGS "yes"
ARG DEBIAN_FRONTEND "noninteractive"
Expand Down
31 changes: 17 additions & 14 deletions src/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ hasDisk() {

[ -b "${DEVICE:-}" ] && return 0

if [ -f "$STORAGE/data.img" ] || [ -f "$STORAGE/data.qcow2" ]; then
if [ -s "$STORAGE/data.img" ] || [ -s "$STORAGE/data.qcow2" ]; then
return 0
fi

Expand Down Expand Up @@ -172,6 +172,8 @@ startInstall() {

else

rm -f "$STORAGE/$BASE"

if skipInstall; then
BASE=""
VGA="virtio-gpu"
Expand Down Expand Up @@ -237,7 +239,7 @@ getESD() {

cd /run

if [ ! -f "$dir/products.xml" ]; then
if [ ! -s "$dir/products.xml" ]; then
error "Failed to find products.xml!" && return 1
fi

Expand Down Expand Up @@ -312,7 +314,7 @@ downloadImage() {
fKill "progress.sh"
(( rc != 0 )) && error "Failed to download $url , reason: $rc" && exit 60

[ ! -f "$iso" ] && return 1
[ ! -s "$iso" ] && return 1

html "Download finished successfully..."
return 0
Expand Down Expand Up @@ -467,7 +469,7 @@ detectImage() {

if [ -n "$DETECTED" ]; then

if [ -f "/run/assets/$DETECTED.xml" ]; then
if [ -s "/run/assets/$DETECTED.xml" ]; then
[[ "$MANUAL" != [Yy1]* ]] && XML="$DETECTED.xml"
return 0
fi
Expand Down Expand Up @@ -495,9 +497,9 @@ detectImage() {
fi

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)
[ ! -s "$loc" ] && loc=$(find "$src" -maxdepth 1 -type f -iname install.esd | head -n 1)

if [ ! -f "$loc" ]; then
if [ ! -s "$loc" ]; then
warn "failed to locate 'install.wim' or 'install.esd' in ISO image, $FB"
return 0
fi
Expand All @@ -524,7 +526,7 @@ detectImage() {
desc=$(printVersion "$DETECTED")
[ -z "$desc" ] && desc="$DETECTED"

if [ -f "/run/assets/$DETECTED.xml" ]; then
if [ -s "/run/assets/$DETECTED.xml" ]; then
[[ "$MANUAL" != [Yy1]* ]] && XML="$DETECTED.xml"
info "Detected: $desc"
else
Expand All @@ -539,7 +541,7 @@ prepareImage() {
local iso="$1"
local dir="$2"

if [ -f "$dir/$ETFS" ] && [ -f "$dir/$EFISYS" ]; then
if [ -s "$dir/$ETFS" ] && [ -s "$dir/$EFISYS" ]; then
return 0
fi

Expand All @@ -559,7 +561,7 @@ updateImage() {
local asset="/run/assets/$3"
local path src loc index result

[ ! -f "$asset" ] && return 0
[ ! -s "$asset" ] && return 0

path=$(find "$dir" -maxdepth 1 -type f -iname autounattend.xml | head -n 1)
[ -n "$path" ] && cp "$asset" "$path"
Expand All @@ -572,9 +574,9 @@ updateImage() {
fi

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)
[ ! -s "$loc" ] && loc=$(find "$src" -maxdepth 1 -type f -iname boot.esd | head -n 1)

if [ ! -f "$loc" ]; then
if [ ! -s "$loc" ]; then
warn "failed to locate 'boot.wim' or 'boot.esd' in ISO image, $FB"
return 1
fi
Expand Down Expand Up @@ -626,14 +628,14 @@ buildImage() {

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
[ -f "$log" ] && echo "$(<"$log")"
[ -s "$log" ] && echo "$(<"$log")"
return 1
fi

local error=""
local hide="Warning: creating filesystem that does not conform to ISO-9660."

[ -f "$log" ] && error="$(<"$log")"
[ -s "$log" ] && error="$(<"$log")"
[[ "$error" != "$hide" ]] && echo "$error"

if [ -f "$STORAGE/$BASE" ]; then
Expand All @@ -652,7 +654,8 @@ if ! startInstall; then
return 0
fi

if [ ! -f "$ISO" ]; then
if [ ! -s "$ISO" ]; then
rm -f "$ISO"
if ! downloadImage "$ISO" "$VERSION"; then
error "Failed to download $VERSION"
exit 61
Expand Down
14 changes: 7 additions & 7 deletions src/power.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ _trap() {
ready() {

[ -f "$STORAGE/windows.boot" ] && return 0
[ ! -f "$QEMU_PTY" ] && return 1
[ ! -s "$QEMU_PTY" ] && return 1

local line="Windows Boot Manager"
if grep -Fq "$line" "$QEMU_PTY"; then
Expand All @@ -42,7 +42,7 @@ finish() {

touch "$QEMU_END"

if [ -f "$QEMU_PID" ]; then
if [ -s "$QEMU_PID" ]; then

pid=$(<"$QEMU_PID")
error "Forcefully terminating Windows, reason: $reason..."
Expand All @@ -51,7 +51,7 @@ finish() {
while isAlive "$pid"; do
sleep 1
# Workaround for zombie pid
[ ! -f "$QEMU_PID" ] && break
[ ! -s "$QEMU_PID" ] && break
done
fi

Expand All @@ -64,7 +64,7 @@ finish() {
fi

pid="/var/run/tpm.pid"
[ -f "$pid" ] && pKill "$(<"$pid")"
[ -s "$pid" ] && pKill "$(<"$pid")"

fKill "wsdd"
fKill "smbd"
Expand All @@ -81,7 +81,7 @@ terminal() {

local dev=""

if [ -f "$QEMU_OUT" ]; then
if [ -s "$QEMU_OUT" ]; then

local msg
msg=$(<"$QEMU_OUT")
Expand Down Expand Up @@ -129,7 +129,7 @@ _graceful_shutdown() {
touch "$QEMU_END"
info "Received $1, sending ACPI shutdown signal..."

if [ ! -f "$QEMU_PID" ]; then
if [ ! -s "$QEMU_PID" ]; then
error "QEMU PID file does not exist?"
finish "$code" && return "$code"
fi
Expand Down Expand Up @@ -158,7 +158,7 @@ _graceful_shutdown() {

! isAlive "$pid" && break
# Workaround for zombie pid
[ ! -f "$QEMU_PID" ] && break
[ ! -s "$QEMU_PID" ] && break

info "Waiting for Windows to shutdown... ($cnt/$QEMU_TIMEOUT)"

Expand Down