Skip to content

Closes #279: use $CARGO_HOME as default location if defined #280

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 20 additions & 20 deletions ci/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Options:
--crate NAME Name of the crate to install (default <repository name>)
--tag TAG Tag (version) of the crate to install (default <latest release>)
--target TARGET Install the release compiled for $TARGET (default <`rustc` host>)
--to LOCATION Where to install the binary (default ~/.cargo/bin)
--to LOCATION Where to install the binary (default '$CARGO_HOME' if defined, otherwise '~/.cargo/bin')
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
--to LOCATION Where to install the binary (default '$CARGO_HOME' if defined, otherwise '~/.cargo/bin')
--to LOCATION Where to install the binary (default '$CARGO_HOME/bin' if defined, otherwise '~/.cargo/bin')

More context is in the comment below.

EOF
}

Expand All @@ -29,16 +29,16 @@ say_err() {
}

err() {
if [ ! -z $td ]; then
rm -rf $td
if [ ! -z "$td" ]; then
rm -rf "$td"
fi

say_err "ERROR $1"
exit 1
}

need() {
if ! command -v $1 > /dev/null 2>&1; then
if ! command -v "$1" > /dev/null 2>&1; then
err "need $1 (command not found)"
fi
}
Expand Down Expand Up @@ -88,49 +88,49 @@ need mktemp
need tar

# Optional dependencies
if [ -z $crate ] || [ -z $tag ] || [ -z $target ]; then
if [ -z "$crate" ] || [ -z "$tag" ] || [ -z "$target" ]; then
need cut
fi

if [ -z $tag ]; then
if [ -z "$tag" ]; then
need rev
fi

if [ -z $target ]; then
if [ -z "$target" ]; then
need grep
need rustc
fi

if [ -z $git ]; then
if [ -z "$git" ]; then
err 'must specify a git repository using `--git`. Example: `install.sh --git japaric/cross`'
fi

url="https://github.com/$git"
say_err "GitHub repository: $url"

if [ -z $crate ]; then
crate=$(echo $git | cut -d'/' -f2)
if [ -z "$crate" ]; then
crate=$(echo "$git" | cut -d'/' -f2)
fi

say_err "Crate: $crate"

url="$url/releases"

if [ -z $tag ]; then
if [ -z "$tag" ]; then
tag=$(curl -s "$url/latest" | cut -d'"' -f2 | rev | cut -d'/' -f1 | rev)
say_err "Tag: latest ($tag)"
else
say_err "Tag: $tag"
fi

if [ -z $target ]; then
if [ -z "$target" ]; then
target=$(rustc -Vv | grep host | cut -d' ' -f2)
fi

say_err "Target: $target"

if [ -z $dest ]; then
dest="$HOME/.cargo/bin"
if [ -z "$dest" ]; then
dest="${CARGO_HOME:-$HOME/.cargo/bin}"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't seem correct as per the definition of $CARGO_HOME.

This seems more like it.

Suggested change
dest="${CARGO_HOME:-$HOME/.cargo/bin}"
dest="${CARGO_HOME:-$HOME/.cargo}/bin"

What do you think?

fi

say_err "Installing to: $dest"
Expand All @@ -139,17 +139,17 @@ url="$url/download/$tag/$crate-$tag-$target.tar.gz"

say_err "Downloading: $url"
td=$(mktemp -d || mktemp -d -t tmp)
curl -sL $url | tar -C $td -xz
curl -sL "$url" | tar -C "$td" -xz

for f in $(cd $td && find . -type f); do
test -x $td/$f || continue
for f in $(cd "$td" && find . -type f); do
test -x "$td/$f" || continue

if [ -e "$dest/$f" ] && [ $force = false ]; then
err "$f already exists in $dest"
else
mkdir -p $dest
install -v -m 755 $td/$f $dest
mkdir -p "$dest"
install -v -m 755 "$td/$f" "$dest"
fi
done

rm -rf $td
rm -rf "$td"
Loading