From 65590470bc08a1f827c5c49422345e112f72154b Mon Sep 17 00:00:00 2001 From: "Stephen M. Coakley" Date: Thu, 23 Nov 2017 21:00:04 -0600 Subject: [PATCH 1/3] fix: #577 add environment sanity checks --- README.md | 6 +- bin/install | 105 +++++++++++++++++++++++-- bin/install.sha256 | 2 +- pkg/omf/functions/core/omf.doctor.fish | 3 + 4 files changed, 105 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 3cd5b67..30929f6 100644 --- a/README.md +++ b/README.md @@ -34,7 +34,7 @@ fish install --path=~/.local/share/omf --config=~/.config/omf You can verify the integrity of the downloaded installer by verifying the script against [this checksum](bin/install.sha256): ``` -92ca680df48640e744b361d376194c5f5f8d6b4f1ac775d22417a0d8a8108767 install +79cb5ff876e4192b63391efda5a200beeac540cde6a56c8bcf63dc9c54c6bda4 install ``` You can also install Oh My Fish with Git or with an offline source tarball downloaded from the [releases page][releases]: @@ -58,8 +58,8 @@ Run `install --help` for a complete list of install options you can customize. #### Known Issues -- Due to a regression bug in fish 2.6 with some terminal emulators, right prompts make the shell unusable. - OMF's `default` theme features a right prompt, so it's necessary to use an alternative theme until a fix is released. +- Due to a regression bug in fish 2.6 with some terminal emulators, right prompts make the shell unusable. + OMF's `default` theme features a right prompt, so it's necessary to use an alternative theme until a fix is released. (see [#541](https://github.com/oh-my-fish/oh-my-fish/issues/541)) diff --git a/bin/install b/bin/install index de89308..0473d07 100755 --- a/bin/install +++ b/bin/install @@ -35,12 +35,14 @@ function main Options: --channel= Download a specific release channel, either \"stable\" or \"dev\" (default is \"$OMF_CHANNEL\"). + --check Do a system readiness check without installing. --config= Put config in a specific path (default is $OMF_CONFIG_DEFAULT). --help, -h Show this help message. --noninteractive Disable interactive questions (assume no, use with --yes to assume yes). --offline[=] Offline install, optionally specifying a tar or directory to use. --path= Use a specific install path (default is $OMF_PATH_DEFAULT). --uninstall Uninstall existing installation instead of installing. + --verbose Enable verbose debugging statements for the installer. --yes, -y Assume yes for interactive questions. " return 0 @@ -54,6 +56,9 @@ Options: case '--channel=*' abort "Unknown release channel \""(echo "$argv[1]" | command cut -d= -f2)"\"." + case --check + set -g CHECK_ONLY + case '--config=*' echo "$argv[1]" | command cut -d= -f2 | command sed -e "s#~#$HOME#" | read -g OMF_CONFIG @@ -73,6 +78,10 @@ Options: case --uninstall set -g UNINSTALL + case --verbose + set -g VERBOSE + debug "verbose turned on" + case --yes -y set -g ASSUME_YES @@ -82,12 +91,19 @@ Options: set -e argv[1] end - # Ensure the environment meets all of the requirements. - assert_fish_version_compatible 2.2.0 - assert_git_version_compatible 1.9.5 - assert_cmds + # Do the check only. + if set -q CHECK_ONLY + sane_environment_check + return + end + assert_interactive + # Ensure the environment meets all of the requirements. + if not sane_environment_check + abort "Environment does not meet the requirements." + end + # If the user wants to uninstall, jump to uninstallation and exit. if set -q UNINSTALL uninstall_omf @@ -123,7 +139,18 @@ end # Add an exit hook to display a message if the installer aborts or errors. function on_exit -p %self if not contains $argv[3] 0 2 - echo -e "\nOh My Fish installation failed.\n\nIf you think that it's a bug, please open an\nissue with the complete installation log here:\n\nhttp://github.com/oh-my-fish/oh-my-fish/issues" + echo " +Oh My Fish installation failed. + +If you think that it's a bug, please open an +issue with the complete installation log here: + +http://github.com/oh-my-fish/oh-my-fish/issues" + + if not set -q VERBOSE + echo + echo "Try rerunning with --verbose to see additional output." + end end end @@ -421,6 +448,44 @@ function restore_backup_file -a file_path end +# Verify we have a sane environment that OMF can run in. +function sane_environment_check + say "Checking for a sane environment..." + assert_cmds + + debug "Checking for a sane 'head' implementation" + set -l result (printf 'a\nb\n' | cmd head -n 1) + and test "$result" = 'a' + or abort (which head)" is not a sane 'head' implementation" + + debug "Checking for a sane 'sort' implementation" + set -l result (printf '1.2.3\n2.2.4\n1.2.4\n' | cmd sort -r -n -t '.' -k 1,1 -k 2,2 -k 3,3 -k 4,4) + and set -q result[3] + and test "$result[1]" = 2.2.4 + and test "$result[2]" = 1.2.4 + and test "$result[3]" = 1.2.3 + or abort (which sort)" is not a sane 'sort' implementation" + + debug "Checking AWK version" + if not cmd awk -Wv | cmd grep -i -q AWK + abort (which awk)" does not look like an AWK interpreter." + end + + assert_fish_version_compatible 2.2.0 + assert_git_version_compatible 1.9.5 + + debug "Verifying Git implementation is not buggy Git for Windows" + if cmd git --version | cmd grep -i -q windows + abort (which git)" is Git for Windows which is not supported." + end + + debug "Verifying Git autocrlf is not enabled" + if test (cmd git config --bool core.autocrlf; or echo false) = true + abort "Please disable core.autocrlf in your Git configuration." + end +end + + # Gets the version of Fish installed. function get_fish_version if set -q FISH_VERSION @@ -492,11 +557,13 @@ end # Assert that all tools we need are available. function assert_cmds - set -l cmds awk basename cp cut date dirname fold head mkdir mv rm sed sort tar tr + set -l cmds awk basename cp cut date dirname env fish fold head mkdir mv readlink rm sed sort tar tr which for cmd in $cmds type -f -q $cmd - or abort "Command '$cmd' not found" + or abort "Missing required command: $cmd" + + debug "Command '$cmd' is "(which $cmd) end end @@ -512,12 +579,36 @@ function assert_interactive end +# A link-following `which` wrapper. +function which + command readlink -f (command which $argv) +end + + +# Execute an external command. +function cmd + if set -q VERBOSE + command env $argv + else + command env $argv ^ /dev/null + end +end + + # Print a message to the user. function say -a message printf "$message\n" | command fold -s -w 80 end +# Write a debug message. +function debug -a message + if set -q VERBOSE + printf 'DEBUG: %s\n' "$message" >&2 + end +end + + # Aborts the installer and displays an error. function abort -a message code if test -z "$code" diff --git a/bin/install.sha256 b/bin/install.sha256 index ca64d26..2943451 100644 --- a/bin/install.sha256 +++ b/bin/install.sha256 @@ -1 +1 @@ -92ca680df48640e744b361d376194c5f5f8d6b4f1ac775d22417a0d8a8108767 install +79cb5ff876e4192b63391efda5a200beeac540cde6a56c8bcf63dc9c54c6bda4 install diff --git a/pkg/omf/functions/core/omf.doctor.fish b/pkg/omf/functions/core/omf.doctor.fish index ba16762..cd7463a 100644 --- a/pkg/omf/functions/core/omf.doctor.fish +++ b/pkg/omf/functions/core/omf.doctor.fish @@ -56,6 +56,9 @@ function omf.doctor __omf.doctor.git_version; or set -l doctor_failed __omf.doctor.theme; or set -l doctor_failed + fish "$OMF_PATH/bin/install" --check + or set -l doctor_failed + if set -q doctor_failed echo "If everything you use Oh My Fish for is working fine, please don't worry and just ignore the warnings. Thanks!" else From 5943c22650c61da6577821e22eb18a177e619b98 Mon Sep 17 00:00:00 2001 From: "Stephen M. Coakley" Date: Tue, 2 Jan 2018 10:52:08 -0600 Subject: [PATCH 2/3] fix: error with BSD readlink --- README.md | 2 +- bin/install | 2 +- bin/install.sha256 | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 30929f6..8cc86ea 100644 --- a/README.md +++ b/README.md @@ -34,7 +34,7 @@ fish install --path=~/.local/share/omf --config=~/.config/omf You can verify the integrity of the downloaded installer by verifying the script against [this checksum](bin/install.sha256): ``` -79cb5ff876e4192b63391efda5a200beeac540cde6a56c8bcf63dc9c54c6bda4 install +bedbff763e374d5ca3367fa75b322302411e961947133eb22c7115083ba3a3ff install ``` You can also install Oh My Fish with Git or with an offline source tarball downloaded from the [releases page][releases]: diff --git a/bin/install b/bin/install index 0473d07..aeee046 100755 --- a/bin/install +++ b/bin/install @@ -581,7 +581,7 @@ end # A link-following `which` wrapper. function which - command readlink -f (command which $argv) + command readlink (command which $argv) end diff --git a/bin/install.sha256 b/bin/install.sha256 index 2943451..8b7fbf6 100644 --- a/bin/install.sha256 +++ b/bin/install.sha256 @@ -1 +1 @@ -79cb5ff876e4192b63391efda5a200beeac540cde6a56c8bcf63dc9c54c6bda4 install +bedbff763e374d5ca3367fa75b322302411e961947133eb22c7115083ba3a3ff install From 7592f43dea9094346fa0ee687a5c2e6888075109 Mon Sep 17 00:00:00 2001 From: "Stephen M. Coakley" Date: Tue, 2 Jan 2018 11:26:20 -0600 Subject: [PATCH 3/3] fix: smarter AWK detection that supports nawk --- .travis.yml | 2 +- README.md | 2 +- bin/install | 11 ++++++++--- bin/install.sha256 | 2 +- 4 files changed, 11 insertions(+), 6 deletions(-) diff --git a/.travis.yml b/.travis.yml index 242fbee..73516ce 100644 --- a/.travis.yml +++ b/.travis.yml @@ -25,7 +25,7 @@ before_script: - tree -h - export - pushd bin; sha256sum -c install.sha256; popd - - fish $TRAVIS_BUILD_DIR/bin/install --offline --noninteractive --yes + - fish $TRAVIS_BUILD_DIR/bin/install --verbose --offline --noninteractive --yes script: - tests/run.fish diff --git a/README.md b/README.md index 8cc86ea..999fe42 100644 --- a/README.md +++ b/README.md @@ -34,7 +34,7 @@ fish install --path=~/.local/share/omf --config=~/.config/omf You can verify the integrity of the downloaded installer by verifying the script against [this checksum](bin/install.sha256): ``` -bedbff763e374d5ca3367fa75b322302411e961947133eb22c7115083ba3a3ff install +4dd63d6a974a61c100cbe145ae46eac69edce985f20b061f353cc399b36c7587 install ``` You can also install Oh My Fish with Git or with an offline source tarball downloaded from the [releases page][releases]: diff --git a/bin/install b/bin/install index aeee046..8df08a5 100755 --- a/bin/install +++ b/bin/install @@ -466,8 +466,9 @@ function sane_environment_check and test "$result[3]" = 1.2.3 or abort (which sort)" is not a sane 'sort' implementation" - debug "Checking AWK version" - if not cmd awk -Wv | cmd grep -i -q AWK + debug "Checking for a working AWK interpreter" + cmd awk 'BEGIN{exit 42;}' < /dev/null ^ /dev/null + if not test $status -eq 42 abort (which awk)" does not look like an AWK interpreter." end @@ -581,7 +582,11 @@ end # A link-following `which` wrapper. function which - command readlink (command which $argv) + if type -q realpath + realpath (command which $argv) + else + command readlink (command which $argv) + end end diff --git a/bin/install.sha256 b/bin/install.sha256 index 8b7fbf6..1c7a2ac 100644 --- a/bin/install.sha256 +++ b/bin/install.sha256 @@ -1 +1 @@ -bedbff763e374d5ca3367fa75b322302411e961947133eb22c7115083ba3a3ff install +4dd63d6a974a61c100cbe145ae46eac69edce985f20b061f353cc399b36c7587 install