This repository was archived by the owner on Jun 13, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall-runner-virtualbox.sh
More file actions
executable file
·124 lines (98 loc) · 3.57 KB
/
install-runner-virtualbox.sh
File metadata and controls
executable file
·124 lines (98 loc) · 3.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#! /bin/bash
# Insist stop on error
set -e
# Help message function
print_help () {
echo "install-runner-virtualbox.sh *CI_TOKEN* | --uninstall | --help"
echo ""
echo "*CI_TOKEN* Gitlab runner CI token"
echo ""
echo "Flags:"
echo "-h | --help Print help"
echo "--uninstall Uninstall gitlab-runner and associated virtual machine"
}
# Start without root
if [ $UID -eq 0 ]; then
echo "Script must not be started as root." >&2
exit 1
fi
# Ensure homebrew is installed
if ! command -v brew > /dev/null ; then
echo "Homebrew must be installed." >&2
exit 2
fi
# Ensure CI token was passed
if [ $# -ne 1 ] ; then
echo "Gitlab CI token or '--uninstall' must be passed as an argument." >&2
print_help
exit 2
fi
#### ---- FUNCTIONS ---- ####
install () {
CI_TOKEN=$1
# Retrieve user password for later
echo -n "Please enter your password (make sure to type it right the first time!): "
read -s PASSWORD
echo
# Download tools
brew update
brew install gitlab-runner
echo $PASSWORD | sudo -kS chown root: $(which gitlab-runner)
brew cask fetch virtualbox virtualbox-extension-pack vagrant
# Install tools, messing with sudo so it doesn't ask for password
echo $PASSWORD | sudo -kS echo; brew cask install virtualbox
echo $PASSWORD | sudo -kS echo; brew cask install virtualbox-extension-pack
echo $PASSWORD | sudo -kS echo; brew cask install vagrant
# Setup VM
echo $PASSWORD | sudo -kS -u root -H vagrant up
# Install Xcode helpers
echo $PASSWORD | sudo -kS gem install xcpretty
# Setup gitlab-runner
echo $PASSWORD | sudo -kS cp .vagrant/machines/default/virtualbox/private_key ~root/.gitlab-runner-private-key
echo $PASSWORD | sudo -kS gitlab-runner register --non-interactive -r $CI_TOKEN --tag-list mac,xamarin.ios,xamarin.android,android-26 -u https://incode.ca/ --executor virtualbox --virtualbox-base-name high-sierra-dev --ssh-user vagrant --ssh-identity-file ~root/.gitlab-runner-private-key
echo $PASSWORD | sudo -kS gitlab-runner install -u root -d ~root
echo $PASSWORD | sudo -S sed '/^$/N;/^\n$/i\
<key>EnvironmentVariables</key><dict><key>HOME</key><string>/var/root</string><key>PATH</key><string>/bin:/usr/bin:/usr/local/bin</string></dict>' /Library/LaunchDaemons/gitlab-runner.plist | sudo sh -c "cat > /Library/LaunchDaemons/gitlab-runner.plist"
echo $PASSWORD | sudo -kS gitlab-runner start
# Shutdown VM
echo $PASSWORD | sudo -kS -u root -H vagrant halt
}
uninstall () {
# Safety check
read -r -p "Are you sure? [y/N] " response
case "$response" in
[yY][eE][sS]|[yY])
echo "Starting uninstall..."
;;
*)
echo "Exiting without uninstalling..."
exit 1
;;
esac
# Retrieve user password for later
echo -n "Please enter your password (make sure to type it right the first time!): "
read -s PASSWORD
echo
# Stop gitlab-runner
brew services stop gitlab-runner
echo $PASSWORD | sudo -kS gitlab-runner unregister -u https://incode.ca/ --all-runners
echo $PASSWORD | sudo -kS rm ~root/.gitlab-runner-private-key
# Shutdown VM
echo $PASSWORD | sudo -kS -u root -H vagrant destroy -f
# Uninstall runner
echo $PASSWORD | sudo -kS gitlab-runner stop
echo $PASSWORD | sudo -kS gitlab-runner uninstall
# Output warning
tput setaf 3; echo "INFO: Preserving Vagrant and Virtualbox. To uninstall, run 'brew cask uninstall vagrant virtualbox'"
tput sgr0
}
#### ------ MAIN PROGRAM ------ ####
# Output a help
if [ $1 == "-h" ] || [ $1 == "--help" ]; then
print_help
elif [ $1 == "--uninstall" ]; then
uninstall $@
else
install $@
fi
exit 0