; $VER: Update-term4.7 1.2 (11.11.96)

(complete 0)

(message (cat "Make sure you are using the most recent version of Installer "
              "(this would be V43.3) or you might have problems updating the "
              "program."
))

(message (cat "This script will update `term' v4.7 to v4.7a. Before the program "
              "is updated, a backup copy of your old v4.7 release will be made "
              "just in case something goes wrong. This requires that you have "
              "at least 600K bytes free storage space available on your hard "
              "disk drive. The script can tell the plain 68k version and the 020+ "
              "version apart, so you do not need to worry about picking the wrong "
              "version."
))

(set original (askfile (prompt "Please locate the `term' v4.7 program")
                       (default "TERM:")
                       (help (cat "Before the installation can proceed "
                                  "you need to indicate where `term' 4.7 "
                                  "was installed."
                       ))
))

(if (<> (exists original (noreq)) 1)
(
    (abort (cat "Could not locate file " original))
))

(set size (getsize original))
(set vers (getversion original))
(set version (/ vers 65536))
(set revision (- vers (* version 65536)))
(set spaceleft (getdiskspace original))

(if (< spaceleft 600000)
(
    (abort (cat ("Not enough storage space left, %ld bytes are available, we need at least 600,000 bytes." spaceleft)))
))

(if (= 0 version)
(
    (abort (cat ("Sorry, %s cannot be patched." original)))
))

(if (and (<> size 552404) (<> size 548168))
(
    (abort (cat ("Hm... %s does not look like `term' v4.7." original)))
))

(if (or (<> version 4) (and (= version 4) (<> revision 7)))
(
    (if (not (askbool (prompt (cat ("This appears to be v%ld.%ld, not v4.7, but I might be wrong. Do you still want to update the program?" version revision))
                 )
                 (help   (cat  "The file could not be safely identified as being `term' v4.7, but "
                               "the Installer may have failed to read the program version number "
                               "correctly. It might be safe to continue as the program to apply "
                               "the patch will have the last word in this matter."
                 ))
                 (default 1)
    )))
    (
        (abort "Your `term' file was not updated.")
    ))
))

(set @default-dest (pathonly original))

(rename original (tackon @default-dest "term-4.7-old"))

(if (= size 548168)
    (set patchfile "term-020-47a.pch")
    (set patchfile "term-any-47a.pch")
)

(working "Updating `term' to v4.7a")

(run ("spatch -o%s -p%s %s" (tackon @default-dest "term") patchfile (tackon @default-dest "term-4.7-old")))

(complete 100)

(message (cat "Keep the old file! Keep it or you might regret it! Subsequent updates might be "
              "based upon the old version"
))

(exit ("Your old %s file was renamed to %s." original (tackon @default-dest "term-4.7-old")))
