Skip to content

Commit

Permalink
Initial Seed
Browse files Browse the repository at this point in the history
  • Loading branch information
duncan-mccracken committed May 15, 2018
1 parent 0bd8262 commit da52d10
Show file tree
Hide file tree
Showing 407 changed files with 13,594 additions and 0 deletions.
41 changes: 41 additions & 0 deletions CreatePatchServer.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/bin/bash
# This script generates a new Patch Server Installer

timeEcho() {
echo $(date "+[%Y-%m-%d %H:%M:%S]: ") "$1"
}

alias md5='md5 -r'
alias md5sum='md5 -r'

echo ""
timeEcho "Building Patch Server Installer..."

# Clean-up old files
rm -f PatchServerInstaller.run 2>&1 > /dev/null
rm -Rf temp 2>&1 > /dev/null

#mkdir temp
mkdir -p temp/installer/checks
mkdir -p temp/installer/resources
mkdir -p temp/installer/utils
cp -R base/PatchInstaller.sh temp/installer/install.sh
cp -R base/testNetSUSRequirements.sh temp/installer/checks/testNetSUSRequirements.sh
cp -R includes/logger.sh temp/installer/utils/logger.sh
cp -R patchserver/patchInstall.sh temp/installer/install-patch_v1.sh
cp -R patchserver/var/appliance/db/* temp/installer/resources/
cp -R patchserver/var/www temp/installer/resources/html
if [ -x "/usr/bin/xattr" ]; then find temp -exec xattr -c {} \; ;fi # Remove OS X extended attributes
find temp -name .DS_Store -delete # Clean out .DS_Store files
find temp -name .svn | xargs rm -Rf # Clean out SVN garbage


# Generate final installer
timeEcho "Creating final installer..."
bash makeself/makeself.sh temp/installer/ PatchServerInstaller.run "Patch Server Installer" "bash install.sh"

timeEcho "Cleaning up..."
rm -Rf temp 2>&1 > /dev/null
timeEcho "Finished creating the Patch Server Installer. "

exit 0
122 changes: 122 additions & 0 deletions base/PatchInstaller.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
#!/bin/bash
# This script controls the flow of the Linux Patch Definition Server installation

export PATH="/bin:$PATH"

netsusdir=/var/appliance

#==== Check Requirements - Root User ======================#

if [[ "$(id -u)" != "0" ]]; then
echo "The Patch Definition Server Installer needs to be run as root or using sudo."
exit 1
fi

# Needed for systems with secure umask settings
OLD_UMASK=$(umask)
umask 022

clean-exit() {
umask "$OLD_UMASK"
exit 0
}

clean-fail() {
umask "$OLD_UMASK"
exit 1
}

# Create NetSUS directory (needed immediately for logging)
mkdir -p $netsusdir/logs

source utils/logger.sh

#==== Parse Arguments =====================================#

export INTERACTIVE=true

while getopts "hny" ARG
do
case $ARG in
h)
echo "Usage: $0 [-y]"
echo "-y Activates non-interactive mode, which will silently install the NetSUS without any prompts"
echo "-h Shows this message"
exit 0
;;
n)
logCritical "The -n flag is deprecated and will be removed in a future version.
Please use -y instead."
export INTERACTIVE=false
;;
y)
export INTERACTIVE=false
;;
esac
done

#==== Check Requirements ==================================#

log "Starting the Patch Definition Server Installation"
log "Checking installation requirements..."

failedAnyChecks=0
# Check for Valid NetSUS
bash checks/testNetSUSRequirements.sh || failedAnyChecks=1

# Abort if we failed any checks
if [[ $failedAnyChecks -ne 0 ]]; then
log "Aborting installation due to unsatisfied requirements."
if [[ $INTERACTIVE = true ]]; then
# shellcheck disable=SC2154
echo "Installation failed. See $logFile for more details."
fi
clean-fail
fi

log "Passed all requirements"

#==== Prompt for Confirmation =============================#

if [[ $INTERACTIVE = true ]]; then
# Prompt user for permission to continue with the installation
echo "
The following will be installed
* Patch Definition Server
"

# shellcheck disable=SC2162,SC2034
read -t 1 -n 100000 devnull # This clears any accidental input from stdin

while [[ $REPLY != [yYnN] ]]; do
# shellcheck disable=SC2162
read -n1 -p "Proceed? (y/n): "
echo ""
done
if [[ $REPLY = [nN] ]]; then
log "Aborting..."
clean-exit
else
log "Installing..."
log ""
fi
else
log "Installing..."
log ""
fi

#==== Initial Cleanup tasks ===============================#

#==== Install Components ==================================#

bash install-patch_v1.sh || clean-fail

#==== Post Cleanup tasks ==================================#

log ""
log "The Patch Definition Server has been installed."
log "To complete the installation, open a web browser and navigate to https://${HOSTNAME}:443/."
log "If you are installing the Patch Definition Server for the first time, please follow the documentation for setup instructions."
log ""

clean-exit
12 changes: 12 additions & 0 deletions base/testNetSUSRequirements.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash

logNoNewLine "Checking for NetSUS 4.1.0 or later..."

if [ ! -e /var/www/html/webadmin/theme/bootstrap.css ]; then
log "Error: Failed to to detect valid NetSUS installation."
exit 1
fi

log "OK"

exit 0
39 changes: 39 additions & 0 deletions includes/logger.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/bin/bash

export logFile="/var/appliance/logs/patchinstaller.log"

mkLogDir() {
if [ ! -f "$logFile" ]
then
mkdir -p "$(dirname $logFile)"
fi
}

timestamp() {
date "+[%Y-%m-%d %H:%M:%S]: "
}

logToFile() {
echo "$(timestamp)" "$1" >> $logFile
}

log(){
mkLogDir

if [[ $INTERACTIVE = true ]]
then
echo "$@"
fi

logToFile "${@: -1}"
}

logCritical(){
INTERACTIVE=true log "$1"
}

logNoNewLine(){
log -n "$1"
}

export -f log logCritical logNoNewLine logToFile timestamp mkLogDir
Loading

0 comments on commit da52d10

Please sign in to comment.