-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbootstrap.sh
168 lines (156 loc) · 5.11 KB
/
bootstrap.sh
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
#!/usr/bin/env bash
#------------------------------------------------------------------------------
# PURPOSE: Normalize the Debian/Jessie Install and Configuration for the Udemy
# course: 'Docker for DevOps: From Dev to Prod'
#------------------------------------------------------------------------------
# URL: https://goo.gl/I9Y1t9
#------------------------------------------------------------------------------
# EXEC: This script is intended only for Vagrant consumption. Which means:
# 1) It is executed by user: root, and
# 2) Enabled by the Vagrantfile line:
# config.vm.provision :shell, path: "bootstrap.sh"
#------------------------------------------------------------------------------
# AUTHOR: Todd E Thomas
#------------------------------------------------------------------------------
# DATE: 2016/10/23
#------------------------------------------------------------------------------
set -eux
###----------------------------------------------------------------------------
### VARIABLES
###----------------------------------------------------------------------------
#export DEBIAN_FRONTEND=noninteractive
#declare osRelease='/etc/os-release'
#source "$osRelease"
declare vagrantHome='/home/vagrant'
#export backupDir="$vagrantHome/backup"
#declare backPortFile='/etc/apt/sources.list.d/docker.list'
#declare grubConf='/etc/default/grub'
declare osPath='/vagrant'
declare osSources="$osPath/sources"
#
#
####----------------------------------------------------------------------------
#### FUNCTIONS
####----------------------------------------------------------------------------
#
#
####----------------------------------------------------------------------------
#### MAIN
####----------------------------------------------------------------------------
#### Backup stuff
####--
#printf '%s\n' "Creating the ~/backup directory..."
#if [[ ! -d "$backupDir" ]]; then
# mkdir -p "$backupDir"
# chown -R vagrant:vagrant "$backupDir"
#fi
#
#### Setup ~/.bashrc
#printf '\n\n%s\n' "Setting the ~/.bashrc file..."
#cp -pv "$vagrantHome/.bashrc" "$backupDir/bashrc.orig"
#cp -pv /vagrant/sources/bashrc-debian "$vagrantHome/.bashrc"
#chown vagrant:vagrant "$vagrantHome/.bashrc"
#
#### Prep OS for Docker install
#printf '\n\n%s\n' "Configuring Grub..."
#sed -i '/GRUB_CMDLINE_LINUX_DEFAULT/ s/quiet/cgroup_enable=memory swapaccount=1/g' "$grubConf"
#
#### Gen a new grub2 config
#update-grub
#
####---
#### Package Management
####---
#### Configure Backports
#printf '\n\n%s\n' "Creating backports file for $PRETTY_NAME..."
#cat <<EOF > "$backPortFile"
#deb https://apt.dockerproject.org/repo debian-jessie main
#EOF
#
#### Import the keys for the current docker apt repository
#### URL: https://goo.gl/JnNrJC
#apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 \
# --recv-keys 58118E89F3A912897C070ADBF76221572C52609D
#
#### Install packages
#printf '\n\n%s\n' "Updating the OS and installing some stuff..."
#apt-get -y install apt-transport-https
#apt-get update
#apt-cache policy docker-engine
#apt-get -y install docker-engine
#
#### install docker-compose
#printf '\n\n%s\n' "Pulling the latest docker-compose..."
#pip install docker-compose
#
####---
#### finalize system work
####---
#### Add user to docker group
#printf '\n\n%s\n' "Adding user to the docker group..."
#usermod -aG docker vagrant
#
#### Enable and Init Docker
#printf '\n\n%s\n' "Enabling and initializing docker..."
#systemctl enable docker
##service docker start
#systemctl start docker
#systemctl -l status docker
#
#
####---
#### Copy keys for github
####---
#printf '\n\n%s\n' "Prepping ssh stuff..."
## FIX this later
##sed -i 's/.*StrictHostKeyChecking.*/StrictHostKeyChecking no/g' /etc/ssh/ssh_config
#ssh-keyscan github.com >> "$vagrantHome/.ssh/known_hosts"
#chown vagrant:vagrant "$vagrantHome/.ssh/known_hosts"
#
##printf '\n\n%s\n' "Number of keys in known_hosts: "
##wc -l < "$vagrantHome/.ssh/known_hosts"
#
##printf '\n\n%s\n' "Display github remote host keys: "
##cat "$vagrantHome/.ssh/known_hosts"
#
###---
### MOVE TO PACKER SCRIPT: scripts/common/vagrant.sh
### Keys should never exist in the final build intended for public use.
###---
printf '\n\n%s\n' "Pulling in build keys..."
#cp -fv "$osSources"/id_rsa* "$vagrantHome/.ssh"
cp -fv "$osSources"/builder "$vagrantHome/.ssh/id_rsa"
cp -fv "$osSources"/builder.pub "$vagrantHome/.ssh/id_rsa.pub"
chown -R vagrant:vagrant "$vagrantHome/.ssh"
find "$vagrantHome/.ssh" -type f -name 'builder*' -exec chmod 600 {} \;
###---
### Prep for testing
### Grab the code; we're root, become vagrant for a moment. He has the keys...
###---
printf '\n\n%s\n' "Pulling the code in for testing..."
cp "$osSources/git-code.sh" "$vagrantHome/git-code.sh"
###---
### Ensure permissions
###---
chown vagrant:vagrant "$vagrantHome/git-code.sh"
chmod u+x "$vagrantHome/git-code.sh"
###---
### Pull the code (deploy keys)
###---
su -l vagrant -c "$vagrantHome/git-code.sh"
###---
### Cleanup work
###---
rm -f "$vagrantHome/git-code.sh"
exit 0
###---
### Starting the app
###---
cd mobydock/feeder/
type -P docker-compose
if [[ $? -eq 0 ]]; then
docker-compose up
fi
###---
### fin~
###---