Unverified Commit d25e18c0 authored by Kroese's avatar Kroese Committed by GitHub
Browse files

feat: Backup installation when switching versions (#1402)

parent ef850e98
Loading
Loading
Loading
Loading
+13 −0
Original line number Diff line number Diff line
@@ -135,6 +135,10 @@ parseVersion() {
    "2003" | "2003r2" | "win2003" | "win2003r2" | "windows2003" | "windows 2003" )
      VERSION="win2003r2"
      ;;
    "nano11" | "nano 11" )
      VERSION="nano11"
      [ -z "$DETECTED" ] && DETECTED="win11x64"
      ;;      
    "core11" | "core 11" )
      VERSION="core11"
      [ -z "$DETECTED" ] && DETECTED="win11x64"
@@ -432,6 +436,7 @@ printVersion() {
    "tiny11"* ) desc="Tiny 11" ;;
    "tiny10"* ) desc="Tiny 10" ;;
    "core11"* ) desc="Core 11" ;;
    "nano11"* ) desc="Nano 11" ;;    
    "win7"* ) desc="Windows 7" ;;
    "win8"* ) desc="Windows 8" ;;
    "win10"* ) desc="Windows 10" ;;
@@ -570,6 +575,9 @@ fromFile() {
    *"winvista"* | *"win_vista"* | *"windowsvista"* | *"windows_vista"* )
      id="winvista${arch}"
      ;;
    "nano11"* | "nano_11"* )
      id="nano11"
      ;;     
    "tiny11core"* | "tiny11_core"* | "tiny_11_core"* )
      id="core11"
      ;;
@@ -1093,6 +1101,11 @@ getLink4() {
  [[ "${lang,,}" != "en" ]] && [[ "${lang,,}" != "en-us" ]] && return 0

  case "${id,,}" in
    "nano11" )
      size=2463565824
      sum="a1e0614372768cbe2d24de74b78a4a97bc1017ea5080dfed1d2125e4a527eb1a"
      url="nano11_25h2/nano11%2025h2.iso"
      ;;
    "core11" )
      size=2159738880
      sum="78f0f44444ff95b97125b43e560a72e0d6ce0a665cf9f5573bf268191e5510c1"
+50 −12
Original line number Diff line number Diff line
@@ -5,6 +5,48 @@ ETFS="boot/etfsboot.com"
FB="falling back to manual installation!"
EFISYS="efi/microsoft/boot/efisys_noprompt.bin"

backup () {

  local count=1
  local iso="$1"
  local name="unknown"
  local root="$STORAGE/backups"
  local previous="$STORAGE/windows.base"

  if [ -f "$previous" ]; then

    previous=$(<"$previous")
    previous="${previous//[![:print:]]/}"

    [ -n "$previous" ] && name="${previous%.*}"

  fi

  mkdir -p "$root"
  local folder="$name"
  local dir="$root/$folder"

  while [ -d "$dir" ]
  do
    count=$((count+1))
    folder="${name}.${count}"
    dir="$root/$folder"
  done

  rm -rf "$dir"
  mkdir -p "$dir"

  [ -f "$iso" ] && mv -f "$iso" "$dir/"
  find "$STORAGE" -maxdepth 1 -type f -iname 'data.*' -not -iname '*.iso' -exec mv -n {} "$dir/" \;
  find "$STORAGE" -maxdepth 1 -type f -iname 'windows.*' -not -iname '*.iso' -exec mv -n {} "$dir/" \;
  find "$STORAGE" -maxdepth 1 -type f \( -iname '*.rom' -or -iname '*.vars' \) -exec mv -n {} "$dir/" \;

  [ -z "$(ls -A "$dir")" ] && rm -rf "$dir"
  [ -z "$(ls -A "$root")" ] && rm -rf "$root"

  return 0
}

skipInstall() {

  local iso="$1"
@@ -45,15 +87,7 @@ skipInstall() {
        fi

        info "Detected that $method, a backup of your previous installation will be saved..."

        local dir="$STORAGE/${previous%.*}.old"

        rm -rf "$dir"
        mkdir -p "$dir"

        [ -f "$STORAGE/$previous" ] && mv -f "$STORAGE/$previous" "$dir/"
        find "$STORAGE" -maxdepth 1 -type f \( -iname '*.rom' -or -iname '*.vars' \) -exec mv -n {} "$dir/" \;
        find "$STORAGE" -maxdepth 1 -type f \( -iname 'data.*' -or -iname 'windows.*' \) -exec mv -n {} "$dir/" \;
        ! backup "$STORAGE/$previous" && error "Backup failed!"

        return 1

@@ -117,6 +151,10 @@ startInstall() {

  skipInstall "$BOOT" && return 1

  if hasDisk; then
    ! backup "" && error "Backup failed!"
  fi

  mkdir -p "$TMP"

  if [ -z "$CUSTOM" ]; then
@@ -132,7 +170,7 @@ startInstall() {

  rm -f "$BOOT"

  find "$STORAGE" -maxdepth 1 -type f -iname 'data.*' -delete
  find "$STORAGE" -maxdepth 1 -type f -iname 'data.*' -not -iname '*.iso' -delete
  find "$STORAGE" -maxdepth 1 -type f -iname 'windows.*' -not -iname '*.iso' -delete
  find "$STORAGE" -maxdepth 1 -type f \( -iname '*.rom' -or -iname '*.vars' \) -delete

@@ -322,7 +360,7 @@ extractESD() {
  fi

  local esdImageCount
  esdImageCount=$(wimlib-imagex info "$iso" | iconv -f UTF-16LE -t UTF-8 | awk '/Image Count:/ {print $3}')
  esdImageCount=$(wimlib-imagex info "$iso" | awk '/Image Count:/ {print $3}')

  if [ -z "$esdImageCount" ]; then
    error "Cannot read the image count in ESD file!" && return 1
@@ -369,7 +407,7 @@ extractESD() {
  fi

  for (( imageIndex=4; imageIndex<=esdImageCount; imageIndex++ )); do
    imageEdition=$(wimlib-imagex info "$iso" ${imageIndex} | iconv -f UTF-16LE -t UTF-8 | grep '^Description:' | sed 's/Description:[ \t]*//')
    imageEdition=$(wimlib-imagex info "$iso" ${imageIndex} | grep '^Description:' | sed 's/Description:[ \t]*//')
    [[ "${imageEdition,,}" != "${edition,,}" ]] && continue
    wimlib-imagex export "$iso" ${imageIndex} "$installWimFile" --compress=LZMS --chunk-size 128K --quiet || {
      retVal=$?