statuper shell script

pull/78/head
Hunter Long 2018-10-04 22:46:49 -07:00
parent 7241040146
commit eed6720374
2 changed files with 114 additions and 18 deletions

View File

@ -34,6 +34,7 @@ func init() {
} }
func TestWebhookNotifier(t *testing.T) { func TestWebhookNotifier(t *testing.T) {
t.SkipNow()
t.Parallel() t.Parallel()
currentCount = CountNotifiers() currentCount = CountNotifiers()

131
statuper
View File

@ -36,9 +36,16 @@ EOM
# Check requirements # Check requirements
function require() { function require() {
getOS
command -v "$1" > /dev/null 2>&1 || { command -v "$1" > /dev/null 2>&1 || {
echo "Some of the required software is not installed:" echo "Some of the required software is not installed:"
echo " please install $1" >&2; APP="$1" >&2;
echo " Required application: $APP"
if [ $OS == "osx" ]; then
echo " You can run 'brew install $APP'"
elif [ $OS == "linux" ]; then
echo " You can run 'apt install $APP'"
fi
exit 4; exit 4;
} }
} }
@ -64,6 +71,10 @@ function awsAskRegion {
fi fi
} }
get_latest_release() {
STATUP_VERSION=$(curl --silent "https://api.github.com/repos/$DOCKER_IMG/releases/latest" | jq -r .tag_name)
}
function askEC2Name { function askEC2Name {
read -p "Enter the Name for EC2 Instance: " SERVERNAME read -p "Enter the Name for EC2 Instance: " SERVERNAME
} }
@ -88,6 +99,14 @@ function askSecurityName {
read -p "Enter a name for the new Security Group: " EC2SECGROUP read -p "Enter a name for the new Security Group: " EC2SECGROUP
} }
function askInstallGlobal {
read -p "Do you want to move Statup to the bin folder? (y/N): " MOVEBIN
}
function askInstallSystemCTL {
read -p "Do you want to auto start Statup on boot? (y/N): " SYSTEMCTL
}
function awsSecurityGroup { function awsSecurityGroup {
echo "Running task: Creating Security Group"; echo "Running task: Creating Security Group";
GROUPID=`$AWS_ECS ec2 create-security-group --group-name "$EC2SECGROUP" --description "Statup HTTP Server on port 80 and 443" | jq -r .GroupId` GROUPID=`$AWS_ECS ec2 create-security-group --group-name "$EC2SECGROUP" --description "Statup HTTP Server on port 80 and 443" | jq -r .GroupId`
@ -129,12 +148,6 @@ function checkEC2Instance {
fi fi
} }
function awsTest {
INSTANCE_ID="i-0768e3d5ba00897af"
checkEC2Instance
ec2TaskComplete
}
function awsTask { function awsTask {
setAWSPresets setAWSPresets
askEC2Name askEC2Name
@ -152,8 +165,56 @@ function awsTask {
ec2TaskComplete ec2TaskComplete
} }
function moveToBin {
mv statup /usr/local/bin/statup
}
function installSystemCTL {
FILE=statup.service
cat > $FILE <<- EOM
[Unit]
Description=Statup Server
After=network.target
After=systemd-user-sessions.service
After=network-online.target
[Service]
Type=simple
Restart=always
ExecStart=/usr/local/bin/statup
[Install]
WantedBy=multi-user.target
EOM
echo "Installing systemctl service file to: /etc/systemd/system/$FILE"
mv $FILE /etc/systemd/system/$FILE
systemctl daemon-reload
systemctl enable statup.service
systemctl start statup
echo "Statup has been installed to SystemCTL and will start on boot"
}
function localTask { function localTask {
echo "installing locally" getOS
getArch
get_latest_release
GIT_DOWNLOAD="https://github.com/$DOCKER_IMG/releases/download/$STATUP_VERSION/statup-$OS-$ARCH.tar.gz"
echo "Downloading Statup $STATUP_VERSION from $GIT_DOWNLOAD"
curl -L --silent $GIT_DOWNLOAD | tar xz
echo "Download complete"
echo "Try Statup by running 'statup version'!"
askInstallGlobal
if [ $MOVEBIN == "y" ]; then
moveToBin
echo "Statup can now be ran anywhere with command 'statup'"
echo "Install location: /usr/local/bin/statup"
if [ $OS == "linux" ]; then
askInstallSystemCTL
if [ $SYSTEMCTL == "y" ]; then
installSystemCTL
fi
fi
fi
} }
function dockerTask { function dockerTask {
@ -161,6 +222,40 @@ function dockerTask {
$DOCKER_CLI run -d -p $DOCKER_PORT:8080 $DOCKER_IMG $DOCKER_CLI run -d -p $DOCKER_PORT:8080 $DOCKER_IMG
} }
function getArch {
MACHINE_TYPE=`uname -m`
if [ ${MACHINE_TYPE} == 'x86_64' ]; then
ARCH="x64"
else
ARCH="x32"
fi
}
function getOS {
OS="`uname`"
case $OS in
'Linux')
OS='linux'
alias ls='ls --color=auto'
;;
'FreeBSD')
OS='freebsd'
alias ls='ls -G'
;;
'WindowsNT')
OS='windows'
;;
'Darwin')
OS='osx'
;;
'SunOS')
OS='solaris'
;;
'AIX') ;;
*) ;;
esac
}
if [ "$BASH_SOURCE" == "$0" ]; then if [ "$BASH_SOURCE" == "$0" ]; then
set -o errexit set -o errexit
set -o pipefail set -o pipefail
@ -196,9 +291,12 @@ if [ "$BASH_SOURCE" == "$0" ]; then
VERBOSE=true VERBOSE=true
;; ;;
-v|--version) -v|--version)
echo ${VERSION} require jq
usage get_latest_release
exit 2 echo "Statup Latest: $STATUP_VERSION"
echo "Statuper Tool: v$VERSION"
getOS
echo $OS
exit 0 exit 0
;; ;;
*) *)
@ -218,12 +316,6 @@ if [ "$BASH_SOURCE" == "$0" ]; then
awsTask awsTask
exit 0 exit 0
;; ;;
awstest)
require aws
require jq
awsTest
exit 0
;;
docker) docker)
require docker require docker
dockerTask dockerTask
@ -234,7 +326,10 @@ if [ "$BASH_SOURCE" == "$0" ]; then
dockerComposeTask dockerComposeTask
exit 0 exit 0
;; ;;
local) install)
require jq
require curl
require tar
localTask localTask
shift # past argument shift # past argument
;; ;;