Skip to content

Commit

Permalink
feat: Extract temporary files to RAM (#195)
Browse files Browse the repository at this point in the history
  • Loading branch information
kroese authored Oct 12, 2024
1 parent 8de285a commit d3a2b0b
Showing 1 changed file with 23 additions and 23 deletions.
46 changes: 23 additions & 23 deletions src/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,7 @@ detectImage() {

if [[ "${LANGUAGE,,}" != "en" ]] && [[ "${LANGUAGE,,}" != "en-"* ]]; then
language=$(getLanguage "$LANGUAGE" "desc")
desc=+" ($language)"
desc+=" ($language)"
fi

info "Detected: $desc"
Expand Down Expand Up @@ -712,18 +712,20 @@ addDriver() {
addDrivers() {

local src="$1"
local file="$2"
local index="$3"
local version="$4"
local tmp="$2"
local file="$3"
local index="$4"
local version="$5"
local drivers="$tmp/drivers"

rm -rf "$drivers"
mkdir -p "$drivers"

local msg="Adding drivers to image..."
info "$msg" && html "$msg"

local drivers="$TMP/drivers"
mkdir -p "$drivers"

if ! tar -xf /drivers.txz -C "$drivers" --warning=no-timestamp; then
error "Failed to extract driver!" && return 1
error "Failed to extract drivers from archive!" && return 1
fi

local target="\$WinPEDriver\$"
Expand All @@ -738,8 +740,8 @@ addDrivers() {
# Disable temporarily : addDriver "$version" "$drivers" "$target" "smbus"
addDriver "$version" "$drivers" "$target" "qxldod"
addDriver "$version" "$drivers" "$target" "viorng"
addDriver "$version" "$drivers" "$target" "viomem"
addDriver "$version" "$drivers" "$target" "viostor"
addDriver "$version" "$drivers" "$target" "viomem"
addDriver "$version" "$drivers" "$target" "NetKVM"
addDriver "$version" "$drivers" "$target" "Balloon"
addDriver "$version" "$drivers" "$target" "vioscsi"
Expand Down Expand Up @@ -797,6 +799,7 @@ updateImage() {
local dir="$1"
local asset="$2"
local language="$3"
local tmp="/run/shm/img"
local file="autounattend.xml"
local org="${file//.xml/.org}"
local dat="${file//.xml/.dat}"
Expand All @@ -812,6 +815,9 @@ updateImage() {
fi
fi

rm -rf "$tmp"
mkdir -p "$tmp"

src=$(find "$dir" -maxdepth 1 -type d -iname sources | head -n 1)

if [ ! -d "$src" ]; then
Expand All @@ -832,33 +838,30 @@ updateImage() {
index="2"
fi

if ! addDrivers "$src" "$wim" "$index" "$DETECTED"; then
if ! addDrivers "$src" "$tmp" "$wim" "$index" "$DETECTED"; then
error "Failed to add drivers to image!" && return 1
fi

if ! addFolder "$src"; then
error "Failed to add OEM folder to image!" && return 1
fi

if wimlib-imagex extract "$wim" "$index" "/$file" "--dest-dir=$TMP" >/dev/null 2>&1; then
if ! wimlib-imagex extract "$wim" "$index" "/$dat" "--dest-dir=$TMP" >/dev/null 2>&1; then
if ! wimlib-imagex extract "$wim" "$index" "/$org" "--dest-dir=$TMP" >/dev/null 2>&1; then
if wimlib-imagex extract "$wim" "$index" "/$file" "--dest-dir=$tmp" >/dev/null 2>&1; then
if ! wimlib-imagex extract "$wim" "$index" "/$dat" "--dest-dir=$tmp" >/dev/null 2>&1; then
if ! wimlib-imagex extract "$wim" "$index" "/$org" "--dest-dir=$tmp" >/dev/null 2>&1; then
if ! wimlib-imagex update "$wim" "$index" --command "rename /$file /$org" > /dev/null; then
warn "failed to backup original answer file ($file)."
fi
fi
fi
rm -f "$TMP/$dat"
rm -f "$TMP/$org"
rm -f "$TMP/$file"
fi

if [[ "$MANUAL" != [Yy1]* ]]; then

xml=$(basename "$asset")
info "Adding $xml for automatic installation..."

local answer="$TMP/$xml"
local answer="$tmp/$xml"
cp "$asset" "$answer"
updateXML "$answer" "$language"

Expand All @@ -869,22 +872,18 @@ updateImage() {
wimlib-imagex update "$wim" "$index" --command "add $answer /$dat" > /dev/null || true
fi

rm -f "$answer"

fi

if [[ "$MANUAL" == [Yy1]* ]]; then

wimlib-imagex update "$wim" "$index" --command "delete --force /$file" > /dev/null || true

if wimlib-imagex extract "$wim" "$index" "/$org" "--dest-dir=$TMP" >/dev/null 2>&1; then
if ! wimlib-imagex update "$wim" "$index" --command "add $TMP/$org /$file" > /dev/null; then
if wimlib-imagex extract "$wim" "$index" "/$org" "--dest-dir=$tmp" >/dev/null 2>&1; then
if ! wimlib-imagex update "$wim" "$index" --command "add $tmp/$org /$file" > /dev/null; then
warn "failed to restore original answer file ($org)."
fi
fi

rm -f "$TMP/$org"

fi

local find="$file"
Expand All @@ -899,6 +898,7 @@ updateImage() {
fi
fi

rm -rf "$tmp"
return 0
}

Expand Down

0 comments on commit d3a2b0b

Please sign in to comment.