| #!/bin/bash |
| # Copyright 2018 The Fuchsia Authors. All rights reserved. |
| # Use of this source code is governed by a BSD-style license that can be |
| # found in the LICENSE file. |
| # |
| # Make a symlink, handling the case where the source is a directory |
| # by removing the source first. |
| # "ln -sf" doesn't work in this case: the symbolic link is placed in the |
| # directory named LINK-NAME. |
| # For paranoia purposes, this script only works if the basename of |
| # TARGET and LINK-NAME are "goroot". This is to avoid accidents resulting |
| # in rm -rf removing way more than intended. |
| |
| set -e |
| |
| if [[ $# != 2 ]] |
| then |
| echo >&2 "Usage: $(basename $0) TARGET LINK-NAME" |
| exit 1 |
| fi |
| |
| declare -r TARGET=$1 |
| declare -r LINK_NAME=$2 |
| |
| if [[ $(basename "$TARGET") != "goroot" ]] |
| then |
| echo >&2 "TARGET basename is not goroot" |
| exit 1 |
| fi |
| if [[ $(basename "$LINK_NAME") != "goroot" ]] |
| then |
| echo >&2 "LINK-NAME basename is not goroot" |
| exit 1 |
| fi |
| |
| /bin/rm -rf "$LINK_NAME" |
| /bin/ln -s "$TARGET" "$LINK_NAME" |