#!/bin/bash ## ## Script for PimpMyBeetle installation ## It will install some stuff ## Author : Lost Baboon / 2019/05/11 ## ## ## Some var RC=0 ## For internet testing SITE=google.com ## Function for some logging with timestamp fct_echo () { DT=$(date +%Y%m%d_%H:%M:%S) echo $DT $STEP $@ } ## Function for testing internet connection fct_internet() { fct_echo "Pinging $SITE for internet connection checking..." ping -c 3 ${SITE} >/dev/null 2>&1 if [ "$?" != "0" ] then fct_echo "Connection to $SITE hangs" RC=1 fct_exit else fct_echo "Connection ok" fi } ## Function for exiting fct_exit() { fct_echo "Exiting with RC code $RC" exit ${RC} } ## Function for installing git fct_git() { fct_echo "Installing git" apt-get install -y git RC=$? if [ "${RC}" -ne 0 ] then RC=1 fct_echo "Failed to install git" fct_exit fi } ## Function for installing somes puppet modules fct_module_install() { fct_echo "Installing module $1 at version $2 with command puppet module install $1 --version $2" puppet module install $1 --version $2 if [ "$?" -ne 0 ] then RC=1 fct_echo "Failed to install module $1 at version $2" fct_exit else fct_echo "Module $1 successfuly installed at version $2" fi } ## Function for puppet installation fct_puppet_install() { which puppet >/dev/null 2>&1 if [ "$?" -ne 0 ] then fct_echo "Puppet not installed, installing with apt-get install -y puppet please wait..." apt-get install -y puppet >/dev/null 2>&1 RC=$? if [ "${RC}" -ne 0 ] then fct_echo "Could'nt install puppet, try it manually => apt-get install puppet" fct_exit else fct_echo "Puppet is now installed, checking ..." which puppet >/dev/null 2>&1 if [ "$?" -ne 0 ] then RC=1 fct_echo "Puppet not found on this system, install not good" fct_exit else fct_echo "Puppet is installed" fi fi else fct_echo "Puppet already installed, nothing to do" fi } fct_puppet() { if [ ! -f ./manifests/${1}.pp ] then fct_echo "Puppet file ${1}.pp not found" RC=1 fct_exit else fct_echo "Configuration of ${1}" puppet apply -tvd ./manifests/${1}.pp fi } clear echo ' _____ _ _____ _____ _ _ ' echo '| _ |_|_____ ___| |_ _| __ |___ ___| |_| |___ ' echo '| __| | | . | | | | | | __ -| -_| -_| _| | -_|' echo '|__| |_|_|_|_| _|_|_|_|_ |_____|___|___|_| |_|___|' echo ' |_| |___| ' echo '' fct_echo "Welcome to PimpMyBeetle installation ... press enter to continue" ; read NEXT ## Step 0, checking if we are root STEP=" STEP_0" ; fct_echo "Checking if you're root" if [ "$(id -u)" != "0" ] then fct_echo "Bad news, you're not root, please elevate rights" RC=1 && fct_exit else fct_echo "Good news, you're root, continue" fi ## Checking current directory STEP=" STEP_0.2" ; fct_echo "Checking we're under /root" if [ $(pwd) != "/root" ] then fct_echo "Bad news, you're not under /root, please make a cd" RC=1 && fct_exit else fct_echo "Good news, we are under /root" fi ## Step 0.5, checking connection STEP=" STEP_0.5" && fct_internet ## Git installation STEP=" STEP_0.6" && fct_git ## Pull project STEP=" STEP_0.6" && git clone https://github.com/coxifred/PimpMyBeetle.git ## Move into /root/PimpMyBeetle/install cd /root/PimpMyBeetle/install >/dev/null 2>&1 ## Step 1, puppet installation if not yet installed STEP=" STEP_1" && fct_puppet_install ## Step 2, puppet modules installation apt-source STEP=" STEP_2" && fct_module_install puppetlabs-apt 7.0.1 STEP=" STEP_2.1" && fct_module_install puppetlabs-inifile 3.0.0 ## Step 3, configure git preference (vi for editor) STEP=" STEP_3" && fct_puppet git ## Step 4, configure influxDb STEP=" STEP_4" && fct_puppet influxDb ## Step 5, configure grafana STEP=" STEP_5" && fct_puppet grafana STEP=END && fct_echo "Installation finished" && echo "" && echo "" fct_exit