Skip to content

Instantly share code, notes, and snippets.

@glesage
Created August 16, 2015 19:53
Show Gist options
  • Save glesage/616dd8363097672b48e9 to your computer and use it in GitHub Desktop.
Save glesage/616dd8363097672b48e9 to your computer and use it in GitHub Desktop.
admin run script
#!/bin/bash
# Admin run script
# Refresh bash environment
if [ "$(uname)" == "Darwin" ]; then
echo 'Mac: Refreshing ~/.bash_profile'
. ~/.bash_profile
elif [ "$(expr substr $(uname -s) 1 5)" == "Linux" ]; then
echo 'Linux: Refreshing ~/.bashrc'
. ~/.bashrc
elif [ "$(expr substr $(uname -s) 1 10)" == "MINGW32_NT" ]; then
echo 'Windows: Not sure where your bash variables are'
else
echo 'Could not figure out what OS you`re running this from!'
exit
fi
# Attempt to install Node & NPM
if [ "$(uname)" == "Darwin" ];
then
echo -e "${skip}Skip ${nc}- Not on Linux: Skip Dependencies install"
elif [ "$(expr substr $(uname -s) 1 5)" == "Linux" ];
then
if [ ! -f /usr/bin/nodejs ];
then
echo -e "${strt}Start ${nc} - Node Install"
apt-get update -qq
apt-get install -y -qq nodejs
. ~/.bashrc
else
echo -e "${skip}Skip ${nc}- Node Install"
fi
if [ ! -f /usr/bin/node ];
then
echo -e "${strt}Start ${nc}- NodeJS -> Node symlink"
ln -s "$(which nodejs)" /usr/bin/node
else
echo -e "${skip}Skip ${nc}- NodeJS -> Node symlink"
fi
if [ ! -f /usr/bin/npm ];
then
echo -e "${strt}Start ${nc}- NPM install"
apt-get install -y -qq npm
else
echo -e "${skip}Skip ${nc}- NPM install"
fi
elif [ "$(expr substr $(uname -s) 1 10)" == "MINGW32_NT" ];
then
echo -e "${skip}Skip ${nc}- Not on Linux: Skip Dependencies install"
else
echo 'Could not figure out what OS you`re running this from!'
exit
fi
args=("$@")
argCount=0
temp=0
environment=""
npmUpdate=false
for i in "{$args[@]}"
do
if [ $i == "{-env[@]}" ];
then
temp=$((argCount + 1))
environment=${args[$temp]}
fi
if [ $i == "{npm[@]}" ];
then
npmUpdate=true
fi
argCount=$(( argCount + 1))
done
if [ ! -f ~/.starchup_vars ];
then
if [ -z "$API_PORT" ];
then
export API_PORT="3001"
echo export API_PORT="3001" > ~/.starchup_vars
fi
if [ -z "$API" ];
then
export API="http://dev.starchup.com:$API_PORT/api"
echo export API="http://dev.starchup.com:$API_PORT/api" >> ~/.starchup_vars
fi
if [ -z "$PUBLIC"];
then
export PUBLIC="https://starchup.com"
echo export PUBLIC="https://starchup.com" >> ~/.starchup_vars
fi
if [ -z "$ADMIN_PORT" ];
then
export ADMIN_PORT="5000"
echo export ADMIN_PORT="5000" >> ~/.starchup_vars
fi
if [ -z "$ADMIN" ];
then
export ADMIN="http://localhost:$ADMIN_PORT"
echo export ADMIN="http://localhost:$ADMIN_PORT" >> ~/.starchup_vars
fi
echo -e "${strt}Use ${nc}- default environment variables"
else
echo -e "${strt}Use ${nc}- starchup_vars"
source ~/.starchup_vars
fi
if [ ! -z "$environment" ] && [ $environment == "local" ];
then
export API_URL="localhost"
fi
if [ ! -f /usr/local/bin/slc ];
then
echo -e "${strt}Start ${nc}- Strongloop install"
npm install -g --silent strongloop
else
echo -e "${skip}Skip ${nc}- Strongloop install"
fi
if [ ! -f /usr/local/bin/gulp ];
then
echo -e "${strt}Start ${nc}- Gulp install"
npm install -g --silent gulp
else
echo -e "${skip}Skip ${nc}- Gulp install"
fi
if [ ! -h ./node_modules/gulp ];
then
echo -e "${strt}Start ${nc}- Gulp symlink"
npm link --silent gulp
else
echo -e "${skip}Skip ${nc}- Gulp symlink"
fi
if [ "$npmUpdate" = true ];
then
echo -e "${strt}Start ${nc}- NPM Update"
npm update --silent | grep -e error -e warn
else
echo -e "${skip}Skip ${nc}- NPM Update"
fi
gulp --silent &
printf "${strt}Start ${nc}- "
# NODE_ENV=dev node node
slc run
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment