2 # Copyright 2014 The Rust Project Developers. See the COPYRIGHT
3 # file at the top-level directory of this distribution and at
4 # http://rust-lang.org/COPYRIGHT.
6 # Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
7 # http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
8 # <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
9 # option. This file may not be copied, modified, or distributed
10 # except according to those terms.
23 echo "install: WARNING: $1"
27 echo "install: error: $1"
39 if command -v $1 >/dev
/null
2>&1
51 printf "install: %-20s := %.35s ...\n" $1 "$T"
53 printf "install: %-20s := %s %s\n" $1 "$T" "$2"
58 VAL_OPTIONS
="$VAL_OPTIONS $1"
67 local UOP
=$
(echo $OP |
tr '[:lower:]' '[:upper:]' |
tr '\-' '\_')
72 if echo "$arg" |
grep -q -- "--$OP="
74 val
=$
(echo "$arg" | cut
-f2 -d=)
84 OP
="${OP}=[${DEFAULT}]"
85 printf " --%-30s %s\n" "$OP" "$DOC"
90 BOOL_OPTIONS
="$BOOL_OPTIONS $1"
111 if [ "$arg" = "--${FLAG}-${OP}" ]
113 OP
=$
(echo $OP |
tr 'a-z-' 'A-Z_')
114 FLAG
=$
(echo $FLAG |
tr 'a-z' 'A-Z')
115 local V
="CFG_${FLAG}_${OP}"
125 printf " --%-30s %s\n" "$FLAG-$OP" "$DOC"
130 BOOL_OPTIONS
="$BOOL_OPTIONS $1"
140 if [ "$arg" = "--${OP}" ]
142 OP
=$
(echo $OP |
tr 'a-z-' 'A-Z_')
153 printf " --%-30s %s\n" "$OP" "$DOC"
161 for option
in $BOOL_OPTIONS
163 if test --disable-$option = $arg
167 if test --enable-$option = $arg
171 if test --$option = $arg
176 for option
in $VAL_OPTIONS
178 if echo "$arg" |
grep -q -- "--$option="
183 if [ "$arg" = "--help" ]
186 echo "No more help available for Configure options,"
187 echo "check the Wiki or join our IRC channel"
190 if test $isArgValid -eq 0
192 err
"Option '$arg' is not recognized"
200 FILE_PATH_DIRNAME
="$(dirname ${FILE_PATH})"
201 FILE_PATH_BASENAME
="$(basename ${FILE_PATH})"
202 FILE_ABS_PATH
="$(cd ${FILE_PATH_DIRNAME} && pwd)"
203 FILE_PATH
="${FILE_ABS_PATH}/${FILE_PATH_BASENAME}"
204 # This is the return value
205 ABSOLUTIFIED
="${FILE_PATH}"
208 msg
"looking for install programs"
220 CFG_SRC_DIR
="$(cd $(dirname $0) && pwd)"
225 if [ "$1" = "--help" ]
230 echo "Usage: $CFG_SELF [options]"
235 step_msg
"processing $CFG_SELF args"
238 # Check for mingw or cygwin in order to special case $CFG_LIBDIR_RELATIVE.
239 # This logic is duplicated from configure in order to get the correct libdir
240 # for Windows installs.
241 CFG_OSTYPE
=$
(uname
-s)
246 CFG_OSTYPE
=unknown-linux-gnu
250 CFG_OSTYPE
=unknown-freebsd
254 CFG_OSTYPE
=unknown-dragonfly
258 CFG_OSTYPE
=apple-darwin
262 # msys' `uname` does not print gcc configuration, but prints msys
263 # configuration. so we cannot believe `uname -m`:
264 # msys1 is always i686 and msys2 is always x86_64.
265 # instead, msys defines $MSYSTEM which is MINGW32 on i686 and
268 CFG_OSTYPE
=pc-windows-gnu
269 if [ "$MSYSTEM" = MINGW64
]
276 CFG_OSTYPE
=pc-windows-gnu
279 # Thad's Cygwin identifers below
283 CFG_OSTYPE
=pc-windows-gnu
289 CFG_OSTYPE
=pc-windows-gnu
295 CFG_OSTYPE
=pc-windows-gnu
301 CFG_OSTYPE
=pc-windows-gnu
310 if [ "$CFG_OSTYPE" = "pc-windows-gnu" ]
313 CFG_OLD_LD_PATH_VAR
=$PATH
314 elif [ "$CFG_OSTYPE" = "apple-darwin" ]
316 CFG_LD_PATH_VAR
=DYLD_LIBRARY_PATH
317 CFG_OLD_LD_PATH_VAR
=$DYLD_LIBRARY_PATH
319 CFG_LD_PATH_VAR
=LD_LIBRARY_PATH
320 CFG_OLD_LD_PATH_VAR
=$LD_LIBRARY_PATH
323 flag uninstall
"only uninstall from the installation prefix"
324 valopt destdir
"" "set installation root"
325 opt verify
1 "verify that the installed binaries run correctly"
326 valopt prefix
"/usr/local" "set installation prefix"
327 # NB This isn't quite the same definition as in `configure`.
328 # just using 'lib' instead of configure's CFG_LIBDIR_RELATIVE
329 valopt libdir
"${CFG_DESTDIR}${CFG_PREFIX}/lib" "install libraries"
330 valopt mandir
"${CFG_DESTDIR}${CFG_PREFIX}/share/man" "install man pages in PATH"
331 opt ldconfig
1 "run ldconfig after installation (Linux only)"
339 step_msg
"validating $CFG_SELF args"
342 # Template configuration.
343 # These names surrounded by '%%` are replaced by sed when generating install.sh
344 # FIXME: Might want to consider loading this from a file and not generating install.sh
347 TEMPLATE_PRODUCT_NAME
=%%TEMPLATE_PRODUCT_NAME
%%
349 TEMPLATE_VERIFY_BIN
=%%TEMPLATE_VERIFY_BIN
%%
351 TEMPLATE_REL_MANIFEST_DIR
=%%TEMPLATE_REL_MANIFEST_DIR
%%
352 # 'Rust is ready to roll.' or 'Cargo is cool to cruise.'
353 TEMPLATE_SUCCESS_MESSAGE
=%%TEMPLATE_SUCCESS_MESSAGE
%%
354 # Locations to look for directories containing legacy, pre-versioned manifests
355 TEMPLATE_LEGACY_MANIFEST_DIRS
=%%TEMPLATE_LEGACY_MANIFEST_DIRS
%%
356 # The installer version
357 TEMPLATE_RUST_INSTALLER_VERSION
=%%TEMPLATE_RUST_INSTALLER_VERSION
%%
359 # OK, let's get installing ...
361 # If we don't have a verify bin then disable verify
362 if [ -z "$TEMPLATE_VERIFY_BIN" ]; then
366 # Sanity check: can we run the binaries?
367 if [ -z "${CFG_DISABLE_VERIFY}" ]
369 # Don't do this if uninstalling. Failure here won't help in any way.
370 if [ -z "${CFG_UNINSTALL}" ]
372 msg
"verifying platform can run binaries"
373 export $CFG_LD_PATH_VAR="${CFG_SRC_DIR}/lib:$CFG_OLD_LD_PATH_VAR"
374 "${CFG_SRC_DIR}/bin/${TEMPLATE_VERIFY_BIN}" --version 2> /dev
/null
1> /dev
/null
377 err
"can't execute binaries on this platform"
379 export $CFG_LD_PATH_VAR="$CFG_OLD_LD_PATH_VAR"
383 # Sanity check: can we can write to the destination?
384 msg
"verifying destination is writable"
385 umask 022 && mkdir
-p "${CFG_LIBDIR}"
386 need_ok
"can't write to destination. consider \`sudo\`."
387 touch "${CFG_LIBDIR}/rust-install-probe" > /dev
/null
390 err
"can't write to destination. consider \`sudo\`."
392 rm -f "${CFG_LIBDIR}/rust-install-probe"
393 need_ok
"failed to remove install probe"
395 # Sanity check: don't install to the directory containing the installer.
396 # That would surely cause chaos.
397 msg
"verifying destination is not the same as source"
398 INSTALLER_DIR
="$(cd $(dirname $0) && pwd)"
399 PREFIX_DIR
="$(cd ${CFG_PREFIX} && pwd)"
400 if [ "${INSTALLER_DIR}" = "${PREFIX_DIR}" ]
402 err
"can't install to same directory as installer"
405 # Open the components file to get the list of components to install
406 COMPONENTS
=`cat "$CFG_SRC_DIR/components"`
408 # Sanity check: do we have components?
409 if [ ! -n "$COMPONENTS" ]; then
410 err
"unable to find installation components"
413 # Using an absolute path to libdir in a few places so that the status
414 # messages are consistently using absolute paths.
415 absolutify
"${CFG_LIBDIR}"
416 ABS_LIBDIR
="${ABSOLUTIFIED}"
418 # Replace commas in legacy manifest list with spaces
419 LEGACY_MANIFEST_DIRS
=`echo "$TEMPLATE_LEGACY_MANIFEST_DIRS" | sed "s/,/ /g"`
421 # Uninstall from legacy manifests
422 for md
in $LEGACY_MANIFEST_DIRS; do
423 # First, uninstall from the installation prefix.
424 # Errors are warnings - try to rm everything in the manifest even if some fail.
425 if [ -f "$ABS_LIBDIR/$md/manifest" ]
428 # Iterate through installed manifest and remove files
430 # The installed manifest contains absolute paths
431 msg
"removing legacy file $p"
437 warn
"failed to remove $p"
440 warn
"supposedly installed file $p does not exist!"
442 done < "$ABS_LIBDIR/$md/manifest"
444 # If we fail to remove $md below, then the
445 # installed manifest will still be full; the installed manifest
446 # needs to be empty before install.
447 msg
"removing legacy manifest $ABS_LIBDIR/$md/manifest"
448 rm -f "$ABS_LIBDIR/$md/manifest"
449 # For the above reason, this is a hard error
450 need_ok
"failed to remove installed manifest"
452 # Remove $TEMPLATE_REL_MANIFEST_DIR directory
453 msg
"removing legacy manifest dir ${ABS_LIBDIR}/$md"
454 rm -Rf "${ABS_LIBDIR}/$md"
457 warn
"failed to remove $md"
460 UNINSTALLED_SOMETHING
=1
464 # Load the version of the installed installer
465 if [ -f "$ABS_LIBDIR/$TEMPLATE_REL_MANIFEST_DIR/rust-installer-version" ]; then
466 INSTALLED_VERSION
=`cat "$ABS_LIBDIR/$TEMPLATE_REL_MANIFEST_DIR/rust-installer-version"`
469 if [ ! -n "$INSTALLED_VERSION" ]; then err
"rust installer version is empty"; fi
472 # If there's something installed, then uninstall
473 if [ -n "$INSTALLED_VERSION" ]; then
474 # Check the version of the installed installer
475 case "$INSTALLED_VERSION" in
477 # TODO: If this is a previous version, then upgrade in place to the
478 # current version before uninstalling. No need to do this yet because
479 # there is no prior version (only the legacy 'unversioned' installer
480 # which we've already dealt with).
482 # This is the current version. Nothing need to be done except uninstall.
483 "$TEMPLATE_RUST_INSTALLER_VERSION")
486 # TODO: If this is an unknown (future) version then bail.
488 echo "The copy of $TEMPLATE_PRODUCT_NAME at $CFG_PREFIX was installed using an"
489 echo "unknown version ($INSTALLED_VERSION) of rust-installer."
490 echo "Uninstall it first with the installer used for the original installation"
491 echo "before continuing."
496 MD
="$ABS_LIBDIR/$TEMPLATE_REL_MANIFEST_DIR"
497 INSTALLED_COMPONENTS
=`cat $MD/components`
499 # Uninstall (our components only) before reinstalling
500 for available_component
in $COMPONENTS; do
501 for installed_component
in $INSTALLED_COMPONENTS; do
502 if [ "$available_component" = "$installed_component" ]; then
503 COMPONENT_MANIFEST
="$MD/manifest-$installed_component"
505 # Sanity check: there should be a component manifest
506 if [ ! -f "$COMPONENT_MANIFEST" ]; then
507 err
"installed component '$installed_component' has no manifest"
510 # Iterate through installed component manifest and remove files
511 while read directive
; do
513 COMMAND
=`echo $directive | cut -f1 -d:`
514 FILE
=`echo $directive | cut -f2 -d:`
517 if [ ! -n "$COMMAND" ]; then err
"malformed installation directive"; fi
518 if [ ! -n "$FILE" ]; then err
"malformed installation directive"; fi
522 msg
"removing file $FILE"
523 if [ -f "$FILE" ]; then
525 if [ $?
-ne 0 ]; then
526 warn
"failed to remove $FILE"
529 warn
"supposedly installed file $FILE does not exist!"
534 msg
"removing directory $FILE"
536 if [ $?
-ne 0 ]; then
537 warn
"unable to remove directory $FILE"
542 err
"unknown installation directive"
546 done < "$COMPONENT_MANIFEST"
548 # Remove the installed component manifest
549 msg
"removing component manifest $COMPONENT_MANIFEST"
550 rm -f "$COMPONENT_MANIFEST"
551 # This is a hard error because the installation is unrecoverable
552 need_ok
"failed to remove installed manifest for component '$installed_component'"
554 # Update the installed component list
555 MODIFIED_COMPONENTS
=`sed /^$installed_component\$/d $MD/components`
556 echo "$MODIFIED_COMPONENTS" > "$MD/components"
557 need_ok
"failed to update installed component list"
562 # If there are no remaining components delete the manifest directory
563 REMAINING_COMPONENTS
=`cat $MD/components`
564 if [ ! -n "$REMAINING_COMPONENTS" ]; then
565 msg
"removing manifest directory $MD"
567 if [ $?
-ne 0 ]; then
568 warn
"failed to remove $MD"
572 UNINSTALLED_SOMETHING
=1
575 # There's no installed version. If we were asked to uninstall, then that's a problem.
576 if [ -n "${CFG_UNINSTALL}" -a ! -n "$UNINSTALLED_SOMETHING" ]
578 err
"unable to find installation manifest at ${CFG_LIBDIR}/${TEMPLATE_REL_MANIFEST_DIR}"
581 # If we're only uninstalling then exit
582 if [ -n "${CFG_UNINSTALL}" ]
585 echo " ${TEMPLATE_PRODUCT_NAME} is uninstalled."
590 # Create the directory to contain the manifests
591 mkdir
-p "${CFG_LIBDIR}/${TEMPLATE_REL_MANIFEST_DIR}"
592 need_ok
"failed to create ${TEMPLATE_REL_MANIFEST_DIR}"
594 # Install each component
595 for component
in $COMPONENTS; do
597 # The file name of the manifest we're installing from
598 INPUT_MANIFEST
="${CFG_SRC_DIR}/manifest-$component.in"
600 # The installed manifest directory
601 MD
="$ABS_LIBDIR/$TEMPLATE_REL_MANIFEST_DIR"
603 # The file name of the manifest we're going to create during install
604 INSTALLED_MANIFEST
="$MD/manifest-$component"
606 # Create the installed manifest, which we will fill in with absolute file paths
607 touch "${INSTALLED_MANIFEST}"
608 need_ok
"failed to create installed manifest"
610 # Sanity check: do we have our input manifests?
611 if [ ! -f "$INPUT_MANIFEST" ]; then
612 err
"manifest for $component does not exist at $INPUT_MANIFEST"
615 # Now install, iterate through the new manifest and copy files
616 while read directive
; do
618 COMMAND
=`echo $directive | cut -f1 -d:`
619 FILE
=`echo $directive | cut -f2 -d:`
622 if [ ! -n "$COMMAND" ]; then err
"malformed installation directive"; fi
623 if [ ! -n "$FILE" ]; then err
"malformed installation directive"; fi
625 # Decide the destination of the file
626 FILE_INSTALL_PATH
="${CFG_DESTDIR}${CFG_PREFIX}/$FILE"
628 if echo "$FILE" |
grep "^lib/" > /dev
/null
630 f
=`echo $FILE | sed 's/^lib\///'`
631 FILE_INSTALL_PATH
="${CFG_LIBDIR}/$f"
634 if echo "$FILE" |
grep "^share/man/" > /dev
/null
636 f
=`echo $FILE | sed 's/^share\/man\///'`
637 FILE_INSTALL_PATH
="${CFG_MANDIR}/$f"
640 # Make sure there's a directory for it
641 umask 022 && mkdir
-p "$(dirname ${FILE_INSTALL_PATH})"
642 need_ok
"directory creation failed"
644 # Make the path absolute so we can uninstall it later without
645 # starting from the installation cwd
646 absolutify
"${FILE_INSTALL_PATH}"
647 FILE_INSTALL_PATH
="${ABSOLUTIFIED}"
653 msg
"copying file $FILE_INSTALL_PATH"
654 if echo "$FILE" |
grep "^bin/" > /dev
/null
656 install -m755 "${CFG_SRC_DIR}/$FILE" "${FILE_INSTALL_PATH}"
658 install -m644 "${CFG_SRC_DIR}/$FILE" "${FILE_INSTALL_PATH}"
660 need_ok
"file creation failed"
662 # Update the manifest
663 echo "file:${FILE_INSTALL_PATH}" >> "${INSTALLED_MANIFEST}"
664 need_ok
"failed to update manifest"
671 msg
"copying directory $FILE_INSTALL_PATH"
673 # Sanity check: bulk dirs are supposed to be uniquely ours and should not exist
674 if [ -e "$FILE_INSTALL_PATH" ]; then
675 err
"$FILE_INSTALL_PATH already exists"
678 cp -R "$CFG_SRC_DIR/$FILE" "$FILE_INSTALL_PATH"
679 need_ok
"failed to copy directory"
681 # Set permissions. 0755 for dirs, 644 for files
682 chmod -R u
+rwX
,go
+rX
,go-w
"$FILE_INSTALL_PATH"
683 need_ok
"failed to set permissions on directory"
685 # Update the manifest
686 echo "dir:$FILE_INSTALL_PATH" >> "$INSTALLED_MANIFEST"
687 need_ok
"failed to update manifest"
691 err
"unknown installation directive"
694 done < "$INPUT_MANIFEST"
696 # Update the components
697 echo "$component" >> "$MD/components"
698 need_ok
"failed to update components list for $component"
702 # Drop the version number into the manifest dir
703 echo "$TEMPLATE_RUST_INSTALLER_VERSION" > "${ABS_LIBDIR}/${TEMPLATE_REL_MANIFEST_DIR}/rust-installer-version"
705 # Run ldconfig to make dynamic libraries available to the linker
706 if [ "$CFG_OSTYPE" = "unknown-linux-gnu" -a ! -n "$CFG_DISABLE_LDCONFIG" ]; then
707 msg
"running ldconfig"
711 warn
"failed to run ldconfig."
712 warn
"this may happen when not installing as root and may be fine"
716 # Sanity check: can we run the installed binaries?
718 # As with the verification above, make sure the right LD_LIBRARY_PATH-equivalent
719 # is in place. Try first without this variable, and if that fails try again with
720 # the variable. If the second time tries, print a hopefully helpful message to
721 # add something to the appropriate environment variable.
722 if [ -z "${CFG_DISABLE_VERIFY}" ]
724 export $CFG_LD_PATH_VAR="${CFG_PREFIX}/lib:$CFG_OLD_LD_PATH_VAR"
725 "${CFG_PREFIX}/bin/${TEMPLATE_VERIFY_BIN}" --version > /dev
/null
728 ERR
="can't execute installed binaries. "
729 ERR
="${ERR}installation may be broken. "
730 ERR
="${ERR}if this is expected then rerun install.sh with \`--disable-verify\` "
731 ERR
="${ERR}or \`make install\` with \`--disable-verify-install\`"
735 echo " Note: please ensure '${CFG_PREFIX}/lib' is added to ${CFG_LD_PATH_VAR}"
740 echo " ${TEMPLATE_SUCCESS_MESSAGE}"