Last active
January 11, 2017 03:48
-
-
Save fullstopslash/e65722a04aa5bae25eeced4ac2875127 to your computer and use it in GitHub Desktop.
A simple bootstrap script.
This file contains 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/bash | |
HOST=$(hostname -s) | |
# Function checks if command exists | |
exists() | |
{ | |
commandApp="$1" | |
set -- $commandApp | |
command -v "$1" >&/dev/null 2>&1 | |
} | |
# Function to check if process is running, otherwise run it with the arguments listed | |
runMe() | |
{ | |
commandApp="$1" | |
set -- $commandApp | |
if pgrep -f "$1" >/dev/null; then | |
# echo "$1 already running" | |
true | |
else | |
# echo "Starting $1" | |
$commandApp >&/dev/null 2>&1 &! | |
fi | |
} | |
# Function to Check hostname | |
checkHost() | |
{ | |
if [[ $(hostname -s) == "$1" ]]; then | |
true | |
else | |
false | |
fi | |
} | |
# Function that reads command and tries to install if not present | |
installMe() | |
{ | |
# commandApp="$1" | |
# set -- "$commandApp" | |
sudo apt-get install -y "$1" | |
if [ $? = 0 ]; then | |
sudo -H pip install "$commandApp" | |
fi | |
} | |
#Function to run app | |
getGoing() | |
{ | |
if exists "$2"; then | |
# echo "$2 is installed" | |
checkHost "$1" | |
if [ $? = 0 ]; then | |
runMe "$2" | |
fi | |
else | |
commandApp="$2" | |
set -- $commandApp | |
# echo "$2 is not installed" | |
installMe "$2" | |
fi | |
} | |
# Settings for autostart.sh | |
# call with getGoing HOSTNAME "command" | |
getGoing HOST1 "command -argument" | |
getGoing HOST2 "command -argument" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment