forked from wballard/starphleet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
starphleet-install
executable file
·121 lines (96 loc) · 3.58 KB
/
starphleet-install
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
#!/usr/bin/env starphleet-launcher
### Usage:
### starphleet-install
### --help
###
### This will get starphleet on a base machine
run_as_root_or_die
#flush out caches, I know, I know -- but really if you don't do this
#Linux would rather swap than let go
sync && echo 3 > /proc/sys/vm/drop_caches
ec2_mounts
#put in the system overlay, gets all the files in place
#for the starphleet jobs
rm -f /etc/init/starphleet*
cp -R ${DIR}/../overlay/* /
cp -R ${DIR}/../nginx/* ${STARPHLEET_ROOT:-/var/starphleet}/nginx/
#source again, yep -- now the environment is in place
source ${DIR}/tools
#this is a provisioning script for the base system/host/vm
#run as root, with the starphleet source tree at /starphleet
#role account for folks acting as the admiral, do this really early
#as it will provide the home directory
make_admiral
mkdir -p "${LXC_ROOT}"
chmod 755 "${LXC_ROOT}"
#yep -- international, no fooling
echo "GMT" > /etc/timezone
dpkg-reconfigure -f noninteractive tzdata
hostname "${SHIP}"
echo "${SHIP}" > /etc/hostname
echo "127.0.0.1 ${SHIP} localhost" > /etc/hosts
#packages
debconf-set-selections <<< "postfix postfix/mailname string '${SHIP}'"
debconf-set-selections <<< "postfix postfix/main_mailer_type string 'Internet Site'"
apt-get -y install --force-yes software-properties-common
add-apt-repository -y ppa:chris-lea/node.js
apt-get -y update
# Run Upgrade before before installing packages - which fixes this error
# https://github.com/lxc/lxc/issues/247
export DEBIAN_FRONTEND=noninteractive; apt-get dist-upgrade -y -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" --force-yes
apt-get -y install --force-yes $(< "${DIR}/packages")
pushd ${STARPHLEET_ROOT:-/var/starphleet}/nginx
set -e
make
set +e
popd
#we will be using bash. period
rm /bin/sh
ln /bin/bash /bin/sh
#starphleet lives here
[ -d ${STARPHLEET_ROOT} ] || mkdir -p ${STARPHLEET_ROOT}
[ -d ${STARPHLEET_TMP} ] || mkdir -p ${STARPHLEET_TMP}
chmod 755 ${STARPHLEET_ROOT}
[ -d ${STARPHLEET_ROOT}/diagnostic ] || mkdir -p ${STARPHLEET_ROOT}/diagnostic
chmod 755 ${STARPHLEET_ROOT}/diagnostic
#starphleet and all of its scripts
pushd "${DIR}/.."
# npm is a jerk, and if a file exists that it tries to write it dies
# this should all be removeed ( the npm install )and replaced with overlay
# but since the whole thing is currently busted I want to get it working
# at all first
rm /usr/bin/starphleet-launcher || true
npm ${NPM_FLAGS} install -g
popd
#make a place for keys
test -d ${PRIVATE_KEYS} || mkdir -p ${PRIVATE_KEYS}
chmod 755 ${PRIVATE_KEYS}
test -d ${PUBLIC_KEYS} || mkdir -p ${PUBLIC_KEYS}
chmod 755 ${PUBLIC_KEYS}
#force install private and public keys from local vagrant image
if find /starphleet/private_keys/* > /dev/null ; then
[ -d "${PRIVATE_KEYS}" ] && cp /starphleet/private_keys/* "${PRIVATE_KEYS}"
fi
if find /starphleet/public_keys/* > /dev/null ; then
[ -d "${PUBLIC_KEYS}" ] && cp /starphleet/public_keys/* "${PUBLIC_KEYS}"
fi
#allow passwordless sudoers
cat > ${ROOT}/etc/sudoers <<'EOF'
Defaults env_reset
Defaults mail_badpass
Defaults secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
root ALL=(ALL:ALL) ALL
%admin ALL=(ALL) ALL
%sudo ALL=(ALL:ALL) NOPASSWD:ALL
vagrant ALL=NOPASSWD: ALL
Defaults env_keep="sSH_AUTH_SOCK"
Defaults !requiretty
EOF
starphleet-buildpacks
#making base containers as needed, base container serves as the source for
#and we clone the service container on top, the idea is the base container
#can be re-used and thus improve build time
${DIR}/starphleet-build-base-container
starphleet-cleanup
start starphleet
announce *Welcome to Starphleet*