-
Notifications
You must be signed in to change notification settings - Fork 24
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
Conversation
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)" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- this isn't really safe, see https://stackoverflow.com/a/49964642/2976251 and https://stackoverflow.com/questions/59895/getting-the-source-directory-of-a-bash-script-from-within and https://stackoverflow.com/questions/9889938/shell-script-current-directory
- doesn't pass shellcheck https://travis-ci.org/hasufell/ghcup/builds/441561213#L1906
README.md
Outdated
(preferably `~/.local/bin`). | ||
|
||
``` | ||
wget https://raw.githubusercontent.com/hasufell/ghcup/master/ghcup -O ~/.local/bin/ghcup && chmod 755 ~/.local/bin/ghcup |
There was a problem hiding this comment.
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
updated |
The suggested fix doesn't pass the linter
🤷♂️ |
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 )" |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
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 |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
argh, there is a typo
should be
I'll send a follow up. |
Doesn't assume an installation directory.