Commit 65590470 authored by Stephen M. Coakley's avatar Stephen M. Coakley

fix: #577 add environment sanity checks

parent cc3f836d
...@@ -34,7 +34,7 @@ fish install --path=~/.local/share/omf --config=~/.config/omf ...@@ -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): 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]: 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. ...@@ -58,8 +58,8 @@ Run `install --help` for a complete list of install options you can customize.
#### Known Issues #### Known Issues
- Due to a regression bug in fish 2.6 with some terminal emulators, right prompts make the shell unusable. - 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. 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)) (see [#541](https://github.com/oh-my-fish/oh-my-fish/issues/541))
......
...@@ -35,12 +35,14 @@ function main ...@@ -35,12 +35,14 @@ function main
Options: Options:
--channel=<channel> Download a specific release channel, either \"stable\" or \"dev\" (default is \"$OMF_CHANNEL\"). --channel=<channel> Download a specific release channel, either \"stable\" or \"dev\" (default is \"$OMF_CHANNEL\").
--check Do a system readiness check without installing.
--config=<path> Put config in a specific path (default is $OMF_CONFIG_DEFAULT). --config=<path> Put config in a specific path (default is $OMF_CONFIG_DEFAULT).
--help, -h Show this help message. --help, -h Show this help message.
--noninteractive Disable interactive questions (assume no, use with --yes to assume yes). --noninteractive Disable interactive questions (assume no, use with --yes to assume yes).
--offline[=<path>] Offline install, optionally specifying a tar or directory to use. --offline[=<path>] Offline install, optionally specifying a tar or directory to use.
--path=<path> Use a specific install path (default is $OMF_PATH_DEFAULT). --path=<path> Use a specific install path (default is $OMF_PATH_DEFAULT).
--uninstall Uninstall existing installation instead of installing. --uninstall Uninstall existing installation instead of installing.
--verbose Enable verbose debugging statements for the installer.
--yes, -y Assume yes for interactive questions. --yes, -y Assume yes for interactive questions.
" "
return 0 return 0
...@@ -54,6 +56,9 @@ Options: ...@@ -54,6 +56,9 @@ Options:
case '--channel=*' case '--channel=*'
abort "Unknown release channel \""(echo "$argv[1]" | command cut -d= -f2)"\"." abort "Unknown release channel \""(echo "$argv[1]" | command cut -d= -f2)"\"."
case --check
set -g CHECK_ONLY
case '--config=*' case '--config=*'
echo "$argv[1]" | command cut -d= -f2 | command sed -e "s#~#$HOME#" | read -g OMF_CONFIG echo "$argv[1]" | command cut -d= -f2 | command sed -e "s#~#$HOME#" | read -g OMF_CONFIG
...@@ -73,6 +78,10 @@ Options: ...@@ -73,6 +78,10 @@ Options:
case --uninstall case --uninstall
set -g UNINSTALL set -g UNINSTALL
case --verbose
set -g VERBOSE
debug "verbose turned on"
case --yes -y case --yes -y
set -g ASSUME_YES set -g ASSUME_YES
...@@ -82,12 +91,19 @@ Options: ...@@ -82,12 +91,19 @@ Options:
set -e argv[1] set -e argv[1]
end end
# Ensure the environment meets all of the requirements. # Do the check only.
assert_fish_version_compatible 2.2.0 if set -q CHECK_ONLY
assert_git_version_compatible 1.9.5 sane_environment_check
assert_cmds return
end
assert_interactive 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 the user wants to uninstall, jump to uninstallation and exit.
if set -q UNINSTALL if set -q UNINSTALL
uninstall_omf uninstall_omf
...@@ -123,7 +139,18 @@ end ...@@ -123,7 +139,18 @@ end
# Add an exit hook to display a message if the installer aborts or errors. # Add an exit hook to display a message if the installer aborts or errors.
function on_exit -p %self function on_exit -p %self
if not contains $argv[3] 0 2 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
end end
...@@ -421,6 +448,44 @@ function restore_backup_file -a file_path ...@@ -421,6 +448,44 @@ function restore_backup_file -a file_path
end 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. # Gets the version of Fish installed.
function get_fish_version function get_fish_version
if set -q FISH_VERSION if set -q FISH_VERSION
...@@ -492,11 +557,13 @@ end ...@@ -492,11 +557,13 @@ end
# Assert that all tools we need are available. # Assert that all tools we need are available.
function assert_cmds 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 for cmd in $cmds
type -f -q $cmd type -f -q $cmd
or abort "Command '$cmd' not found" or abort "Missing required command: $cmd"
debug "Command '$cmd' is "(which $cmd)
end end
end end
...@@ -512,12 +579,36 @@ function assert_interactive ...@@ -512,12 +579,36 @@ function assert_interactive
end 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. # Print a message to the user.
function say -a message function say -a message
printf "$message\n" | command fold -s -w 80 printf "$message\n" | command fold -s -w 80
end 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. # Aborts the installer and displays an error.
function abort -a message code function abort -a message code
if test -z "$code" if test -z "$code"
......
92ca680df48640e744b361d376194c5f5f8d6b4f1ac775d22417a0d8a8108767 install 79cb5ff876e4192b63391efda5a200beeac540cde6a56c8bcf63dc9c54c6bda4 install
...@@ -56,6 +56,9 @@ function omf.doctor ...@@ -56,6 +56,9 @@ function omf.doctor
__omf.doctor.git_version; or set -l doctor_failed __omf.doctor.git_version; or set -l doctor_failed
__omf.doctor.theme; 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 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!" echo "If everything you use Oh My Fish for is working fine, please don't worry and just ignore the warnings. Thanks!"
else else
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment