improving health cheack and adding at least gawk 4

This commit is contained in:
Jorge Morante 2017-04-09 17:40:15 +02:00
parent 90faa45f99
commit 0d69d6412f
3 changed files with 35 additions and 18 deletions

View File

@ -1,6 +1,6 @@
dependencies:
pre:
- if [[ ! -e tmux-2.2 ]]; then sudo bash ./test/provisioning/ubuntu.sh; fi
- sudo bash ./test/provisioning/ubuntu.sh
- sudo mkdir -p /home/vagrant/ && sudo chmod a+w /home/vagrant && ln -s $(pwd) /home/vagrant/shared
- tmux -V
- gawk -W version

View File

@ -4,7 +4,7 @@ CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
source $CURRENT_DIR/utils.sh
REQUIRED_BASH_MAJOR=4
REQUIRED_TMUX_MAJOR=2
REQUIRED_GAWK_MAJOR=4
RECOMMENDED_TMUX_MINOR=3
HELP_LINK="https://github.com/Morantron/tmux-fingers/blob/master/docs/health-check.md"
@ -21,6 +21,14 @@ function is_tmux_ready() {
fi
}
function version_major() {
echo "$1" | cut -f1 -d. | grep -Eo "[0-9]"
}
function version_minor() {
echo "$1" | cut -f2 -d. | grep -Eo "[0-9]"
}
function program_exists() {
local prog="$1"
@ -98,34 +106,41 @@ function dump_log() {
function perform_health_check() {
local healthy=1
# BASH_VERSION is a global
local TMUX_VERSION=$(tmux -V | grep -Eio "[0-9]+(\.[0-9a-z])*$")
local GAWK_VERSION=""
if [[ $(program_exists "gawk") = "1" ]]; then
GAWK_VERSION=$(gawk -W version | grep -Eo "[0-9]+\.[0-9]\.[0-9]" | head -n 1)
fi
FINGERS_SKIP_HEALTH_CHECK=$(tmux show-option -gqv @fingers-skip-health-check)
if [[ $FINGERS_SKIP_HEALTH_CHECK -eq 1 ]]; then
return
fi
if [[ $(program_exists "gawk") = "0" ]]; then
log_message "* 'gawk' not found"
if [[ $(program_exists "gawk") = 0 ]]; then
log_message " * 'gawk' not found"
healthy=0
fi
BASH_MAJOR=$(echo "$BASH_VERSION" | grep -Eo "^[0-9]")
if [[ "$BASH_MAJOR" -lt "$REQUIRED_BASH_MAJOR" ]]; then
log_message " * Bash version \"$BASH_VERSION\" is too old."
if [[ $(version_major "$BASH_VERSION") -lt "$REQUIRED_BASH_MAJOR" ]]; then
log_message " * bash version \"$BASH_VERSION\" is too old. bash $REQUIRED_BASH_MAJOR.x+ is required."
healthy=0
fi
TMUX_VERSION=$(tmux -V | grep -Eio "[0-9]+(\.[0-9a-z])*$")
TMUX_MAJOR=$(echo "$TMUX_VERSION" | cut -f1 -d.)
TMUX_MINOR=$(echo "$TMUX_VERSION" | cut -f2 -d. | grep -Eo "[0-9]")
if [[ $TMUX_MAJOR -lt $REQUIRED_TMUX_MAJOR ]]; then
log_message " * tmux version \"$TMUX_VERSION\" is too old."
if [[ $(program_exists "gawk") = 1 ]] && [[ $(version_major "$GAWK_VERSION") -lt "$REQUIRED_GAWK_MAJOR" ]]; then
log_message " * gawk version \"$GAWK_VERSION\" is too old. gawk $REQUIRED_GAWK_MAJOR.x+ is required."
healthy=0
fi
if [[ $TMUX_MAJOR -eq $REQUIRED_TMUX_MAJOR ]] && [[ $TMUX_MINOR -lt $RECOMMENDED_TMUX_MINOR ]]; then
if [[ $(version_major "$TMUX_VERSION") -lt $REQUIRED_TMUX_MAJOR ]]; then
log_message " * tmux version \"$TMUX_VERSION\" is too old. tmux $REQUIRED_TMUX_MAJOR.$RECOMMENDED_TMUX_MINOR+ is required."
healthy=0
fi
if [[ $(version_major "$TMUX_VERSION") -eq $REQUIRED_TMUX_MAJOR ]] && [[ $(version_minor "$TMUX_VERSION") -lt $RECOMMENDED_TMUX_MINOR ]]; then
echo " * WARNING: tmux 2.2+ is recommended"
fi

View File

@ -1,13 +1,15 @@
#!/bin/sh
apt-get remove -y tmux
apt-get install -y libevent-dev libncurses5-dev expect fish
apt-get install -y gawk
sudo aptitude update
sudo aptitude install -y expect fish gawk
useradd -m -p "$(perl -e "print crypt('fishman','sa');")" -s "/usr/bin/fish" fishman
wget https://github.com/tmux/tmux/releases/download/2.2/tmux-2.2.tar.gz
# install tmux from source
sudo aptitude remove -y tmux
sudo aptitude install -y libevent-dev libncurses5-dev
tar xvzf tmux-2.2.tar.gz
cd tmux-2.2/ || echo "Could not find tmux-2.2/ folder" || exit 1