Skip to content
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

self-update in-place #12

Merged
merged 2 commits into from
Oct 15, 2018
Merged

self-update in-place #12

merged 2 commits into from
Oct 15, 2018

Conversation

fommil
Copy link
Contributor

@fommil fommil commented Oct 15, 2018

Doesn't assume an installation directory.

ghcup Outdated
@@ -994,7 +994,7 @@ while [ $# -gt 0 ] ; do
if [ "${TARGET_LOCATION}" ] ; then
self_update "${TARGET_LOCATION}"
else
self_update "${HOME}/.local/bin"
self_update "$(dirname $0)"
Copy link
Member

@hasufell hasufell Oct 15, 2018

Choose a reason for hiding this comment

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

README.md Outdated
(preferably `~/.local/bin`).

```
wget https://raw.githubusercontent.com/hasufell/ghcup/master/ghcup -O ~/.local/bin/ghcup && chmod 755 ~/.local/bin/ghcup
Copy link
Member

Choose a reason for hiding this comment

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

curl is more portable than wget

@fommil
Copy link
Contributor Author

fommil commented Oct 15, 2018

updated

@fommil
Copy link
Contributor Author

fommil commented Oct 15, 2018

The suggested fix doesn't pass the linter

 ^---------------^ SC2039: In POSIX sh, array references are undefined.

🤷‍♂️

ghcup Outdated
@@ -994,7 +994,9 @@ while [ $# -gt 0 ] ; do
if [ "${TARGET_LOCATION}" ] ; then
self_update "${TARGET_LOCATION}"
else
self_update "${HOME}/.local/bin"
# https://stackoverflow.com/a/246128/1041691
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )"
Copy link
Member

@hasufell hasufell Oct 15, 2018

Choose a reason for hiding this comment

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

This is bash syntax, we are not using bash. Instead of "${BASH_SOURCE[0]}" you can probably just use "$0" (from global scope rather, as a variable like SCRIPT).

Check https://gist.github.com/tvlooy/cbfbdb111a4ebad8b93e for tests and discussions of different approaches. This one is also not entirely safe. Mind that we are replacing a file here, so it should be safe.

Copy link
Member

@hasufell hasufell Oct 15, 2018

Choose a reason for hiding this comment

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

# @VARIABLE: SOURCE
# @DESCRIPTION:
# The $0 argument, which contains
# the script name.
SOURCE="$0"

# @FUNCTION: script_dir
# @DESCRIPTION:
# Portably gets the full directory of where
# this script resides in and prints it to stdout.
# @STDOUT: script directory
script_dir() {
    mysource=${SOURCE}

    while [ -h "${mysource}" ]; do
        mydir="$( cd -P "$( dirname "${mysource}" )" > /dev/null && pwd )"
        mysource="$(readlink "${mysource}")"
        [ "${mysource%${mysource#?}}"x != '/x' ] && mysource="${mydir}/${mysource}"
    done
    mydir="$( cd -P "$( dirname "${mysource}" )" > /dev/null && pwd )"
    echo "${mydir}"

    unset mysource mydir
}

I think this will do and is posix compliant and portable.

@fommil
Copy link
Contributor Author

fommil commented Oct 15, 2018

thanks! I pushed your changes and checked locally that it works for my custom installation directory.

README.md Outdated
(preferably `~/.local/bin`).

```
curl https://raw.githubusercontent.com/hasufell/ghcup/master/ghcup > ~/.local/bin/ghcup && chmod 755 ~/.local/bin/ghcup
Copy link
Member

@hasufell hasufell Oct 15, 2018

Choose a reason for hiding this comment

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

I prefer to be a bit more verbose here, so people are forced to read the command ;)

E.g.:

mkdir -p ~/.local/bin
curl https://raw.githubusercontent.com/hasufell/ghcup/master/ghcup > ~/.local/bin/ghcup
chmod +x ~/.local/bin/ghcup

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@hasufell hasufell merged commit 1f32be4 into haskell:master Oct 15, 2018
@fommil fommil deleted the self-update-in-place branch October 15, 2018 14:22
@fommil
Copy link
Contributor Author

fommil commented Oct 15, 2018

argh, there is a typo

mkdir -p ~/.local/bin/ghcup

should be

mkdir -p ~/.local/bin

I'll send a follow up.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants