; $VER: 1.0 All Rights Reserved.

(delopts "oknodelete" "force" "askuser")

(onerror

    (exit (quiet))
)

(set app-name "ShowURL")

(set @options

    (askoptions

        (prompt "Select components to install:")

        (help @askoptions-help)

        (default 7)

        (choices

            "Developer material"

            "Library"

            "Configuration"
        )
    )
)

; install library

(if (IN @options 1)

    (copylib

        (prompt "Install shared library ?")

        (source "libs/remote.library")

        (dest "libs:")

        (confirm)

        (help @copylib-help)
    )
)

; install database

(if (IN @options 2)

    (
        (if (getenv "remote.cfg")

            (
                (set @cfgfile (getenv "remote.cfg"))

                ; get rid of LF

                (set @cfgfile (substr @cfgfile 0 (- (strlen @cfgfile) 1)))
            )

            (set @cfgfile "s:remote.ini")
        )

        (if (exists @cfgfile)

            (set @overwrite (askbool

                (prompt "Overwrite existing configuration ?")

                (help (cat "\n"

                    "The configuration file is a database of applications\n"
                    "installed on your computer. It comes preconfigured  \n"
                    "with RA and is updated automatically on an as-needed\n"
                    "basis while RA is used (RA will then scan your hard \n"
                    "disks(s).                                           \n"
                ))

                (default 0)
            ))

            (set @overwrite 1)
        )

        (if (= @overwrite 1)

            (copyfiles

                (source "database/remote.ini")

                (dest (pathonly @cfgfile))

                (newname (fileonly @cfgfile))
            )
        )
    )
)

; install developer material

(if (IN @options 0)

    (
        (if (exists "golded:" (quiet))

            (
                (if (not (exists "golded:developer"))

                    (makedir "golded:developer")
                )

                (set @default-dest "golded:developer")
            )
        )

        (set @default-dest

            (askdir

                (prompt "Choose a directory for installing the developer material. The drawer RA is created in the path you specify:")

                (help @askdir-help)

                (default @default-dest)
            )
        )

        (copyfiles

            (source "developer")

            (dest (tackon @default-dest "ra"))

            (all)
        )

        ; set environment variable

        (run (cat "echo >envarc:remote.cfg " @cfgfile))

        (run (cat "echo >env:remote.cfg " @cfgfile))

        ; delete obsolete files

        (delete (tackon @default-dest "RA/Install"))

        (delete (tackon @default-dest "RA/Install.info"))
    )
)

(exit)

(welcome)
