www

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

installer-header (15172B)


      1 
      2 ###############################################################################
      3 ## Command-line flags
      4 
      5 show_help() {
      6   echo "Command-line flags:"
      7   echo "/ --unix-style : install as Unix-style"
      8   echo "\ --in-place : install in-place (not Unix-style)"
      9   echo "  --dest <path> : install to <path>"
     10   echo "  --create-dir : create destination for Unix-style if it does not exist"
     11   echo "  --create-links <dir> : create links in <dir> for in-place install"
     12   echo "  -h, --help : show this help"
     13 }
     14 
     15 where=""
     16 unixstyle=""
     17 accept_dirs=""
     18 SYSDIR=""
     19 SYSDIR_set=""
     20 
     21 while test $# -gt 0 ; do
     22  case "$1" in
     23   -h | --help)
     24     show_help
     25     exit 0
     26     ;;
     27   --unix-style)
     28     if test "$unixstyle" != "" ; then
     29       echo "conflicting or redundant flag: --unix-style"
     30       exit 1
     31     fi
     32     unixstyle="Y"
     33     accept_dirs="Y"
     34     shift
     35     ;;
     36   --in-place)
     37     if test "$unixstyle" != "" ; then
     38       echo "conflicting or redundant flag: --in-place"
     39       exit 1
     40     fi
     41     unixstyle="N"
     42     SYSDIR_set="Y"
     43     shift
     44     ;;
     45   --dest)
     46     shift
     47     if test $# -lt 1 ; then
     48       echo "missing path for --dest"
     49       exit 1
     50     fi
     51     where="$1"
     52     if test "$where" = "" ; then
     53       echo "empty path for --dest"
     54       exit 1
     55     fi
     56     shift
     57     ;;
     58   --create-dir)
     59     if test "$create_dir" != "" ; then
     60       echo "redundant flag: --create-dir"
     61       exit 1
     62     fi
     63     create_dir="Y"
     64     shift
     65     ;;
     66   --create-links)
     67     if test "$SYSDIR" != "" ; then
     68       echo "redundant flag: --create-links"
     69       exit 1
     70     fi
     71     shift
     72     if test $# -lt 1 ; then
     73       echo "missing path for --create-links"
     74       exit 1
     75     fi
     76     SYSDIR="$1"
     77     SYSDIR_set="Y"
     78     if test "$SYSDIR" = "" ; then
     79       echo "empty path for --create-links"
     80       exit 1
     81     fi
     82     shift
     83     ;;
     84   *)
     85     echo "unrecognized command-line argument: $1"
     86     exit 1
     87   ;;
     88  esac
     89 done
     90 
     91 ###############################################################################
     92 ## Utilities
     93 
     94 PATH=/usr/bin:/bin
     95 
     96 if test "x`echo -n`" = "x-n"; then
     97   echon() { /bin/echo "$*\c"; }
     98 else
     99   echon() { echo -n "$*"; }
    100 fi
    101 
    102 rm_on_abort=""
    103 failwith() {
    104   err="Error: "
    105   if test "x$1" = "x-noerror"; then err=""; shift; fi
    106   echo "$err$*" 1>&2
    107   if test ! "x$rm_on_abort" = "x" && test -e "$rm_on_abort"; then
    108     echon "  (Removing installation files in $rm_on_abort)"
    109     "$rm" -rf "$rm_on_abort"
    110     echo ""
    111   fi
    112   exit 1
    113 }
    114 # intentional aborts
    115 abort() { failwith -noerror "Aborting installation."; }
    116 # unexpected exits
    117 exithandler() { echo ""; failwith "Aborting..."; }
    118 
    119 trap exithandler 2 3 9 15
    120 
    121 lookfor() {
    122   saved_IFS="${IFS}"
    123   IFS=":"
    124   for dir in $PATH; do
    125     if test -x "$dir/$1"; then
    126       eval "$1=$dir/$1"
    127       IFS="$saved_IFS"
    128       return
    129     fi
    130   done
    131   IFS="$saved_IFS"
    132   failwith "could not find \"$1\"."
    133 }
    134 
    135 lookfor rm
    136 lookfor ls
    137 lookfor ln
    138 lookfor tail
    139 lookfor cksum
    140 lookfor tar
    141 lookfor gunzip
    142 lookfor mkdir
    143 lookfor basename
    144 lookfor dirname
    145 
    146 # substitute env vars and tildes
    147 expand_path_var() {
    148   eval "expanded_val=\"\$$1\""
    149   first_part="${expanded_val%%/*}"
    150   if [ "x$first_part" = "x$expanded_val" ]; then
    151     rest_parts=""
    152   else
    153     rest_parts="/${expanded_val#*/}"
    154   fi
    155   case "x$first_part" in
    156     x*" "* ) ;;
    157     x~* ) expanded_val="`eval \"echo $first_part\"`$rest_parts" ;;
    158   esac
    159   eval "$1=\"$expanded_val\""
    160 }
    161 
    162 # Need this to make new `tail' respect old-style command-line arguments.  Can't
    163 # use `tail -n #' because some old tails won't know what to do with that.
    164 _POSIX2_VERSION=199209
    165 export _POSIX2_VERSION
    166 
    167 origwd="`pwd`"
    168 installer_file="$0"
    169 cat_installer() {
    170   oldwd="`pwd`"; cd "$origwd"
    171   "$tail" +"$BINSTARTLINE" "$installer_file"
    172   cd "$oldwd"
    173 }
    174 
    175 echo "This program will extract and install $DISTNAME."
    176 echo ""
    177 echo "Note: the required diskspace for this installation is $ORIGSIZE."
    178 echo ""
    179 
    180 ###############################################################################
    181 ## What kind of installation?
    182 
    183 if test "$unixstyle" = ""; then
    184   echo "Do you want a Unix-style distribution?"
    185   echo "  In this distribution mode files go into different directories according"
    186   echo "  to Unix conventions.  A \"racket-uninstall\" script will be generated"
    187   echo "  to be used when you want to remove the installation.  If you say 'no',"
    188   echo "  the whole Racket directory is kept in a single installation directory"
    189   echo "  (movable and erasable), possibly with external links into it -- this is"
    190   echo "  often more convenient, especially if you want to install multiple"
    191   echo "  versions or keep it in your home directory."
    192   if test ! "x$RELEASED" = "xyes"; then
    193     echo "*** This is a non-release build: such a Unix-style distribution is NOT"
    194     echo "*** recommended, because it cannot be used to install multiple versions"
    195     echo "*** in the default location."
    196   fi
    197   unixstyle="x"
    198   while test "$unixstyle" = "x"; do
    199     echon "Enter yes/no (default: no) > "
    200     read unixstyle
    201     case "$unixstyle" in
    202       [yY]* ) unixstyle="Y" ;;
    203       [nN]* ) unixstyle="N" ;;
    204       "" )    unixstyle="N" ;;
    205       * )     unixstyle="x" ;;
    206     esac
    207   done
    208   echo ""
    209 fi
    210 
    211 ###############################################################################
    212 ## Where do you want it?
    213 ## sets $where to the location: target path for wholedir, prefix for unixstyle
    214 
    215 if test "$where" = ""; then
    216   if test "$unixstyle" = "Y"; then
    217     echo "Where do you want to base your installation of $DISTNAME?"
    218     echo "  (If you've done such an installation in the past, either"
    219     echo "   enter the same directory, or run 'racket-uninstall' manually.)"
    220     TARGET1="..."
    221   else
    222     echo "Where do you want to install the \"$TARGET\" directory tree?"
    223     TARGET1="$TARGET"
    224   fi
    225   echo "  1 - /usr/$TARGET1 [default]"
    226   echo "  2 - /usr/local/$TARGET1"
    227   echo "  3 - ~/$TARGET1 ($HOME/$TARGET1)"
    228   echo "  4 - ./$TARGET1 (here)"
    229   if test "$unixstyle" = "Y"; then
    230     echo "  Or enter a different directory prefix to install in."
    231   else
    232     echo "  Or enter a different \"racket\" directory to install in."
    233   fi
    234   echon "> "
    235   read where
    236 
    237   # numeric choice (make "." and "./" synonym for 4)
    238   if test "$unixstyle" = "Y"; then TARGET1=""
    239   else TARGET1="/$TARGET"; fi
    240   case "x$where" in
    241     x | x1 ) where="/usr$TARGET1" ;;
    242     x2     ) where="/usr/local${TARGET1}" ;;
    243     x3     ) where="${HOME}${TARGET1}" ;;
    244     x4 | x. | x./ ) where="`pwd`${TARGET1}" ;;
    245     * ) expand_path_var where ;;
    246   esac
    247 fi
    248 
    249 ###############################################################################
    250 ## Default system directories prefixed by $1, mimic configure behavior
    251 ## used for unixstyle targets and for wholedir links
    252 
    253 set_dirs() {
    254   # unixstyle: uses all of these
    255   # wholedir: uses only bindir, mandir, and appsdir, no need for the others
    256   bindir="$1/bin"
    257   libdir="$1/lib"
    258   incrktdir="$1/include/$TARGET"
    259   librktdir="$1/lib/$TARGET"
    260   sharerktdir="$1/share/$TARGET"
    261   configdir="$1/etc/$TARGET"
    262   appsdir="$1/share/applications"
    263   has_share="N"
    264   if test -d "$1/share"; then has_share="Y"; fi
    265   if test "$has_share" = "N" && test -d "$1/doc"; then docdir="$1/doc/$TARGET"
    266   else docdir="$1/share/$TARGET/doc"
    267   fi
    268   if test "$has_share" = "N" && test -d "$1/man"; then mandir="$1/man"
    269   else mandir="$1/share/man"
    270   fi
    271 }
    272 
    273 ###############################################################################
    274 ## Integrity check and unpack into $1
    275 ## also sets $INSTDIR to the directory in its canonical form
    276 
    277 unpack_installation() {
    278   T="$1"
    279   # integrity check
    280   echo ""
    281   echon "Checking the integrity of the binary archive... "
    282   SUM="`cat_installer | \"$cksum\"`" || failwith "problems running cksum."
    283   SUM="`set $SUM; echo $1`"
    284   test "$BINSUM" = "$SUM" || failwith "bad CRC checksum."
    285   echo "ok."
    286   # test that the target does not exists
    287   here="N"
    288   if test -d "$T" || test -f "$T"; then
    289     if test -d "$T" && test -x "$T"; then
    290       # use the real name, so "/foo/.." shows as an explicit "/"
    291       oldwd="`pwd`"; cd "$T"; T="`pwd`"; cd "$oldwd"
    292     fi
    293     if test -f "$T"; then echon "\"$T\" exists (as a file)"
    294     elif test ! "`pwd`" = "$T"; then echon "\"$T\" exists"
    295     else here="Y"; echon "\"$T\" is where you ran the installer from"
    296     fi
    297     echon ", delete? "
    298     read R
    299     case "$R" in
    300       [yY]* )
    301         echon "Deleting old \"$T\"... "
    302         "$rm" -rf "$T" || failwith "could not delete \"$T\"."
    303         echo "done."
    304         ;;
    305       * ) abort ;;
    306     esac
    307   fi
    308   # unpack
    309   rm_on_abort="$T"
    310   "$mkdir" -p "$T" || failwith "could not create directory: $T"
    311   if test "$here" = "Y"; then
    312     cd "$T"; INSTDIR="$T"
    313     echo "*** Note: your original directory was deleted, so you will need"
    314     echo "*** to 'cd' back into it when the installer is done, otherwise"
    315     echo "*** it will look like you have an empty directory."
    316     sleep 1
    317   else oldwd="`pwd`"; cd "$T"; INSTDIR="`pwd`"; cd "$oldwd"
    318   fi
    319   rm_on_abort="$INSTDIR"
    320   echo "Unpacking into \"$INSTDIR\" (Ctrl+C to abort)..."
    321   cat_installer | "$gunzip" -c \
    322     | { cd "$INSTDIR"
    323         "$tar" xf - || failwith "problems during unpacking of binary archive."
    324       }
    325   test -d "$INSTDIR/collects" \
    326     || failwith "unpack failed (could not find \"$T/collects\")."
    327   echo "Done."
    328 }
    329 
    330 ###############################################################################
    331 ## Whole-directory installations
    332 
    333 wholedir_install() {
    334 
    335   unpack_installation "$where"
    336   rm_on_abort=""
    337 
    338   if test "$SYSDIR_set" != "Y"; then
    339     echo ""
    340     echo "If you want to install new system links within the \"bin\", \"man\""
    341     echo "  and \"share/applications\" subdirectories of a common directory prefix"
    342     echo "  (for example, \"/usr/local\") then enter the prefix of an existing"
    343     echo "  directory that you want to use.  This might overwrite existing symlinks,"
    344     echo "  but not files."
    345     echon "(default: skip links) > "
    346     read SYSDIR
    347   fi
    348   if test "x$SYSDIR" = "x"; then :
    349   elif test ! -d "$SYSDIR"; then
    350     echo "\"$SYSDIR\" does not exist, skipping links."
    351   elif test ! -x "$SYSDIR" || test ! -w "$SYSDIR"; then
    352     echo "\"$SYSDIR\" is not writable, skipping links."
    353   else
    354     oldwd="`pwd`"; cd "$SYSDIR"; SYSDIR="`pwd`"; cd "$oldwd"
    355     set_dirs "$SYSDIR"
    356     install_links() { # tgtdir(absolute) srcdir(relative to INSTDIR)
    357       if ! test -d "$1"; then
    358         echo "\"$1\" does not exist, skipping."
    359       elif ! test -x "$1" || ! test -w "$1"; then
    360         echo "\"$1\" is not writable, skipping"
    361       else
    362         echo "Installing links in \"$1\"..."
    363         printsep="  "
    364         cd "$1"
    365         for x in `cd "$INSTDIR/$2"; ls`; do
    366           echon "${printsep}$x"; printsep=", "
    367           if test -h "$x"; then rm -f "$x"; fi
    368           if test -d "$x" || test -f "$x"; then
    369             echon " skipped (non-link exists)"
    370           elif ! "$ln" -s "$INSTDIR/$2/$x" "$x"; then
    371             echon " skipped (symlink failed)"
    372           fi
    373         done
    374         echo ""; echo "  done."
    375       fi
    376     }
    377     install_links "$bindir" "bin"
    378     install_links "$mandir/man1" "man/man1"
    379     install_links "$appsdir" "share/applications"
    380   fi
    381 
    382 }
    383 
    384 ###############################################################################
    385 ## Unix-style installations
    386 
    387 dir_createable() {
    388   tdir="`\"$dirname\" \"$1\"`"
    389   if test -d "$tdir" && test -x "$tdir" && test -w "$tdir"; then return 0
    390   elif test "$tdir" = "/"; then return 1
    391   else dir_createable "$tdir"; fi
    392 }
    393 show_dir_var() {
    394   if   test -f   "$2"; then status="error: not a directory!"; err="Y"
    395   elif test ! -d "$2"; then
    396     if dir_createable "$2"; then status="will be created"
    397     else                    status="error: not writable!"; err="Y"; fi
    398   elif test ! -w "$2"; then status="error: not writable!"; err="Y"
    399   else                      status="exists"
    400   fi
    401   echo "  $1 $2 ($status)"
    402 }
    403 
    404 unixstyle_install() {
    405 
    406   if test -f "$where"; then
    407     failwith "The entered base directory exists as a file: $where"
    408   elif test ! -d "$where"; then
    409     echo "Base directory does not exist: $where"
    410     if test "$create_dir" != "Y"; then
    411       echon "  should I create it? (default: yes) "
    412       read R; case "$R" in [nN]* ) abort ;; esac
    413     fi
    414     "$mkdir" -p "$where" || failwith "could not create directory: $where"
    415   elif test ! -w "$where"; then
    416     failwith "The entered base directory is not writable: $where"
    417   fi
    418   cd "$where" || failwith "Base directory does not exist: $where"
    419   where="`pwd`"; cd "$origwd"
    420 
    421   set_dirs "$where"
    422   # loop for possible changes
    423   done="N"; retry="N"
    424   if test "$accept_dirs" = "Y" ; then done="Y"; fi
    425   while test ! "$done" = "Y" || test "x$err" = "xY" ; do
    426     err="N"
    427     if test "$retry" = "N"; then
    428       echo ""
    429       echo "Target Directories:"
    430       show_dir_var "[e] Executables   " "$bindir"
    431       show_dir_var "[o] Libraries     " "$librktdir"
    432       show_dir_var "[s] Shared files  " "$sharerktdir"
    433       show_dir_var "[c] Configuration " "$configdir"
    434       show_dir_var "[d] Documentation " "$docdir"
    435       show_dir_var "[a] .desktop files" "$appsdir"
    436       show_dir_var "[m] Man Pages     " "$mandir"
    437       show_dir_var "[l] C Libraries   " "$libdir"
    438       show_dir_var "[h] C headers     " "$incrktdir"
    439       echo "Enter a letter to change an entry, or enter to continue."
    440     fi
    441     retry="N"
    442     echon "> "; read change_what
    443     read_dir() {
    444       echon "New directory (absolute or relative to $where): "; read new_dir
    445       expand_path_var new_dir
    446       case "$new_dir" in
    447         "/"* ) eval "$1=\"$new_dir\"" ;;
    448         *    ) eval "$1=\"$where/$new_dir\"" ;;
    449       esac
    450     }
    451     case "$change_what" in
    452       [eE]* ) read_dir bindir ;;
    453       [dD]* ) read_dir docdir ;;
    454       [lL]* ) read_dir libdir ;;
    455       [hH]* ) read_dir incrktdir ;;
    456       [oO]* ) read_dir librktdir ;;
    457       [sS]* ) read_dir sharerktdir ;;
    458       [cC]* ) read_dir configdir ;;
    459       [aA]* ) read_dir appsdir ;;
    460       [mM]* ) read_dir mandir ;;
    461       ""    ) if test "$err" = "N"; then done="Y"
    462               else echo "*** Please fix erroneous paths to proceed"; fi ;;
    463       *     ) retry="Y" ;;
    464     esac
    465   done
    466 
    467   if test -x "$bindir/racket-uninstall"; then
    468     echo ""
    469     echo "A previous Racket uninstaller is found at"
    470     echo "  \"$bindir/racket-uninstall\","
    471     echon "  should I run it? (default: yes) "
    472     read R
    473     case "$R" in
    474       [nN]* ) abort ;;
    475       * ) echon "  running uninstaller..."
    476           "$bindir/racket-uninstall" || failwith "problems during uninstall"
    477           echo " done." ;;
    478     esac
    479   fi
    480 
    481   tmp="$where/$TARGET-tmp-install"
    482   if test -f "$tmp" || test -d "$tmp"; then
    483     echo "\"$tmp\" already exists (needed for the installation),"
    484     echon "  ok to remove it? "
    485     read R; case "$R" in [yY]* ) "$rm" -rf "$tmp" ;; * ) abort ;; esac
    486   fi
    487   unpack_installation "$tmp"
    488 
    489   cd "$where"
    490   "$tmp/bin/racket" "$tmp/collects/setup/unixstyle-install.rkt" \
    491     "move" "$tmp" "$bindir" "$sharerktdir/collects" "$docdir" "$libdir" \
    492     "$incrktdir" "$librktdir" "$sharerktdir" "$configdir" "$appsdir" "$mandir" \
    493     || failwith "installation failed"
    494 
    495 }
    496 
    497 ###############################################################################
    498 ## Run the right installer now
    499 
    500 if test "$unixstyle" = "Y"; then unixstyle_install; else wholedir_install; fi
    501 
    502 echo ""
    503 echo "Installation complete."
    504 
    505 exit
    506 
    507 ========== tar.gz file follows ==========