@@ -335,7 +335,7 @@ set -o errexit
335335shopt -s extglob
336336
337337short_options=' yhvp:'
338- long_options=' disable-confirmation,no-modify-profile,no-install-system-deps,help,version,platform:'
338+ long_options=' disable-confirmation,no-modify-profile,no-install-system-deps,help,version,platform:,overwrite '
339339
340340args=$( getopt --options " $short_options " --longoptions " $long_options " --name " swiftly-install" -- " ${@ } " )
341341eval " set -- ${args} "
@@ -351,14 +351,18 @@ USAGE:
351351 swiftly-install [options]
352352
353353OPTIONS:
354- -y, --disable-confirmation Disable confirmation prompt .
354+ -y, --disable-confirmation Disable confirmation prompts .
355355 --no-modify-profile Do not attempt to modify the profile file to set environment
356356 variables (e.g. PATH) on login.
357357 --no-install-system-deps Do not attempt to install Swift's required system dependencies.
358358 -p, --platform <platform> Specifies which platform's toolchains swiftly will download. If
359359 unspecified, the platform will be automatically detected. Available
360360 options are "ubuntu22.04", "ubuntu20.04", "ubuntu18.04", "rhel9", and
361361 "amazonlinux2".
362+ --overwrite Overwrite the existing swiftly installation found at the configured
363+ SWIFTLY_HOME, if any. If this option is unspecified and an existing
364+ installation is found, the swiftly executable will be updated, but
365+ the rest of the installation will not be modified.
362366 -h, --help Prints help information.
363367 --version Prints version information.
364368EOF
415419 shift 2
416420 ;;
417421
422+ " --overwrite" )
423+ overwrite_existing_intallation=" true"
424+ shift
425+ ;;
426+
418427 --)
419428 shift
420429 break
@@ -535,19 +544,14 @@ while [ -z "$DISABLE_CONFIRMATION" ]; do
535544done
536545
537546if [[ -d " $HOME_DIR " ]]; then
538- if [[ " $DISABLE_CONFIRMATION " == " true" ]]; then
547+ detected_existing_installation=" true"
548+ if [[ " $overwrite_existing_intallation " == " true" ]]; then
539549 echo " Overwriting existing swiftly installation at $( replace_home_path $HOME_DIR ) "
550+ find $BIN_DIR -lname " $HOME_DIR /toolchains/**/bin/*" -delete
551+ rm -r $HOME_DIR
540552 else
541- echo " Existing swiftly installation detected at $( replace_home_path $HOME_DIR ) , overwrite? (Y/n)"
542-
543- read_yn_input " true"
544- if [[ " $READ_INPUT_RETURN " == " false" ]]; then
545- echo " Cancelling installation."
546- exit 0
547- fi
553+ echo " Updating existing swiftly installation at $( replace_home_path $HOME_DIR ) "
548554 fi
549-
550- rm -r $HOME_DIR
551555fi
552556
553557mkdir -p $HOME_DIR /toolchains
@@ -566,35 +570,37 @@ curl \
566570
567571chmod +x " $BIN_DIR /swiftly"
568572
569- echo " $JSON_OUT " > " $HOME_DIR /config.json"
573+ if [[ " $detected_existing_installation " != " true" || " $overwrite_existing_intallation " == " true" ]]; then
574+ echo " $JSON_OUT " > " $HOME_DIR /config.json"
570575
571- # Verify the downloaded executable works. The script will exit if this fails due to errexit.
572- SWIFTLY_HOME_DIR=" $HOME_DIR " SWIFTLY_BIN_DIR=" $BIN_DIR " " $BIN_DIR /swiftly" --version > /dev/null
576+ # Verify the downloaded executable works. The script will exit if this fails due to errexit.
577+ SWIFTLY_HOME_DIR=" $HOME_DIR " SWIFTLY_BIN_DIR=" $BIN_DIR " " $BIN_DIR /swiftly" --version > /dev/null
573578
574- ENV_OUT=$( cat << EOF
579+ ENV_OUT=$( cat << EOF
575580export SWIFTLY_HOME_DIR="$( replace_home_path $HOME_DIR ) "
576581export SWIFTLY_BIN_DIR="$( replace_home_path $BIN_DIR ) "
577582if [[ ":\$ PATH:" != *":\$ SWIFTLY_BIN_DIR:"* ]]; then
578583 export PATH="\$ SWIFTLY_BIN_DIR:\$ PATH"
579584fi
580585EOF
581- )
586+ )
582587
583- echo " $ENV_OUT " > " $HOME_DIR /env.sh"
588+ echo " $ENV_OUT " > " $HOME_DIR /env.sh"
584589
585- if [[ " $MODIFY_PROFILE " == " true" ]]; then
586- SOURCE_LINE=" . $( replace_home_path $HOME_DIR ) /env.sh"
590+ if [[ " $MODIFY_PROFILE " == " true" ]]; then
591+ SOURCE_LINE=" . $( replace_home_path $HOME_DIR ) /env.sh"
587592
588- # Only append the line if it isn't in .profile already.
589- if [[ ! -f " $PROFILE_FILE " ]] || [[ ! " $( cat $PROFILE_FILE ) " =~ " $SOURCE_LINE " ]]; then
590- echo " $SOURCE_LINE " >> " $PROFILE_FILE "
593+ # Only append the line if it isn't in .profile already.
594+ if [[ ! -f " $PROFILE_FILE " ]] || [[ ! " $( cat $PROFILE_FILE ) " =~ " $SOURCE_LINE " ]]; then
595+ echo " $SOURCE_LINE " >> " $PROFILE_FILE "
596+ fi
591597 fi
592- fi
593598
594- if [[ " $SWIFTLY_INSTALL_SYSTEM_DEPS " != " false" ]]; then
595- echo " "
596- echo " Installing Swift's system dependencies via $package_manager (note: this may require root access)..."
597- install_system_deps
599+ if [[ " $SWIFTLY_INSTALL_SYSTEM_DEPS " != " false" ]]; then
600+ echo " "
601+ echo " Installing Swift's system dependencies via $package_manager (note: this may require root access)..."
602+ install_system_deps
603+ fi
598604fi
599605
600606echo " "
0 commit comments