Enhance Add colours (#21)

added colour support in a way that will not screw up the console if
colour support is not available
Used US spelling ;p
If approved will add to remaining scripts
This commit is contained in:
Mafoo 2016-06-14 01:40:49 +01:00 committed by FusionPBX
parent 70a03da58f
commit 76eb530f3b
3 changed files with 89 additions and 29 deletions

38
debian/install.sh vendored
View File

@ -1,10 +1,15 @@
#!/bin/sh
#move to script directory so all relative paths work
cd "$(dirname "$0")"
. resources/colors.sh
#Process command line options
ARGS=$(getopt -n 'install.sh' -o h -l help,use-switch-source,use-switch-package-all,use-switch-master,use-switch-package-unofficial-arm,no-cpu-check -- "$@")
if [ $? -ne 0 ]; then
echo "Failed parsing options."
error "Failed parsing options."
exit 1
fi
@ -29,12 +34,12 @@ while true; do
done
if [ $HELP = true ]; then
echo "Debian installer script"
echo " --use-switch-source will use freeswitch from source rather than (default:packages)"
echo " --use-switch-package-all if using packages use the meta-all package"
echo " --use-switch-package-unofficial-arm if your system is arm and you are using packages, use the unofficial arm repo"
echo " --use-switch-master will use master branch/packages instead of (default:stable)"
echo " --no-cpu-check disable the cpu check (default:check)"
warning "Debian installer script"
warning " --use-switch-source will use freeswitch from source rather than ${green}(default:packages)"
warning " --use-switch-package-all if using packages use the meta-all package"
warning " --use-switch-package-unofficial-arm if your system is arm and you are using packages, use the unofficial arm repo"
warning " --use-switch-master will use master branch/packages instead of ${green}(default:stable)"
warning " --no-cpu-check disable the cpu check ${green}(default:check)"
exit;
fi
@ -50,17 +55,17 @@ if [ $CPU_CHECK = true ]; then
if [ $USE_SWITCH_SOURCE = false ]; then
if [ $OS_arch = 'armv7l' ]; then
if [ $USE_SWITCH_PACKAGE_UNOFFICIAL_ARM = false && OS_bits = 'i686' ]; then
echo "You are using a 32bit arm OS this is unsupported"
echo " please rerun with either --use-switch-package-unofficial-arm or --use-switch-source"
error "You are using a 32bit arm OS this is unsupported"
warning " please rerun with either --use-switch-package-unofficial-arm or --use-switch-source"
exit 3
fi
else
if [ $OS_bits = 'i686' ]; then
echo "You are using a 32bit OS this is unsupported"
error "You are using a 32bit OS this is unsupported"
if [ $CPU_bits = 'x86_64' ]; then
echo "Your CPU is 64bit you should consider reinstalling with a 64bit OS"
error "Your CPU is 64bit you should consider reinstalling with a 64bit OS"
fi
echo " please rerun with --use-switch-source"
warning " please rerun with --use-switch-source"
exit 3
fi
fi
@ -71,12 +76,9 @@ fi
sed -i '/cdrom:/d' /etc/apt/sources.list
#Update Debian
echo "Update Debian"
verbose "Update Debian"
apt-get upgrade && apt-get update -y --force-yes
#move to script directory so all relative paths work
cd "$(dirname "$0")"
#IPTables
resources/iptables.sh
@ -129,8 +131,8 @@ systemctl restart nginx
systemctl restart fail2ban
#Show database password
echo "Complete the install by by going to the IP address of this server ";
echo "in your web browser or with a domain name for this server.";
verbose "Complete the install by by going to the IP address of this server ";
verbose "in your web browser or with a domain name for this server.";
echo " https://$server_address"
echo ""
echo ""

25
debian/resources/colors.sh vendored Normal file
View File

@ -0,0 +1,25 @@
#!/bin/sh
verbose () {
echo "${green}$1${normal}"
}
error () {
echo "${red}$1${normal}"
}
warning () {
echo "${yellow}$1${normal}"
}
# check for color support
if test -t 1; then
# see if it supports colors...
ncolors=$(tput colors)
if test -n "$ncolors" && test $ncolors -ge 8; then
normal="$(tput sgr0)"
red="$(tput setaf 1)"
green="$(tput setaf 2)"
yellow="$(tput setaf 3)"
fi
fi

View File

@ -4,12 +4,44 @@
# 2 unsupported OS
# 3 unsupported CPU/OS bits
verbose () {
echo "${green}$1${normal}"
}
error () {
echo "${red}$1${normal}"
}
# check for color support
if test -t 1; then
# see if it supports colors...
ncolors=$(tput colors)
if test -n "$ncolors" && test $ncolors -ge 8; then
bold="$(tput bold)"
underline="$(tput smul)"
standout="$(tput smso)"
normal="$(tput sgr0)"
black="$(tput setaf 0)"
red="$(tput setaf 1)"
green="$(tput setaf 2)"
yellow="$(tput setaf 3)"
blue="$(tput setaf 4)"
magenta="$(tput setaf 5)"
cyan="$(tput setaf 6)"
white="$(tput setaf 7)"
fi
verbose "Enabled color support"
fi
# check to confirm running as root.
if [ "$(id -u)" -ne "0" ]; then
echo "$(basename "$0") must be run as root";
error "$(basename "$0") must be run as root";
exit 1
fi
echo
#Make ourselves executable next time we are run
chmod +x $0
#Os/Distro Check
os_check=$(lsb_release -is)
@ -18,29 +50,30 @@ check_major_release=$(lsb_release -rs | cut -d. -f1)
os_unsupported () {
echo " Your Operating System appears to be: "
lsb_release -a
echo "Your Operating System is not currently supported... Exiting the install."
error "Your Operating System is not currently supported... Exiting the install."
exit 2;
}
if [ $os_check = 'Debian' ]; then
if [ $check_major_release -ge 8 ]; then
echo "Removing the CD image from /etc/apt/sources.list"
verbose "Removing the CD image from /etc/apt/sources.list"
sed -i '/cdrom:/d' /etc/apt/sources.list
echo "Updating system before starting."
verbose "Updating system before starting."
apt-get update && apt-get -y upgrade
echo "Installing Git"
verbose "Installing Git"
apt-get install -y git
cd /usr/src
echo "Fetching Installer"
verbose "Fetching Installer"
if [ -d /usr/src/fusionpbx-install.sh ]; then
echo "Cannot continue you already have a installer downloaded"
exit 1
fi
cd /usr/src/fusionpbx-install.sh
git pull
else
git clone https://github.com/fusionpbx/fusionpbx-install.sh
fi
cd /usr/src/fusionpbx-install.sh/debian
./install.sh $@
else
echo "Although you are running Debian we require version >= 8"
error "Although you are running Debian we require version >= 8"
os_unsupported
fi
else