Last active
December 23, 2016 15:07
-
-
Save qastmoran/2d918261cda13cc9ae13f4435ecd880b to your computer and use it in GitHub Desktop.
qtest_install2.sh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
function set_var { | |
set -e | |
#set -x | |
hostip=$(ip addr | grep -Eo 'inet (addr:)?([0-9]*\.){3}[0-9]*' | grep -Eo '([0-9]*\.){3}[0-9]*' | grep -v '127.0.0.1' | head -1) | |
sel_host='' | |
log=' 2>&1 |tee -a qest_install.log' | |
} | |
function add_color { | |
#Add Basic Color | |
red=`tput setaf 1` | |
green=`tput setaf 2` | |
yellow=`tput setaf 3` | |
blue=`tput setaf 4` | |
reset=`tput sgr0` | |
} | |
function isroot { | |
# Check if root else quit | |
if [ "$EUID" -ne 0 ] | |
then echo "${red}Please run as root${reset}" | |
exit | |
fi | |
} | |
function spaces { | |
echo | |
echo | |
} | |
function welcome { | |
spaces | |
echo "${green}Welcome to the Automated Installation of qTest Manager in Docker!${reset}" | |
spaces | |
echo "${green}The following changes will be made during this installation:${reset}" | |
echo "${yellow}1. Use the yum -y update option to upgrade all of your CentOS system software to the latest version with one operation${reset}" | |
echo "${yellow}2. Temporarily disable SELinux during the installation of Docker and qTest${reset}" | |
echo "${yellow}3. Add the Docker0 interface as trusted and allow all required ports for Docker & qTest(defaults)${reset}" | |
echo "${yellow}4. Install Docker${reset}" | |
echo "${yellow}5. Start the Docker Service${reset}" | |
echo "${yellow}6. Enable Docker on Startup${reset}" | |
echo "${yellow}7. Install wget if it is not already installed${reset}" | |
echo "${yellow}8. Download the qTest deployment package via wget${reset}" | |
echo "${yellow}9. Deploy qTest to /opt/qtest${reset}" | |
echo "${yellow}10. Configure qTest with the default settings using http://$hostip/${reset}" | |
echo "${yellow}11. Download the qTest Docker Images and Start the qTest app containers(this can take up to 30 minutes)${reset}" | |
spaces | |
echo "${yellow} Sleeping for 5 seconds, please press ctrl+c to abort installation${reset}" | |
sleep 5 | |
} | |
function yum_update { | |
spaces | |
echo "${blue}Updating your CentOS system software to the latest version${reset}" | |
yum -y update | |
} | |
function selchk { | |
if [ $(getenforce) = "Enforcing" ] | |
then spaces | |
echo "${red}SELinux is set to Enforcing - disabling SELinux during installation${reset}" | |
setenforce 0 | |
sel_host="1" | |
fi | |
} | |
function firechk { | |
if [ -x /bin/firewall-cmd ] | |
then systemctl status firewalld >/dev/null 2>&1 | |
if [ $? = 0 ] | |
then spaces | |
echo "${yellow}FirewallD found running on host, add Docker & qTest ports to the public zone.${reset}" | |
echo "trust interface=docker0" && firewall-cmd --permanent --zone=trusted --change-interface=docker0 | |
echo "Adding 4243/tcp" && firewall-cmd --permanent --zone=trusted --add-port=4243/tcp | |
echo "Adding 6784/tcp" && firewall-cmd --zone=public --add-port=6784/tcp --permanent | |
echo "Adding 6784/udp" && firewall-cmd --zone=public --add-port=6784/udp --permanent | |
echo "Adding 6783/tcp" && firewall-cmd --zone=public --add-port=6783/tcp --permanent | |
echo "Adding 6783/udp" && firewall-cmd --zone=public --add-port=6783/udp --permanent | |
echo "Adding 53/tcp" && firewall-cmd --zone=public --add-port=53/tcp --permanent | |
echo "Adding 53/udp" && firewall-cmd --zone=public --add-port=53/udp --permanent | |
echo "${yellow}Reloading FirewallD configuration...${reset}" && firewall-cmd --reload | |
else echo "${yellow}FirewallD was found on your system but is not running, please note enabling FirewallD will block both Docker & qTest ports by default.${reset}" | |
echo "It is recommended you add the following rules to your FirewallD configuration." | |
echo "firewall-cmd --permanent --zone=trusted --change-interface=docker0" | |
echo "firewall-cmd --permanent --zone=trusted --add-port=4243/tcp" | |
echo "firewall-cmd --zone=public --add-port=6784/tcp --permanent" | |
echo "firewall-cmd --zone=public --add-port=6783/tcp --permanent" | |
echo "firewall-cmd --zone=public --add-port=6783/udp --permanent" | |
echo "firewall-cmd --zone=public --add-port=6784/udp --permanent" | |
echo "firewall-cmd --zone=public --add-port=53/udp --permanent" | |
echo "firewall-cmd --zone=public --add-port=53/tcp --permanent" | |
echo "firewall-cmd --reload" | |
fi | |
fi | |
if [ -x /bin/iptables ] | |
then systemctl status iptables >/dev/null 2>&1 | |
if [ $? = 0 ] | |
then echo "${yellow}iptables found running on host, add Docker & qTest ports to the public zone.${reset}" | |
echo "trust interface=docker0" && iptables -D FORWARD -j REJECT --reject-with icmp-host-prohibited | |
echo "4243/tcp" && iptables -D INPUT -j REJECT --reject-with icmp-host-prohibited | |
echo "6784/tcp" && iptables -A INPUT -p tcp -m tcp --dport 53 -j ACCEPT | |
echo "6784/udp" && iptables -A INPUT -p udp -m udp --dport 53 -j ACCEPT | |
echo "6783/tcp" && iptables -A INPUT -p tcp -m tcp --dport 6783 -j ACCEPT | |
echo "6783/udp" && iptables -A INPUT -p udp -m udp --dport 6783 -j ACCEPT | |
echo "6243/tcp" && iptables -A INPUT -p udp -m tcp --dport 6784 -j ACCEPT | |
echo "6243/udp" && iptables -A INPUT -p tcp -m udp --dport 6784 -j ACCEPT | |
echo "Saving iptables configuration..." && iptables-save | |
else echo "${yellow}iptables was found on your system but is not running, please note enabling iptables will block both Docker & qTest ports by default.${reset}" | |
echo "It is recommended you add the following rules to your iptables configuration." | |
echo "iptables -D FORWARD -j REJECT --reject-with icmp-host-prohibited" | |
echo "iptables -D INPUT -j REJECT --reject-with icmp-host-prohibited" | |
echo "iptables -A INPUT -p tcp -m tcp --dport 53 -j ACCEPT" | |
echo "iptables -A INPUT -p udp -m udp --dport 53 -j ACCEPT" | |
echo "iptables -A INPUT -p tcp -m tcp --dport 6783 -j ACCEPT" | |
echo "iptables -A INPUT -p udp -m udp --dport 6783 -j ACCEPT" | |
echo "iptables -A INPUT -p udp -m tcp --dport 6784 -j ACCEPT" | |
echo "iptables -A INPUT -p tcp -m udp --dport 6784 -j ACCEPT" | |
echo "iptables-save" | |
fi | |
fi | |
} | |
function install_docker { | |
if [ ! -x /bin/docker ] | |
then spaces | |
echo "${blue}Installing Docker...${reset}" | |
curl https://get.docker.com/ | sh | |
else dver=$(docker -v) | |
echo "${yellow}Docker $dver already installed!${reset}" | |
fi | |
} | |
function start_docker { | |
if [ "$(systemctl status docker >/dev/null 2>&1)" = 0 ] | |
then spaces | |
echo "${yellow}Docker is already running!${reset}" | |
else echo "${blue}Starting Docker...${reset}" | |
systemctl start docker | |
fi | |
} | |
function enable_docker { | |
if [ ! -f "/usr/lib/systemd/system/docker.service" ] | |
then spaces | |
echo "${blue}Enabling Docker on startup...${reset}" | |
systemctl enable docker | |
fi | |
} | |
function wgetchk { | |
if [ ! -x /usr/bin/wget ] | |
then command -v wget >/dev/null 2>&1 || echo "${blue}Installing wget${reset}" && yum -y install wget | |
fi | |
} | |
function download_qtest { | |
if [ ! -d "/var/cache/qasymphony" ] | |
then spaces | |
echo "${blue}Downloading qTest 8.1.5 Installation Package...${reset}" | |
sh -c 'cd /tmp && wget https://qtest-storage.s3.amazonaws.com/docker/deployment/docker-deployment-3.0.tar.gz' | |
else echo "${red}A previous qTest installation is detected... aborting installation!${reset}" | |
exit | |
fi | |
} | |
function deploy_qtest { | |
if [ ! -d "/opt/qtest/docker-deployment-3.0" ] | |
then spaces | |
echo "${blue}Installing qTest 8.1.5 Deployment scripts in /opt/qtest${reset}" | |
sh -c 'mkdir -p /opt/qtest && cd /tmp && tar -zxf docker-deployment-3.0.tar.gz -C /opt/qtest' | |
else echo "${red}A previous qTest 8.1.5 installation is detected in /opt/qtest/docker-deployment-3.0... aborting installation!${reset}" | |
exit | |
fi | |
} | |
function config_qtest { | |
if [ ! -f "/opt/qtest/docker-deployment-3.0/profiles/default.in" ] | |
then spaces | |
echo "${blue}Generating initial qTest configuration file in /opt/qtest/docker-deployment-3.0/profiles... visit https://support.qasymphony.com for advanced configuration options${reset}" | |
sh -c "cd /opt/qtest/docker-deployment-3.0 && ./configure --qtest-url http://$hostip/ --sessions-url http://$hostip:8080/" | |
else spaces | |
echo "${red}A previous qTest 8.1.5 configuration file is detected in /opt/qtest/docker-deployment-3.0/profiles/... aborting installation!${reset}" | |
exit | |
fi | |
} | |
function start_qtest { | |
if [ ! "$(docker ps -q -f name=qtest)" ] | |
then spaces | |
echo "${blue}Downloading Docker Images and Starting qTest...${reset}" | |
echo "${yellow}This process may take up to 30 minutes to complete.${reset}" | |
sh -c 'cd /opt/qtest/docker-deployment-3.0 && ./startup' | |
else echo "${red}qTest is already running on your system!${reset}" | |
fi | |
} | |
function selenf { | |
if [ sel_host = "1" ] | |
then spaces | |
echo "${green}Restoring SELinux Enforcement${reset}" | |
setenforce 1 | |
fi | |
} | |
function post_install { | |
spaces | |
echo "${green}Thank you for installing qTest 8.1.5!!!${reset}" | |
echo "${green}Please visit${reset} ${white}http://$hostip/${reset} ${green}to setup your local qTest administrator account.${reset}" | |
} | |
function main { | |
set_var | |
add_color | |
isroot | |
welcome | |
yum_update | |
selchk | |
firechk | |
wgetchk | |
install_docker | |
#curl http://tinyurl.com/jnrg855 | sh | |
start_docker | |
enable_docker | |
download_qtest | |
deploy_qtest | |
config_qtest | |
start_qtest | |
selenf | |
post_install | |
} | |
main |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment