Created
June 12, 2017 11:26
-
-
Save sydseter/c293bd8f941145892d23a5685bf23c86 to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env bash | |
# | |
# Simple bootstrapping program for the "aptoma" project. | |
# Should work on Darwin and Debian | |
set -o nounset | |
set -o errtrace | |
set -o errexit | |
set -o pipefail | |
# Text color variables | |
declare -r txtund=$(tput sgr 0 1) # Underline | |
declare -r txtbld=$(tput bold) # Bold | |
declare -r bldred=${txtbld}$(tput setaf 1) # red | |
declare -r bldyellow=${txtbld}$(tput setaf 3) # yellow | |
declare -r bldgreen=$(tput setaf 2) # green | |
declare -r bldpurp=${txtbld}$(tput setaf 5) # purple | |
declare -r bldblu=${txtbld}$(tput setaf 4) # blue | |
declare -r bldwht=${txtbld}$(tput setaf 7) # white | |
declare -r txtrst=$(tput sgr0) # Reset | |
declare -r isNumber='^[0-9]+$'; | |
declare -r vagrant_repo='https://github.com/aptoma/drvideo-vagrant.git'; | |
declare installdir=""; | |
# make sure we don't leave the terminal with some strange color | |
trap "printf '%b${txtrst}'" EXIT; | |
function say () { | |
printf "\n${bldwht}%b${txtrst}\n" "$*"; | |
} | |
function brag () { | |
printf "\n${bldpurp}%b${txtrst}\n" "$*"; | |
} | |
function warn () { | |
printf "\n${bldyellow}WARN: %b${txtrst}\n" "$*"; | |
} | |
function error () { | |
printf "\n${bldred}ERROR: %b${txtrst}\n" "$*"; | |
} | |
function fail () { | |
printf "\n${bldred}FATAL ERROR: %b${txtrst}\n" "$*"; | |
exit 1; | |
} | |
function info () { | |
printf "\n${bldgreen}%b${txtrst}\n" "$*"; | |
} | |
function prompt_yes_no () { | |
local choice; | |
builtin read -p "${bldblu}$1 (y/n): ${txtrst}" -r choice; | |
case $choice in | |
y|Y) echo "yes";; | |
n|N) echo "no";; | |
*) echo "invalid";; | |
esac | |
} | |
function prompt_string () { | |
local answer; | |
builtin read -ep "${bldblu}$1:${txtrst} | |
" -r answer; | |
if [ ! -z "$answer" ]; then | |
echo $answer; | |
return 0; | |
else | |
return 1; | |
fi | |
} | |
function wait_for_keypress () { | |
local answer; | |
builtin read -n 1 -p "${bldblu}Press any key to continue${txtrst}" -r answer; | |
} | |
function open_url () { | |
local -r url=$1; | |
case "$(uname)" in | |
Darwin) | |
open $1; | |
;; | |
Linux) | |
BROWSER=${BROWSER:-}; | |
if [ ! -z "$BROWSER" ]; then | |
$BROWSER "$url"; | |
elif which xdg-open > /dev/null; then | |
xdg-open "$url"; | |
elif which gnome-open > /dev/null; then | |
gnome-open "$url"; | |
else | |
warn "What kind of webbrowser are you using on your system anayway? curl??? | |
Have you been living under a stone? Chrome is the shit!! | |
Please copy&past this url: $url. | |
and open it in your marginated Hyper Text Transport Protocol Reader"; | |
fi | |
;; | |
*) | |
warn "You are using Windows!! Yuck!! Shame on yourself. | |
copy&past this url: $url. and open it in your marginated | |
Hyper Text Transport Protocol Reader"; | |
;; | |
esac | |
return 0; | |
} | |
function abort_not_installed () { | |
local -r progname=$1; | |
local -r prog_url=$2; | |
say "You do not have $progname, and you call yourself a developer? Incompetent fool!"; | |
local answer=$(prompt_yes_no \ | |
"I will give you on more chance to go to the $progname website "\ | |
"to download and install it ASAP. Will You do it?"); | |
[[ $answer == "yes" ]] && open_url $prog_url; | |
answer=$(prompt_yes_no \ | |
"Have you managed to install this $programe crap yet?"); | |
[[ $answer == "yes" ]] && say "Good boy. Now go and roll over." && return 0; | |
warn "\nYou are such an idiot! I guess you have to do it manually. "\ | |
"Try to run this script again before bothering the guy that wrote me."; | |
return 2; | |
} | |
function abort_too_old () { | |
local -r progname=$1; | |
local -r prog_url=$2; | |
local -r minver=$3; | |
say "$progname is too old, and so are you (you need at least $minver)!"; | |
local answer=$(prompt_yes_no \ | |
"Do you want to visit the $progname website to upgrade your ass?"); | |
[[ $answer == "yes" ]] && open_url $prog_url; | |
answer=$(prompt_yes_no \ | |
"Have you managed to install this $programe crap yet?"); | |
[[ $answer == "yes" ]] && say "Good! I guess you are cool again" && return 0; | |
warn "\nTry running this script again after upgrading $progname, you old unix dog!"; | |
return 2; | |
} | |
# http://stackoverflow.com/questions/4023830/bash-how-compare-two-strings-in-version-format | |
function vercomp () { | |
if [ $1 == $2 ];then | |
echo 0; | |
return 0; | |
fi | |
local IFS=.; | |
local i ver1=($1) ver2=($2); | |
# fill empty fields in ver1 with zeros | |
for ((i=${#ver1[@]}; i<${#ver2[@]}; i++)) | |
do | |
ver1[i]=0; | |
done | |
for ((i=0; i<${#ver1[@]}; i++)) | |
do | |
if [ -z ${ver2[i]} ];then | |
# fill empty fields in ver2 with zeros | |
ver2[i]=0; | |
fi | |
if [ ${ver1[i]} -gt ${ver2[i]} ];then | |
echo 1; | |
return 0; | |
fi | |
if [ ${ver1[i]} -lt ${ver2[i]} ];then | |
echo 2; | |
return 0; | |
fi | |
done | |
echo 0; | |
return 0; | |
} | |
function found () { | |
hash $1 2>&-; | |
} | |
# installs all dependencies given as arguments | |
function deps () { | |
local dep; | |
local last=$(expr $#) | |
local last_dep=${@:$last}; | |
for dep in $@; do | |
if [ "$(type -t is_${dep}_installed)" == 'function' ]; then | |
if ! is_${dep}_installed; then | |
if [ $(type -t install_$dep) == 'function' ]; then | |
info "Installing $dep..."; | |
install_$dep && [ "${last_dep}" = "${dep}" ] && return 0 || continue; | |
error "Could not install $dep." \ | |
"Please don't send med to /dev/null to die!"\ | |
" I promise to be good next time."; | |
return 1; | |
fi | |
error "There are no function called install_${dep}."; | |
error "$dep is not installed and no code to install it was found." \ | |
"Please don't send med to /dev/null to die! I promise to be good next time."; | |
return 1; | |
fi | |
[ "${last_dep}" = "${dep}" ] && return 0 || continue; | |
fi | |
error "There are no function called is_${dep}_installed."; | |
return 1; | |
done | |
return 0; | |
} | |
### virtualbox | |
function is_virtualbox_installed () { | |
found VBoxManage || return 1; | |
return 0; | |
} | |
function install_virtualbox () { | |
local -r virtualbox_url='https://www.virtualbox.org/'; | |
case "$(uname)" in | |
Darwin) | |
abort_not_installed "VirtualBox" $virtualbox_url; | |
return 1; | |
;; | |
Linux) | |
if found apt-get; then | |
say "Trying to install virtualbox - this might require god given sudo powers."; | |
if (( UID )); then | |
sudo apt-get install virtualbox || return 1; | |
sudo apt-get install virtualbox-dkms || return 1; | |
else | |
apt-get install virtualbox || return 1; | |
apt-get install virtualbox-dkms || return 1; | |
fi | |
fi | |
return 0; | |
;; | |
*) | |
error "Could not install virtualbox. You incompetent fool. \n"\ | |
"I guess you have to do it manually. Try running this script again before \n"\ | |
"bothering the guy that wrote me."; | |
esac | |
} | |
### ruby | |
function install_ruby () { | |
case "$(uname)" in | |
Darwin) | |
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" | |
brew install rbenv ruby-build | |
echo 'if which rbenv > /dev/null; then eval "$(rbenv init -)"; fi' >> ~/.bash_profile | |
source ~/.bash_profile | |
rbenv install 2.3.1 | |
rbenv global 2.3.1 | |
ruby -v | |
;; | |
Linux) | |
if found apt-get; then | |
say "Trying to install ruby - this might require god given sudo powers."; | |
if (( UID )); then | |
sudo apt-get install ruby; | |
else | |
apt-get install ruby; | |
fi | |
fi | |
;; | |
*) | |
fail "\nCould not install ruby. You incompetent fool. "\ | |
"I guess you have to do it manually. Try running this script again before "\ | |
"bothering the guy that wrote me."; | |
esac | |
} | |
function is_ruby_installed () { | |
found ruby; | |
} | |
### ssh | |
function install_ssh () { | |
case "$(uname)" in | |
Darwin) | |
deps 'ruby'; | |
brew install openssh && return 0; | |
;; | |
Linux) | |
if found apt-get; then | |
say "Trying to install ssh - this might require god given sudo powers"; | |
if (( UID )); then | |
sudo apt-get install openssh-client && return 0; | |
else | |
apt-get install openssh-client && return 0; | |
fi | |
fi | |
error "You do not have apt-get on your system." && return 1; | |
;; | |
*) | |
error "Could not install ssh. You incompetent fool. "\; | |
"I guess you have to do it manually. Try running this script again before "\ | |
"bothering the guy that wrote me."; | |
return 1; | |
esac | |
} | |
function is_ssh_installed () { | |
found ssh; | |
} | |
function ssh_list_keys () { | |
eval `ssh-agent -s`; | |
if [[ "$(ssh-add -L)" =~ 'no identities' ]]; then | |
if [[ -d ~/.ssh && -e ~/.ssh/id_rsa.pub ]]; then | |
cat ~/.ssh/id_rsa.pub; | |
else | |
warn "no ssh keys found. Who are you anyway?"; | |
fi | |
else | |
ssh-add -L; | |
fi | |
} | |
function generate_ssh_key () { | |
email=$(prompt_string "Please enter your email address (will be used in your ssh key "\ | |
"and not to spam your ass motherfucker!"); | |
if ssh-keygen -t rsa -C "$email"; then | |
say "Now I know who you are. You are good dam ugly. I guess you aren't a motherfucker after all.". | |
say "The ssh key should be listed below:" | |
ssh_list_keys; | |
if [[ -e ~/.ssh/id_rsa.pub && "$(uname)" == "Darwin" ]]; then | |
pbcopy < ~/.ssh/id_rsa.pub; | |
say "The public key generated has been copied for your sorry ass to the "\ | |
"clipboard (ready to be pasted into your looser github ssh key page)"; | |
fi | |
return 0; | |
else | |
fail "Could not generate a new ssh key for you. You incompetent fool! "\ | |
"I guess you have to do it manually. Try running this script again before "\ | |
"bothering the guy that wrote me."; | |
fi | |
} | |
function has_ssh_keys () { | |
[[ ( -d ~/.ssh && -e ~/.ssh/id_rsa.pub ) || ! ( "$(ssh-add -L)" =~ 'no identities' ) ]]; | |
} | |
### git | |
function is_git_installed () { | |
found git; | |
} | |
function install_git () { | |
case "$(uname)" in | |
Darwin) | |
deps 'ruby'; | |
brew install git; | |
;; | |
Linux) | |
if found apt-get; then | |
say "Trying to install the amazingly cool git - this might require god given sudo powers."; | |
if (( UID )); then | |
sudo apt-get install git; | |
else | |
apt-get install git; | |
fi | |
fi | |
;; | |
*) | |
fail "Could not install git. You incompetent fool! "\ | |
"I guess you have to do it manually. Try running this script again before "\ | |
"bothering the guy that wrote me."; | |
esac | |
} | |
### Access to github | |
function is_gitaccess_installed () { | |
deps 'ssh' || | |
(error "Could not install gitaccess dependencies: ssh. Please don't send me to /dev/null to die!!!" && return 1); | |
local answer=$(ssh -T git@github.com 3>&1 1>&2- 2>&3-); | |
[[ "$answer" =~ "successfully authenticated" ]]; | |
} | |
# FIXME: To be able to correctly generate a ssh key. | |
# I would have to ensure that the sshd is running. | |
# This is more work then I want to do. So I would just | |
# tell the user to do it manually. | |
function install_gitaccess () { | |
deps 'git' 'ssh' || | |
(error "could not install gitaccess dependencies: git and ssh. Please don't send me to /dev/null to die!!!" && return 1 ); | |
warn "You do not have a proper ssh key to access git hub. "\ | |
"You will have to create one. We can take you to a website "\ | |
"where you can follow a recipy that will give you access."; | |
l ical answer=$(prompt_yes_no \ | |
"Do you want to go to the website where the recipy is?"); | |
[[ $answer == "yes" ]] && | |
open_url "https://help.github.com/articles/generating-ssh-keys/" || | |
warn "I will not be able to setup aptoma without you setting up a ssh key."; | |
local success=false; | |
display_github_sshkey_message && success=true || success=false; | |
while [ $success == false ] | |
do | |
display_github_sshkey_message && success=true || success=false; | |
[ $success == false ] && warn "You did not setup proper github access, mooron!!" && | |
repeat_or_fail_prompt && continue || return 1; | |
! is_gitaccess_installed && warn "Oh, but the key(s) you have doesn't appear to work with github? "\ | |
"What could I expect from a moroon like you. Your existing public keys:" && | |
ssh_list_keys && say "" && | |
repeat_or_fail_prompt && success=false && continue || return 1; | |
done | |
say "It seems that you can access github with your ssh key."; | |
return 0; | |
} | |
function display_github_sshkey_message () { | |
say "You need to configure github with (one of) your shitty ass ssh public keys.\n"\ | |
"Log into your looser github account and add the shitty ssh key.\n"\ | |
"You will be sent to their stupid site where this can be done.\n"\ | |
"Do I need to do everything around here? Press enter please!"; | |
wait_for_keypress; | |
open_url 'https://github.com/settings/ssh'; | |
repeat_or_fail_git_prompt && return 0 || return 1; | |
} | |
function repeat_or_fail_git_prompt() { | |
local answer=$(prompt_yes_no \ | |
"Have you done the crap I told you yet? | |
You know, git ssh key?, github page? copy&past? chop, chop. | |
what are you waiting for!"); | |
[[ $answer == "yes" ]] || error "Could not access git via ssh. You mooron! | |
I guess you have to do it manually." && return 1; | |
say "Good boy, now roll over!"; | |
return 0; | |
} | |
### vagrant | |
function is_vagrant_installed () { | |
if found vagrant; then | |
local answer=''; | |
local ver=$(vagrant --version | sed -E 's/Vagrant (version)? ?([0-9]+\.[0-9]+\.[0-9]+)$/\2/'); | |
local -r minver='1.7.0'; | |
local result; | |
result=$(vercomp "${ver}" $minver); | |
if [ "$result" = "2" ]; then | |
warn "You should install vagrant version: $minver "\ | |
"You have version $ver" && answer=$(prompt_yes_no \ | |
"Do you want to upgrade it?"); | |
[ $answer == "yes" ] && install_vagrant || warn "Die of all age, You relic!!"\ | |
"Go and find some production server you can rape.\n"\ | |
"aptoma-vagrant might work, but you won't be playing with the really cool vagrant features."; | |
fi | |
local -r ancient='1.1.0'; | |
result=$(vercomp "$ver" $minver); | |
if [ "$result" = "2" ]; then | |
warn "Your vagrant $ver is ancient. You must at least install vagrant version: "$ancient; | |
answer=$(prompt_yes_no \ | |
"Do you want to upgrade it?"); | |
[ $answer == "yes" ] && install_vagrant || fail "This is a deal breaker. Die of all age, You relic!!"\ | |
"Go and find some production server you can rape.\n"\ | |
"aptoma-vagrant will never work with this versions less then $ancient"; | |
fi | |
say "A sufficent version for vagrant is installed." | |
return 0; | |
else | |
return 1; | |
fi | |
} | |
function install_vagrant () { | |
local -r vagrant_url='https://releases.hashicorp.com/vagrant/1.8.6/'; | |
local url; | |
local file; | |
case "$(uname)" in | |
Darwin) | |
url='https://releases.hashicorp.com/vagrant/1.8.6/vagrant_1.8.6.dmg' | |
file=`mktemp`; curl "$url" -o $file && hdiutil mount $file; rm $file | |
;; | |
Linux) | |
url='https://releases.hashicorp.com/vagrant/1.8.6/vagrant_1.8.6_x86_64.deb' | |
file=`mktemp`; wget "$url" -qO $file && sudo dpkg -i $file; rm $file | |
;; | |
*) | |
warn "Could not install stupid vagrant. Are you using windows moroon? "\ | |
" If so, I can not help you. "\ | |
"I guess you have to do it manually."; | |
abort_not_installed "vagrant" $vagrant_url || return 1; | |
esac | |
found vagrant || abort_not_installed "vagrant" $vagrant_url || return 1; | |
return 0; | |
} | |
function is_vagrant_plugins_installed () { | |
return 1; | |
} | |
function install_vagrant_plugins () { | |
deps 'aptoma_vagrant' 'vagrant' || | |
(error "aptoma-vagrant and vagrant did not get installed. Please don't send me to /dev/null to die!!!" && return 1); | |
repodir=$(basename $vagrant_repo '.git'); | |
local -r vagrant_plugins_file=$installdir"/"$repodir"/vagrant_plugins"; | |
[ ! -f $vagrant_plugins_file ] && touch $vagrant_plugins_file && | |
say "The vagrant_plugins file $vagrant_plugins_file did not exist, but was created.\n"\ | |
"Please add some vagrant_plugins to the vagrant_plugins file if needed!\n"\ | |
"each plugin in the file needs to be on a separate line in the file. \n"\ | |
"Do I have to do everything around here!!" && popd > /dev/null && return 0; | |
IFS=$'\r\n' vagrant_plugins=($(cat "${vagrant_plugins_file}")); | |
[ -z ${vagrant_plugins:-} ] && popd > /dev/null && return 0; | |
say "Going to install the following crappy vagrant plugins: $vagrant_plugins"; | |
info "This may take some time. Prepare to die of old age!!!"; | |
local vagrant_plugin=''; | |
local installed=true; | |
for vagrant_plugin in $vagrant_plugins; do | |
[ "$(vagrant plugin list | grep $vagrant_plugin | cut -d' ' -f1)" = "$vagrant_plugin" ] && continue; | |
! vagrant plugin install $vagrant_plugin && installed=false && | |
error "Could not install the crappy $vagrant_plugin. Your vagrant version might not be high enough."; | |
done | |
[ $installed == true ] && say "Lucky you! All the crappy plugins is installed." && return 0; | |
warn "The crappy plugins didn't get installed. Who would have guessed!\n"\ | |
"You will have to install vagrant-plugin-bundler and vagrant-hostsupdater manually.\n"\ | |
"Try running this script again before "\ | |
"bothering the guy that wrote me." && return 1; | |
} | |
function is_installdir_installed () { | |
[ ! -z $installdir ] && [ -w "$installdir" ] && return 0; | |
[ ! -z $installdir ] && mkdir -p $installdir && return 0; | |
return 1; | |
} | |
function install_installdir () { | |
create_installdir && local success=true || local success=false; | |
local count=0; | |
while [ $success == false ] | |
do | |
echo "trying again..."; | |
create_installdir && success=true || success=false; | |
done | |
} | |
function create_installdir () { | |
local workdir=''; | |
workdir=$(prompt_string \ | |
"Type the name of a directory where the crap will be created"); | |
[ -z $workdir ] && | |
warn "You didn't specify any directory. Did your hand slip!" && | |
repeat_or_fail_prompt && | |
return 1; | |
! mkdir -p $workdir && | |
warn "The crap can not be created there. Pick somewhere else!" && | |
repeat_or_fail_prompt && | |
return 1; | |
installdir=$workdir; | |
[ $(basename $installdir) = '.' ] && installdir=$(pwd) | |
[ ! -w $installdir ] && | |
warn "The crap can't be written there. You don't have the mucle. You need sudo for that!" && | |
repeat_or_fail_prompt && | |
return 1; | |
say "The crap will be installed to: "$installdir; | |
return 0; | |
} | |
function repeat_or_fail_prompt() { | |
local answer=$(prompt_yes_no "Do you want to try this crap again?") && | |
[[ $answer == "yes" ]] || fail "The crap could not be installed."; | |
return 0; | |
} | |
function is_aptoma_vagrant_installed() { | |
deps 'installdir' 'git' || | |
(error "Could not install the dependencies for aptoma-vagrant: installdir" && return 1); | |
repodir=$(basename $vagrant_repo '.git'); | |
[ -w $installdir"/"$repodir/".git" ] && return 0 | |
return 1; | |
} | |
function install_aptoma_vagrant() { | |
deps 'installdir' 'git' || | |
(error "You did not choose a proper installation directory to install from. Aborting." && return 1); | |
local -r td=$installdir; | |
local repo; | |
local repodir; | |
pushd $td > /dev/null; | |
say "Going to check out all the aptoma-vagrant crap into $PWD. | |
This may take some time. Prepare to die of old age..."; | |
say "Please make sure you have generated and are using an oauth token. see: https://help.github.com/articles/git-automation-with-oauth-tokens/" | |
local success=false; | |
repodir=$(basename $vagrant_repo '.git'); | |
if [[ ! -d "$repodir" || ! -d "$repodir"/.git ]]; then | |
while [ $success == false ] | |
do | |
git clone --recursive $vagrant_repo && success=true || success=false; | |
popd > /dev/null; | |
is_aptoma_vagrant_installed && success=true || success=false; | |
[ $success == false ] && warn "You did not clone this $repodir crap, mooron!!" && | |
say "Please make sure you have generated and are using an oauth token. see: https://help.github.com/articles/git-automation-with-oauth-tokens/" && | |
repeat_or_fail_prompt && continue || return 0; | |
done | |
else | |
say "Found the $repodir crap."; | |
say "Fetching the latest crap."; | |
pushd $repodir > /dev/null; | |
if ! git pull; then | |
warn "Unable to update to the latest crap version for the crappy $repodir repo. "\ | |
"You have to do the crap yourself." | |
fi | |
popd > /dev/null; | |
fi | |
popd > /dev/null; | |
return 0; | |
} | |
#FIXME: I am going to put all the repositories on the inside of the box for now. | |
# It make me more able to mirror a production setup and will make it easier to setup secret deploy keys. | |
function checkout_git_repos () { | |
deps 'git'; | |
local git_repos; | |
local repo; | |
local repodir; | |
local -r td=$1; | |
pushd $installdir > /dev/null; | |
say "Going to check out all the crappy aptoma repositories into $installdir. | |
This may take some time. Prepare to die of old age!!!"; | |
if [ ! -z ${git_repos:-} ]; then | |
unset repo; | |
unset repodir; | |
for repo in $git_repos; do | |
repodir=$(basename $repo '.git')'../'; | |
if [[ ! -d "$repodir" || ! -d "$repodir"/.git ]]; then | |
if ! git clone --recursive $repo; then | |
say "Could not clone the crappy $repodir repo. The repository might allready be cloned out."; | |
fi | |
else | |
say "Found the crappy $repodir repo."; | |
say "Fetching the latest crap."; | |
pushd $repodir > /dev/null; | |
if ! git pull; then | |
warn "Unable to update to the latest crap version of the code for $repodir repo. "\ | |
"You have to do the crap yourself."; | |
fi | |
popd > /dev/null; | |
fi | |
done | |
fi | |
popd > /dev/null; | |
return 0; | |
} | |
function is_chef_deploy_keys_installed () { | |
[ -f ~/.chef/deploy_data_bag_secret ] && [ -f ~/.chef/aptoma_deploy.pem ] && return 0; | |
return 1; | |
} | |
function install_chef_deploy_keys () { | |
deps 'ssh'; | |
info "If you are a developer at aptoma, you might want to setup a environment\n"\ | |
"that is able to deploy code to production, but to be able to do so\n"\ | |
"you have to setup deploy keys. To setup these keys, you have to have a ssh key\n"\ | |
"on your local machine that is connected to the aptoma user group that is used\n"\ | |
"on all the servers."; | |
local access=false; | |
local answer=$(prompt_yes_no "Do you have such a ssh key?"); | |
[[ $answer == "no" ]] && say "Who are you anyway? Please setup this ssh key and run this script again if you want to deploy code." && return 0; | |
answer=$(prompt_yes_no "Do you want to be able to deploy code?"); | |
[[ $answer == "no" ]] && say "Coward!! Stop beeing such a sissy. Run this script again if you change your mind." && return 0; | |
ssh -q aptoma@hageslange.aptoma.no exit && access=true; | |
[[ $access == true ]] && mkdir ~/.chef && | |
scp aptoma@hageslange.aptoma.no:~/.chef/aptoma_deploy.pem ~/.chef/aptoma_deploy.pem && | |
scp aptoma@hageslange.aptoma.no:~/.chef/deploy_data_bag_secret ~/.chef/deploy_data_bag_secret || return 1; | |
return 0; | |
} | |
function show_done_message () { | |
printf "${bldblu}%b" "" | |
cat <<"EOF" | |
______ __ ____ __ __ | |
/\ _ \ /\ \__ /\ _`\ /\ \__ /\ \__ | |
\ \ \L\ \ _____\ \ ,_\ ___ ___ ___ __ \ \ \L\ \ ___ ___\ \ ,_\ ____\ \ ,_\ _ __ __ _____ __ _ __ | |
\ \ __ \/\ '__`\ \ \/ / __`\ /' __` __`\ /'__`\ \ \ _ <' / __`\ / __`\ \ \/ /',__\\ \ \/ /\`'__\/'__`\ /\ '__`\ /'__`\/\`'__\ | |
\ \ \/\ \ \ \L\ \ \ \_/\ \L\ \/\ \/\ \/\ \/\ \L\.\_ \ \ \L\ \/\ \L\ \/\ \L\ \ \ \_/\__, `\\ \ \_\ \ \//\ \L\.\_\ \ \L\ \/\ __/\ \ \/ | |
\ \_\ \_\ \ ,__/\ \__\ \____/\ \_\ \_\ \_\ \__/.\_\ \ \____/\ \____/\ \____/\ \__\/\____/ \ \__\\ \_\\ \__/.\_\\ \ ,__/\ \____\\ \_\ | |
\/_/\/_/\ \ \/ \/__/\/___/ \/_/\/_/\/_/\/__/\/_/ \/___/ \/___/ \/___/ \/__/\/___/ \/__/ \/_/ \/__/\/_/ \ \ \/ \/____/ \/_/ | |
\ \_\ \ \_\ | |
\/_/ \/_/ | |
EOF | |
repodir=$(basename $vagrant_repo '.git'); | |
pushd $installdir > /dev/null; | |
info " | |
Successfully bootstrapped aptoma! | |
You can now run vagrant like this. | |
DrFront: | |
cd $repodir/vagrant | |
And then run: | |
vagrant up --provision vagrant.drfront.aptoma.no | |
vagrant ssh vagrant.drfront.aptoma.no | |
DrVideo: | |
vagrant up --provision www.drvideo.no | |
vagrant ssh www.drvideo.no | |
or | |
vagrant up --provision vagrant.meta-admin.drvideo.aptoma.no | |
vagrant ssh vagrant.meta-admin.drvideo.aptoma.no | |
"; | |
say " | |
web access: http://vagrant.drfront.aptoma.no | |
web access: http://vagrant.mobile-conversion.drfront.aptoma.no/mobile/ | |
"; | |
popd > /dev/null; | |
return 0; | |
} | |
function show_welcome_message () { | |
printf "${bldblu}%b" ""; | |
cat <<"EOF" | |
(\.---./) | |
/.-.-.\ | |
/| 0_0 |\ | |
|_`-(v)-'_| | |
\`-._._.-'/ .-. | |
-~-(((.`-\_|_/-'.)))-~' <_ | |
`. .' | |
Hello, I am `._.' the Aptoma | |
bootstrapper!! | |
-----~--~---~~~----~-`.-;~ | |
EOF | |
say " | |
I can be quite rude at times, but please hang in there | |
and I will guide you through the installation process | |
and automaticly install all the things you need. | |
Oh! What a great guy I am! | |
"; | |
} | |
function check_interactive () { | |
if [[ "$-" =~ "i" ]]; then | |
fail "This program must be run interactively"; | |
fi | |
} | |
function check_supported_platform () { | |
if [[ "$(uname)" =~ "Darwin|Linux" ]]; then | |
if [ $(prompt_yes_no \ | |
"This program isn't tested on your platform. "\ | |
"Which means that you are probably are running cygwin on windows. "\ | |
"Yuck!! Continue anayway?") == 'no' ]; then | |
exit 0; | |
fi | |
fi | |
} | |
function bootstrap_vagrant () { | |
deps "aptoma_vagrant" "vagrant_plugins" "ssh" "chef_deploy_keys" || | |
fatal "Could not clone aptoma-vagrant and all the vagrant plugins. The installation will not work"; | |
local answer=''; | |
info "I can only install virtualbox for you, but aptoma-vagrant will also work with vmware fusion or vmware workstation,\n"\ | |
"vmware is proprietary software, and you will have to buy a vagrant plugin license if you want to use it.\n"\ | |
"You also need to install the necessary vm provider plugins for vagrant manually.\n"\ | |
"Read more: https://docs.vagrantup.com/v2/vmware/installation.html"; | |
! is_virtualbox_installed && answer=$(prompt_yes_no "Do you want to install virtualbox instead?"); | |
[[ $answer == "no" ]] && show_done_message && return 0; | |
[[ $answer == "yes" ]] && ! is_virtualbox_installed && install_virtualbox; | |
! is_virtualbox_installed && fatal "Virtualbox couldn't be installed. You have to do it manually, unluck bastard!"; | |
show_done_message; | |
} | |
check_interactive; | |
check_supported_platform; | |
show_welcome_message; | |
bootstrap_vagrant; | |
exit 0; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment