Unix installer: add support for command-line arguments

Command-line arguments replace interactive prompts, which is
better for scripting runs of the installer.
This commit is contained in:
Matthew Flatt 2014-06-30 11:15:24 +01:00
parent 83e8cfbafe
commit bdccb135e7

View File

@ -1,4 +1,93 @@
###############################################################################
## Command-line flags
show_help() {
echo "Command-line flags:"
echo "/ --unix-style : install as Unix-style"
echo "\ --in-place : install in-place (not Unix-style)"
echo " --dest <path> : install to <path>"
echo " --create-dir : create destination for Unix-style if it does not exist"
echo " --create-links <dir> : create links in <dir> for in-place install"
echo " -h, --help : show this help"
}
where=""
unixstyle=""
accept_dirs=""
SYSDIR=""
SYSDIR_set=""
while test $# -gt 0 ; do
case "$1" in
-h | --help)
show_help
exit 0
;;
--unix-style)
if test "$unixstyle" != "" ; then
echo "conflicting or redundant flag: --unix-style"
exit 1
fi
unixstyle="Y"
accept_dirs="Y"
shift
;;
--in-place)
if test "$unixstyle" != "" ; then
echo "conflicting or redundant flag: --in-place"
exit 1
fi
unixstyle="N"
SYSDIR_set="Y"
shift
;;
--dest)
shift
if test $# -lt 1 ; then
echo "missing path for --dest"
exit 1
fi
where="$1"
if test "$where" = "" ; then
echo "empty path for --dest"
exit 1
fi
shift
;;
--create-dir)
if test "$create_dir" != "" ; then
echo "redundant flag: --create-dir"
exit 1
fi
create_dir="Y"
shift
;;
--create-links)
if test "$SYSDIR" != "" ; then
echo "redundant flag: --create-links"
exit 1
fi
shift
if test $# -lt 1 ; then
echo "missing path for --create-links"
exit 1
fi
SYSDIR="$1"
SYSDIR_set="Y"
if test "$SYSDIR" = "" ; then
echo "empty path for --create-links"
exit 1
fi
shift
;;
*)
echo "unrecognized command-line argument: $1"
exit 1
;;
esac
done
############################################################################### ###############################################################################
## Utilities ## Utilities
@ -91,6 +180,7 @@ echo ""
############################################################################### ###############################################################################
## What kind of installation? ## What kind of installation?
if test "$unixstyle" = ""; then
echo "Do you want a Unix-style distribution?" echo "Do you want a Unix-style distribution?"
echo " In this distribution mode files go into different directories according" echo " In this distribution mode files go into different directories according"
echo " to Unix conventions. A \"racket-uninstall\" script will be generated" echo " to Unix conventions. A \"racket-uninstall\" script will be generated"
@ -116,11 +206,13 @@ while test "$unixstyle" = "x"; do
esac esac
done done
echo "" echo ""
fi
############################################################################### ###############################################################################
## Where do you want it? ## Where do you want it?
## sets $where to the location: target path for wholedir, prefix for unixstyle ## sets $where to the location: target path for wholedir, prefix for unixstyle
if test "$where" = ""; then
if test "$unixstyle" = "Y"; then if test "$unixstyle" = "Y"; then
echo "Where do you want to base your installation of $DISTNAME?" echo "Where do you want to base your installation of $DISTNAME?"
echo " (If you've done such an installation in the past, either" echo " (If you've done such an installation in the past, either"
@ -152,6 +244,7 @@ case "x$where" in
x4 | x. | x./ ) where="`pwd`${TARGET1}" ;; x4 | x. | x./ ) where="`pwd`${TARGET1}" ;;
* ) expand_path_var where ;; * ) expand_path_var where ;;
esac esac
fi
############################################################################### ###############################################################################
## Default system directories prefixed by $1, mimic configure behavior ## Default system directories prefixed by $1, mimic configure behavior
@ -242,6 +335,7 @@ wholedir_install() {
unpack_installation "$where" unpack_installation "$where"
rm_on_abort="" rm_on_abort=""
if test "$SYSDIR_set" != "Y"; then
echo "" echo ""
echo "If you want to install new system links within the \"bin\", \"man\"" echo "If you want to install new system links within the \"bin\", \"man\""
echo " and \"share/applications\" subdirectories of a common directory prefix" echo " and \"share/applications\" subdirectories of a common directory prefix"
@ -250,6 +344,7 @@ wholedir_install() {
echo " but not files." echo " but not files."
echon "(default: skip links) > " echon "(default: skip links) > "
read SYSDIR read SYSDIR
fi
if test "x$SYSDIR" = "x"; then : if test "x$SYSDIR" = "x"; then :
elif test ! -d "$SYSDIR"; then elif test ! -d "$SYSDIR"; then
echo "\"$SYSDIR\" does not exist, skipping links." echo "\"$SYSDIR\" does not exist, skipping links."
@ -312,8 +407,10 @@ unixstyle_install() {
failwith "The entered base directory exists as a file: $where" failwith "The entered base directory exists as a file: $where"
elif test ! -d "$where"; then elif test ! -d "$where"; then
echo "Base directory does not exist: $where" echo "Base directory does not exist: $where"
if test "$create_dir" != "Y"; then
echon " should I create it? (default: yes) " echon " should I create it? (default: yes) "
read R; case "$R" in [nN]* ) abort ;; esac read R; case "$R" in [nN]* ) abort ;; esac
fi
"$mkdir" -p "$where" || failwith "could not create directory: $where" "$mkdir" -p "$where" || failwith "could not create directory: $where"
elif test ! -w "$where"; then elif test ! -w "$where"; then
failwith "The entered base directory is not writable: $where" failwith "The entered base directory is not writable: $where"
@ -324,6 +421,7 @@ unixstyle_install() {
set_dirs "$where" set_dirs "$where"
# loop for possible changes # loop for possible changes
done="N"; retry="N" done="N"; retry="N"
if test "$accept_dirs" = "Y" ; then done="Y"; fi
while test ! "$done" = "Y" || test "x$err" = "xY" ; do while test ! "$done" = "Y" || test "x$err" = "xY" ; do
err="N" err="N"
if test "$retry" = "N"; then if test "$retry" = "N"; then