; Install Complete
; ----------------
;
; Date: 2021-10-24
; Author: Henrik Noerfjand Stengaard
;
; AmigaDOS script to complete Amiga OS and Kickstart roms installation by rebooting system or quiting UAE.


; create install complete prefs
echo "" >INSTALLDIR:Prefs/Install-Complete

; amiga OS and Kickstart roms installation complete
cls
echo "*e[32m" NOLINE
echo "Amiga OS and Kickstart roms installation complete"
echo "*e[0m*e[1m" NOLINE
echo "-------------------------------------------------"
echo "*e[0m" NOLINE
echo ""

; set uae to 1, if use prefs exists
set uae "0"
IF EXISTS INSTALLDIR:Prefs/UAE
  set uae "1"
ENDIF

; install packages or user packages
set installpackages "0"
IF EXISTS INSTALLDIR:Prefs/Install-Packages
  set installpackages "1"
ELSE
  IF EXISTS INSTALLDIR:Prefs/Install-User-Packages
    set installpackages "1"
  ENDIF
ENDIF

; get amiga os install
set amigaosinstall ""
set amigaosinstall "`type INSTALLDIR:Prefs/Install-Amiga-OS`"

; status message
IF "$amigaosinstall" EQ "Amiga-OS-390"
  echo "HstWB Installer has completed Amiga OS and Kickstart roms"
  IF $uae EQ 1 VAL
    echo "installation and will quit and restart UAE to start"
    echo "installation of Amiga OS 3.9 using Emergency Boot."
  ELSE
    echo "installation and will reboot system to start"
    echo "installation of Amiga OS 3.9 using Emergency Boot."
  ENDIF
ELSE
  ; 
  IF "$installpackages" EQ 1 VAL
    ; Copy assign hstwb installer for installing boing bags
    Copy >NIL: INSTALLDIR:S/Assign-HstWB-Installer SYSTEMDIR:S

    ; Replace workbench startup-sequence with packages startup-sequence
    Rename >NIL: SYSTEMDIR:S/Startup-Sequence SYSTEMDIR:S/Startup-Sequence.Workbench
    Copy >NIL: INSTALLDIR:S/Startup-Sequence.Packages SYSTEMDIR:S/Startup-Sequence

    echo "HstWB Installer has completed Amiga OS and Kickstart roms"
    IF $uae EQ 1 VAL
      echo "installation and will quit and restart UAE to"
      echo "start package and user package installation."
    ELSE
      echo "installation and will reboot system to"
      echo "start package and user package installation."
    ENDIF
  ELSE
    echo "HstWB Installer has completed Amiga OS and Kickstart roms"
    echo "installation and system is now ready for use."
  ENDIF
ENDIF
echo ""

; remove assigns from installdir
Assign >NIL: S: INSTALLDIR:S REMOVE
Assign >NIL: C: INSTALLDIR:C REMOVE
Assign >NIL: Devs: INSTALLDIR:Devs REMOVE
Assign >NIL: L: INSTALLDIR:L REMOVE
Assign >NIL: Libs: INSTALLDIR:Libs REMOVE
Assign >NIL: Prefs: INSTALLDIR:Prefs REMOVE

; copy hstwb installer log to install dir, if it exists
IF EXISTS SYS:hstwb-installer.log
  Copy >NIL: SYS:hstwb-installer.log INSTALLDIR:hstwb-installer.log
ENDIF

; get boing bag install
set boingbaginstall "0"
IF EXISTS INSTALLDIR:Prefs/Install-Amiga-OS-390-BB
  set boingbaginstall "`type INSTALLDIR:Prefs/Install-Amiga-OS-390-BB`"
ENDIF

; replace startup sequence and run install cleanup, if install boing bags, install packages and install user packages prefs doesn't exist
IF "$boingbaginstall" EQ 0 VAL
  IF "$installpackages" EQ 0 VAL
    ; Replace startup-sequence with workbench startup-sequence, if it exists
    IF EXISTS SYSTEMDIR:S/Startup-Sequence.Workbench
      Copy >NIL: SYSTEMDIR:S/Startup-Sequence.Workbench SYSTEMDIR:S/Startup-Sequence
      Delete >NIL: SYSTEMDIR:S/Startup-Sequence.Workbench
    ENDIF

    ; Run install cleanup      
    execute INSTALLDIR:S/Install-Cleanup
  ENDIF
ENDIF

echo "Please let the system wait 10 seconds before continuing"
echo "to allow file system to write changes to disk." 
echo ""

; quit UAE or reboot message
IF $uae EQ 1 VAL
  echo "Continue will quit UAE in 10 seconds."
ELSE
  echo "Continue will reboot system in 10 seconds."
ENDIF

echo ""
ask "Press ENTER to continue"
echo ""

; quit UAE, if UAE is used. Otherwise reboot
IF $uae EQ 1 VAL
  echo "UAE will quit in 10 seconds..."
  wait 10
  UAEquit >NIL:
ELSE
  echo "System will reboot in 10 seconds..."
  wait 10
  TotalReset >NIL:
ENDIF