propro 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +3 -0
- data/Gemfile +4 -0
- data/LICENSE +339 -0
- data/README.md +134 -0
- data/Rakefile +9 -0
- data/bin/propro +6 -0
- data/examples/vagrant.propro +41 -0
- data/examples/vps_webserver.propro +51 -0
- data/ext/bash/app/nginx.sh +9 -0
- data/ext/bash/app/node.sh +5 -0
- data/ext/bash/app/pg.sh +5 -0
- data/ext/bash/app/puma/nginx.sh +58 -0
- data/ext/bash/app/puma.sh +64 -0
- data/ext/bash/app/rvm.sh +7 -0
- data/ext/bash/app/sidekiq.sh +69 -0
- data/ext/bash/app.sh +75 -0
- data/ext/bash/db/pg.sh +47 -0
- data/ext/bash/db/redis.sh +20 -0
- data/ext/bash/lib/extras.sh +11 -0
- data/ext/bash/lib/nginx.sh +233 -0
- data/ext/bash/lib/node.sh +28 -0
- data/ext/bash/lib/pg.sh +44 -0
- data/ext/bash/lib/propro.sh +104 -0
- data/ext/bash/lib/redis.sh +59 -0
- data/ext/bash/lib/rvm.sh +21 -0
- data/ext/bash/lib/system.sh +57 -0
- data/ext/bash/lib/ubuntu.sh +175 -0
- data/ext/bash/vagrant/nginx.sh +31 -0
- data/ext/bash/vagrant/node.sh +5 -0
- data/ext/bash/vagrant/pg.sh +12 -0
- data/ext/bash/vagrant/redis.sh +5 -0
- data/ext/bash/vagrant/rvm.sh +6 -0
- data/ext/bash/vagrant/system.sh +26 -0
- data/ext/bash/vagrant.sh +3 -0
- data/ext/bash/vps/system.sh +156 -0
- data/lib/propro/cli/templates/init.tt +21 -0
- data/lib/propro/cli.rb +125 -0
- data/lib/propro/command.rb +17 -0
- data/lib/propro/export.rb +119 -0
- data/lib/propro/option.rb +36 -0
- data/lib/propro/package.rb +68 -0
- data/lib/propro/script.rb +95 -0
- data/lib/propro/source.rb +86 -0
- data/lib/propro/version.rb +3 -0
- data/lib/propro.rb +57 -0
- data/propro.gemspec +27 -0
- data/test/export_spec.rb +88 -0
- data/test/minitest_helper.rb +6 -0
- data/test/option_spec.rb +34 -0
- metadata +167 -0
@@ -0,0 +1,104 @@
|
|
1
|
+
#!/usr/bin/env bash
|
2
|
+
|
3
|
+
set -e
|
4
|
+
set -u
|
5
|
+
|
6
|
+
export PROPRO_LOG_FILE="/root/provision.log"
|
7
|
+
export PROPRO_FULL_LOG_FILE="/root/full_provision.log"
|
8
|
+
export PROPRO_LOG_USE_COLOR="yes"
|
9
|
+
export PROPRO_DISABLE_LOG="no"
|
10
|
+
|
11
|
+
>$PROPRO_FULL_LOG_FILE
|
12
|
+
exec > >(tee $PROPRO_FULL_LOG_FILE)
|
13
|
+
exec 2>&1
|
14
|
+
|
15
|
+
function log {
|
16
|
+
echo -e "$1"
|
17
|
+
|
18
|
+
if is-yes $PROPRO_DISABLE_LOG; then
|
19
|
+
return 0
|
20
|
+
fi
|
21
|
+
|
22
|
+
if [ $PROPRO_LOG_FILE ]; then
|
23
|
+
touch $PROPRO_LOG_FILE
|
24
|
+
echo -e "$1" >> $PROPRO_LOG_FILE
|
25
|
+
fi
|
26
|
+
}
|
27
|
+
|
28
|
+
# $1 text
|
29
|
+
function section {
|
30
|
+
local msg="#### $1"
|
31
|
+
log ""
|
32
|
+
if is-yes $PROPRO_LOG_USE_COLOR; then
|
33
|
+
log "\e[32m\e[1m$msg\e[0m"
|
34
|
+
else
|
35
|
+
log "$msg"
|
36
|
+
fi
|
37
|
+
}
|
38
|
+
|
39
|
+
# $1 text
|
40
|
+
function announce {
|
41
|
+
if is-yes $PROPRO_LOG_USE_COLOR; then
|
42
|
+
log "\e[34m\e[1m--->\e[0m $1"
|
43
|
+
else
|
44
|
+
log "---> $1"
|
45
|
+
fi
|
46
|
+
}
|
47
|
+
|
48
|
+
# $1 text
|
49
|
+
function announce-item {
|
50
|
+
if is-yes $PROPRO_LOG_USE_COLOR; then
|
51
|
+
log " - \e[36m$1\e[0m"
|
52
|
+
else
|
53
|
+
log " - $1"
|
54
|
+
fi
|
55
|
+
}
|
56
|
+
|
57
|
+
function finished {
|
58
|
+
if is-yes $PROPRO_LOG_USE_COLOR; then
|
59
|
+
log "\e[35m\e[1m Fin.\e[0m"
|
60
|
+
else
|
61
|
+
log " Fin."
|
62
|
+
fi
|
63
|
+
log ""
|
64
|
+
}
|
65
|
+
|
66
|
+
function get-tmp-dir {
|
67
|
+
mktemp -d
|
68
|
+
}
|
69
|
+
|
70
|
+
# $1 "yes" or "no"
|
71
|
+
function is-yes {
|
72
|
+
if [ $1 == "yes" ]; then
|
73
|
+
return 0
|
74
|
+
else
|
75
|
+
return 1
|
76
|
+
fi
|
77
|
+
}
|
78
|
+
|
79
|
+
# $1 "yes" or "no"
|
80
|
+
function is-no {
|
81
|
+
if [ $1 == "no" ]; then
|
82
|
+
return 0
|
83
|
+
else
|
84
|
+
return 1
|
85
|
+
fi
|
86
|
+
}
|
87
|
+
|
88
|
+
# $1 comma separated list
|
89
|
+
#
|
90
|
+
# example:
|
91
|
+
# > $ csl-to-wsl "item1,item2,item3"
|
92
|
+
# > item1 item2 item3
|
93
|
+
function csl-to-wsl {
|
94
|
+
echo "$1" | sed 's/,/ /g'
|
95
|
+
}
|
96
|
+
|
97
|
+
# $1 path or relative uri
|
98
|
+
#
|
99
|
+
# example:
|
100
|
+
# > $ path-to-id example.com/neat/stuff
|
101
|
+
# > example_com_neat_stuff
|
102
|
+
function path-to-id {
|
103
|
+
echo "$1" | sed -r 's/[-\.:\/\]/_/g'
|
104
|
+
}
|
@@ -0,0 +1,59 @@
|
|
1
|
+
#!/usr/bin/env bash
|
2
|
+
export REDIS_VERSION="2.8.4" # @specify
|
3
|
+
export REDIS_USER="redis"
|
4
|
+
export REDIS_CONF_FILE="/etc/redis.conf"
|
5
|
+
export REDIS_DATA_DIR="/var/lib/redis"
|
6
|
+
export REDIS_FORCE_64BIT="no" # @specify Force 64bit build even if available memory is lte 4GiB
|
7
|
+
REDIS_URL="http://download.redis.io/releases/redis-$REDIS_VERSION.tar.gz"
|
8
|
+
|
9
|
+
function redis-install {
|
10
|
+
local tmpdir=$(get-tmp-dir)
|
11
|
+
cd "$tmpdir"
|
12
|
+
|
13
|
+
announce "Download $REDIS_VERSION"
|
14
|
+
download $REDIS_URL
|
15
|
+
|
16
|
+
announce "Extract"
|
17
|
+
extract redis-$REDIS_VERSION.tar.gz
|
18
|
+
cd redis-$REDIS_VERSION
|
19
|
+
|
20
|
+
if [ $(get-ram-bytes) -gt 4294967296 ] || is-yes $REDIS_FORCE_64BIT; then
|
21
|
+
announce "Compile"
|
22
|
+
make
|
23
|
+
else
|
24
|
+
announce "Compile (32bit, available memory <= 4GiB)"
|
25
|
+
install-packages libc6-dev-i386
|
26
|
+
make 32bit
|
27
|
+
fi
|
28
|
+
|
29
|
+
announce "Install $REDIS_VERSION"
|
30
|
+
make install
|
31
|
+
|
32
|
+
announce "Add Redis user: $REDIS_USER"
|
33
|
+
useradd -r $REDIS_USER
|
34
|
+
|
35
|
+
announce "Create Redis directories"
|
36
|
+
as-user-mkdir $REDIS_USER $REDIS_DATA_DIR
|
37
|
+
|
38
|
+
announce "Copy Redis config to $REDIS_CONF_FILE"
|
39
|
+
cp ./redis.conf $REDIS_CONF_FILE
|
40
|
+
|
41
|
+
cd ~/
|
42
|
+
rm -rf "$tmpdir"
|
43
|
+
|
44
|
+
announce "Update Redis config"
|
45
|
+
tee -a $REDIS_CONF_FILE <<EOT
|
46
|
+
syslog-enabled yes
|
47
|
+
syslog-ident redis
|
48
|
+
dir $REDIS_DATA_DIR
|
49
|
+
EOT
|
50
|
+
|
51
|
+
announce "Create upstart for Redis"
|
52
|
+
tee /etc/init/redis.conf <<EOT
|
53
|
+
description "Redis"
|
54
|
+
start on runlevel [23]
|
55
|
+
stop on shutdown
|
56
|
+
exec sudo -u $REDIS_USER /usr/local/bin/redis-server $REDIS_CONF_FILE
|
57
|
+
respawn
|
58
|
+
EOT
|
59
|
+
}
|
data/ext/bash/lib/rvm.sh
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
#!/usr/bin/env bash
|
2
|
+
# requires app.sh
|
3
|
+
export RVM_CHANNEL="stable"
|
4
|
+
RVM_REQUIRED_PACKAGES="curl gawk g++ gcc make libc6-dev libreadline6-dev zlib1g-dev libssl-dev libyaml-dev libsqlite3-dev sqlite3 autoconf libgdbm-dev libncurses5-dev automake libtool bison pkg-config libffi-dev"
|
5
|
+
|
6
|
+
# $1 unix user
|
7
|
+
# $2 ruby version
|
8
|
+
function rvm-install-for-user {
|
9
|
+
section "RVM"
|
10
|
+
install-packages $RVM_REQUIRED_PACKAGES
|
11
|
+
|
12
|
+
announce "Install RVM for user $1"
|
13
|
+
su - $1 -c "curl -L https://get.rvm.io | bash -s $RVM_CHANNEL"
|
14
|
+
su - $1 -c "rvm autolibs read-fail"
|
15
|
+
|
16
|
+
announce "Install Ruby $2 for user $1"
|
17
|
+
su - $1 -c "rvm install $2"
|
18
|
+
|
19
|
+
announce "Set Ruby $2 as default for user $1"
|
20
|
+
su - $1 -c "rvm --default use $2"
|
21
|
+
}
|
@@ -0,0 +1,57 @@
|
|
1
|
+
#!/usr/bin/env bash
|
2
|
+
export SYSTEM_SHMALL_PERCENT="0.75" # @specify
|
3
|
+
export SYSTEM_SHMMAX_PERCENT="0.5" # @specify
|
4
|
+
export SYSTEM_BASE_PACKAGES="curl vim-nox less htop build-essential openssl git tree python-software-properties"
|
5
|
+
export SYSTEM_TIMEZONE="Etc/UTC" # @specify
|
6
|
+
export SYSTEM_LOCALE="en_US.UTF-8" # @specify
|
7
|
+
export SYSTEM_SOURCES_PG_KEY_URL="http://apt.postgresql.org/pub/repos/apt/ACCC4CF8.asc"
|
8
|
+
|
9
|
+
function system-configure-shared-memory {
|
10
|
+
announce "Configuring shared memory"
|
11
|
+
install-packages bc
|
12
|
+
|
13
|
+
local shmall=$(get-kernel-shmall $SYSTEM_SHMALL_PERCENT)
|
14
|
+
local shmmax=$(get-kernel-shmmax $SYSTEM_SHMMAX_PERCENT)
|
15
|
+
|
16
|
+
sysctl -w kernel.shmall=$shmall
|
17
|
+
sysctl -w kernel.shmmax=$shmmax
|
18
|
+
tee -a /etc/sysctl.conf <<EOT
|
19
|
+
|
20
|
+
kernel.shmall = $shmall
|
21
|
+
kernel.shmmax = $shmmax
|
22
|
+
EOT
|
23
|
+
}
|
24
|
+
|
25
|
+
function system-install-packages {
|
26
|
+
install-packages $SYSTEM_BASE_PACKAGES
|
27
|
+
}
|
28
|
+
|
29
|
+
function system-configure-timezone {
|
30
|
+
announce "Set timezone to $SYSTEM_TIMEZONE"
|
31
|
+
set-timezone $SYSTEM_TIMEZONE
|
32
|
+
}
|
33
|
+
|
34
|
+
function system-configure-locale {
|
35
|
+
announce "Set locale to $SYSTEM_LOCALE"
|
36
|
+
set-locale $SYSTEM_LOCALE
|
37
|
+
}
|
38
|
+
|
39
|
+
function system-upgrade {
|
40
|
+
announce "Update and upgrade system packages"
|
41
|
+
upgrade-system
|
42
|
+
}
|
43
|
+
|
44
|
+
function system-add-pg-source {
|
45
|
+
announce "Add PostgreSQL sources:"
|
46
|
+
tee /etc/apt/sources.list.d/pgdg.list <<EOT
|
47
|
+
deb http://apt.postgresql.org/pub/repos/apt/ $(release-codename)-pgdg main
|
48
|
+
EOT
|
49
|
+
|
50
|
+
announce-item "apt.postgresql.org"
|
51
|
+
add-source-key $SYSTEM_SOURCES_PG_KEY_URL
|
52
|
+
update-sources
|
53
|
+
}
|
54
|
+
|
55
|
+
function system-install-sources {
|
56
|
+
system-add-pg-source
|
57
|
+
}
|
@@ -0,0 +1,175 @@
|
|
1
|
+
#!/usr/bin/env bash
|
2
|
+
function get-processor-count {
|
3
|
+
nproc
|
4
|
+
}
|
5
|
+
|
6
|
+
function release-codename {
|
7
|
+
lsb_release -c -s
|
8
|
+
}
|
9
|
+
|
10
|
+
# $@ package names
|
11
|
+
function install-packages {
|
12
|
+
announce "Installing packages:"
|
13
|
+
for package in $@; do
|
14
|
+
announce-item "$package"
|
15
|
+
done
|
16
|
+
aptitude -q -y -o Dpkg::Options::="--force-confnew" install $@
|
17
|
+
}
|
18
|
+
|
19
|
+
function get-archtype {
|
20
|
+
if [ $(getconf LONG_BIT) == 32 ]; then
|
21
|
+
echo 'x86'
|
22
|
+
else
|
23
|
+
echo 'x64'
|
24
|
+
fi
|
25
|
+
}
|
26
|
+
|
27
|
+
function update-sources {
|
28
|
+
apt-get -qq -y update
|
29
|
+
}
|
30
|
+
|
31
|
+
function add-repository {
|
32
|
+
add-apt-repository -y $1
|
33
|
+
}
|
34
|
+
|
35
|
+
# $1 unix user
|
36
|
+
# $2 service name
|
37
|
+
# $3 service args
|
38
|
+
function add-sudoers-entries {
|
39
|
+
for event in start status stop reload restart; do
|
40
|
+
if [ $3 ]; then
|
41
|
+
tee -a /etc/sudoers.d/$2.entries <<EOT
|
42
|
+
$1 ALL=NOPASSWD: /sbin/$event $2 $3
|
43
|
+
EOT
|
44
|
+
else
|
45
|
+
tee -a /etc/sudoers.d/$2.entries <<EOT
|
46
|
+
$1 ALL=NOPASSWD: /sbin/$event $2
|
47
|
+
EOT
|
48
|
+
fi
|
49
|
+
done
|
50
|
+
}
|
51
|
+
|
52
|
+
function reboot-system {
|
53
|
+
shutdown -r now
|
54
|
+
}
|
55
|
+
|
56
|
+
# $1 package name
|
57
|
+
function reconfigure-package {
|
58
|
+
dpkg-reconfigure -f noninteractive $1
|
59
|
+
}
|
60
|
+
|
61
|
+
# $1 key URL
|
62
|
+
function add-source-key {
|
63
|
+
wget --quiet -O - $1 | apt-key add -
|
64
|
+
}
|
65
|
+
|
66
|
+
# $@ files to extract
|
67
|
+
function extract {
|
68
|
+
tar xzf $@
|
69
|
+
}
|
70
|
+
|
71
|
+
# $1 URL to download
|
72
|
+
function download {
|
73
|
+
wget -nv $1
|
74
|
+
}
|
75
|
+
|
76
|
+
function get-ram-bytes {
|
77
|
+
free -m -b | awk '/^Mem:/{print $2}'
|
78
|
+
}
|
79
|
+
|
80
|
+
function get-page-size {
|
81
|
+
getconf PAGE_SIZE
|
82
|
+
}
|
83
|
+
|
84
|
+
function get-ram-pages {
|
85
|
+
echo "$(get-ram-bytes) / $(get-page-size)" | bc
|
86
|
+
}
|
87
|
+
|
88
|
+
# $1 shmall percent
|
89
|
+
function get-kernel-shmall {
|
90
|
+
echo "($(get-ram-pages) * $1) / 1" | bc
|
91
|
+
}
|
92
|
+
|
93
|
+
# $1 shmmax percent
|
94
|
+
function get-kernel-shmmax {
|
95
|
+
echo "($(get-ram-bytes) * $1) / 1" | bc
|
96
|
+
}
|
97
|
+
|
98
|
+
# $1 unix user
|
99
|
+
# $2 path
|
100
|
+
function as-user-mkdir {
|
101
|
+
mkdir -p $2
|
102
|
+
chown $1:$1 $2
|
103
|
+
}
|
104
|
+
|
105
|
+
function upgrade-system {
|
106
|
+
update-sources
|
107
|
+
apt-get -qq -y install aptitude
|
108
|
+
aptitude -q -y -o Dpkg::Options::="--force-confnew" full-upgrade
|
109
|
+
}
|
110
|
+
|
111
|
+
# $1 timezone
|
112
|
+
function set-timezone {
|
113
|
+
echo $1 > /etc/timezone
|
114
|
+
reconfigure-package tzdata
|
115
|
+
}
|
116
|
+
|
117
|
+
# $1 locale eg: en_US.UTF-8
|
118
|
+
function set-locale {
|
119
|
+
export LANGUAGE=$1
|
120
|
+
export LANG=$1
|
121
|
+
export LC_ALL=$1
|
122
|
+
locale-gen $1
|
123
|
+
reconfigure-package locales
|
124
|
+
update-locale
|
125
|
+
}
|
126
|
+
|
127
|
+
# $1 hostname
|
128
|
+
function set-hostname {
|
129
|
+
echo $1 > /etc/hostname
|
130
|
+
hostname -F /etc/hostname
|
131
|
+
}
|
132
|
+
|
133
|
+
# $1 unix user
|
134
|
+
# $2 unix group
|
135
|
+
# $3 password
|
136
|
+
function add-user {
|
137
|
+
if [ $2 ]; then
|
138
|
+
announce "Adding $1 user to group $2"
|
139
|
+
useradd -m -s /bin/bash -g $2 $1
|
140
|
+
else
|
141
|
+
announce "Adding $1 user"
|
142
|
+
useradd -m -s /bin/bash $1
|
143
|
+
fi
|
144
|
+
|
145
|
+
if [ $3 ]; then
|
146
|
+
announce "Setting password for $1 user"
|
147
|
+
echo "$1:$3" | chpasswd
|
148
|
+
fi
|
149
|
+
}
|
150
|
+
|
151
|
+
# $1 unix user
|
152
|
+
# $2 github usernames for public keys
|
153
|
+
function add-pubkeys-from-github {
|
154
|
+
announce "Installing public keys for $1 from GitHub users:"
|
155
|
+
|
156
|
+
local ssh_dir="/home/$1/.ssh"
|
157
|
+
local keys_file="$ssh_dir/authorized_keys"
|
158
|
+
|
159
|
+
mkdir -p $ssh_dir
|
160
|
+
touch $keys_file
|
161
|
+
|
162
|
+
for user in $2; do
|
163
|
+
announce-item "$user"
|
164
|
+
local url="https://github.com/$user.keys"
|
165
|
+
tee -a $keys_file <<EOT
|
166
|
+
# $url
|
167
|
+
$(wget -qO- $url)
|
168
|
+
|
169
|
+
EOT
|
170
|
+
done
|
171
|
+
|
172
|
+
chmod 700 $ssh_dir
|
173
|
+
chmod 600 $keys_file
|
174
|
+
chown -R $1 $ssh_dir
|
175
|
+
}
|
@@ -0,0 +1,31 @@
|
|
1
|
+
#!/usr/bin/env bash
|
2
|
+
function provision-vagrant-nginx {
|
3
|
+
section "Nginx"
|
4
|
+
nginx-install
|
5
|
+
nginx-configure
|
6
|
+
nginx-conf-add-gzip
|
7
|
+
nginx-conf-add-mimetypes
|
8
|
+
|
9
|
+
announce "Adding Nginx config for Vagrant"
|
10
|
+
tee "$NGINX_SITES_DIR/vagrant.conf" <<EOT
|
11
|
+
upstream rack_app {
|
12
|
+
server 127.0.0.1:3000 fail_timeout=0;
|
13
|
+
}
|
14
|
+
|
15
|
+
server {
|
16
|
+
root $VAGRANT_DATA_DIR/public;
|
17
|
+
|
18
|
+
access_log /dev/null;
|
19
|
+
error_log /dev/null;
|
20
|
+
|
21
|
+
try_files \$uri/index.html \$uri.html \$uri @upstream_app;
|
22
|
+
|
23
|
+
location @upstream_app {
|
24
|
+
proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
|
25
|
+
proxy_set_header Host \$http_host;
|
26
|
+
proxy_redirect off;
|
27
|
+
proxy_pass http://rack_app;
|
28
|
+
}
|
29
|
+
}
|
30
|
+
EOT
|
31
|
+
}
|
@@ -0,0 +1,12 @@
|
|
1
|
+
#!/usr/bin/env bash
|
2
|
+
function vagrant-pg-create-user {
|
3
|
+
announce "Create database user: $VAGRANT_USER"
|
4
|
+
su - $PG_USER -c "createuser -s $VAGRANT_USER"
|
5
|
+
}
|
6
|
+
|
7
|
+
function provision-vagrant-pg {
|
8
|
+
section "PostgreSQL Server"
|
9
|
+
pg-install-packages
|
10
|
+
pg-tune
|
11
|
+
vagrant-pg-create-user
|
12
|
+
}
|
@@ -0,0 +1,26 @@
|
|
1
|
+
#!/usr/bin/env bash
|
2
|
+
function vagrant-system-install-user-aliases {
|
3
|
+
announce "Installing helper aliases for user: $VAGRANT_USER"
|
4
|
+
tee -a /home/$VAGRANT_USER/.profile <<EOT
|
5
|
+
alias be="bundle exec"
|
6
|
+
alias r="bin/rails"
|
7
|
+
alias v="cd $VAGRANT_DATA_DIR"
|
8
|
+
cd $VAGRANT_DATA_DIR
|
9
|
+
EOT
|
10
|
+
}
|
11
|
+
|
12
|
+
function vagrant-system-purge-grub-menu-config {
|
13
|
+
ucf --purge /boot/grub/menu.lst
|
14
|
+
}
|
15
|
+
|
16
|
+
function provision-vagrant-system {
|
17
|
+
section "Vagrant System"
|
18
|
+
vagrant-system-purge-grub-menu-config
|
19
|
+
system-upgrade
|
20
|
+
system-configure-timezone
|
21
|
+
system-configure-locale
|
22
|
+
system-install-packages
|
23
|
+
system-configure-shared-memory
|
24
|
+
system-install-sources
|
25
|
+
vagrant-system-install-user-aliases
|
26
|
+
}
|
data/ext/bash/vagrant.sh
ADDED
@@ -0,0 +1,156 @@
|
|
1
|
+
#!/usr/bin/env bash
|
2
|
+
export VPS_SYSTEM_HOSTNAME="" # @require
|
3
|
+
export VPS_SYSTEM_FQDN="" # @require
|
4
|
+
export VPS_SYSTEM_ADMIN_AUTHORIZED_GITHUB_USERS="" # @require
|
5
|
+
export VPS_SYSTEM_ADMIN_SUDO_PASSWORD="" # @require
|
6
|
+
export VPS_SYSTEM_PRIVATE_IP="" # @specify
|
7
|
+
export VPS_SYSTEM_ADMIN_USER="admin" # @specify
|
8
|
+
export VPS_SYSTEM_PRIVATE_NETMASK="255.255.128.0"
|
9
|
+
export VPS_SYSTEM_ALLOW_PORTS="www 443 ssh"
|
10
|
+
export VPS_SYSTEM_LIMIT_PORTS="ssh"
|
11
|
+
export VPS_SYSTEM_ALLOW_PRIVATE_IPS="" # @specify
|
12
|
+
export VPS_SYSTEM_ALLOW_PRIVATE_PORTS="5432 6379" # Postgres & Redis
|
13
|
+
export VPS_SYSTEM_GET_PUBLIC_IP_SERVICE_URL="http://ipecho.net/plain"
|
14
|
+
|
15
|
+
function get-vps-system-public-ip {
|
16
|
+
wget -qO- $VPS_SYSTEM_GET_PUBLIC_IP_SERVICE_URL
|
17
|
+
}
|
18
|
+
|
19
|
+
function get-vps-system-default-gateway {
|
20
|
+
ip route | awk '/default/ { print $3 }'
|
21
|
+
}
|
22
|
+
|
23
|
+
function vps-system-configure-hostname {
|
24
|
+
announce "Set hostname to $VPS_SYSTEM_HOSTNAME"
|
25
|
+
set-hostname $VPS_SYSTEM_HOSTNAME
|
26
|
+
}
|
27
|
+
|
28
|
+
function vps-system-configure-sshd {
|
29
|
+
announce "Configure sshd:"
|
30
|
+
announce-item "disable root login"
|
31
|
+
announce-item "disable password auth"
|
32
|
+
tee /etc/ssh/sshd_config <<EOT
|
33
|
+
Port 22
|
34
|
+
Protocol 2
|
35
|
+
HostKey /etc/ssh/ssh_host_rsa_key
|
36
|
+
HostKey /etc/ssh/ssh_host_dsa_key
|
37
|
+
HostKey /etc/ssh/ssh_host_ecdsa_key
|
38
|
+
UsePrivilegeSeparation yes
|
39
|
+
KeyRegenerationInterval 3600
|
40
|
+
ServerKeyBits 768
|
41
|
+
SyslogFacility AUTH
|
42
|
+
LogLevel INFO
|
43
|
+
LoginGraceTime 120
|
44
|
+
PermitRootLogin no
|
45
|
+
StrictModes yes
|
46
|
+
RSAAuthentication yes
|
47
|
+
PubkeyAuthentication yes
|
48
|
+
IgnoreRhosts yes
|
49
|
+
RhostsRSAAuthentication no
|
50
|
+
HostbasedAuthentication no
|
51
|
+
PermitEmptyPasswords no
|
52
|
+
ChallengeResponseAuthentication no
|
53
|
+
PasswordAuthentication no
|
54
|
+
X11Forwarding yes
|
55
|
+
X11DisplayOffset 10
|
56
|
+
PrintMotd no
|
57
|
+
PrintLastLog yes
|
58
|
+
TCPKeepAlive yes
|
59
|
+
AcceptEnv LANG LC_*
|
60
|
+
Subsystem sftp /usr/lib/openssh/sftp-server
|
61
|
+
UsePAM yes
|
62
|
+
EOT
|
63
|
+
|
64
|
+
announce "Restart sshd"
|
65
|
+
service ssh restart
|
66
|
+
}
|
67
|
+
|
68
|
+
function vps-system-configure-firewall {
|
69
|
+
section "Firewall"
|
70
|
+
install-packages ufw
|
71
|
+
|
72
|
+
announce "Configuring firewall:"
|
73
|
+
ufw default deny
|
74
|
+
ufw logging on
|
75
|
+
|
76
|
+
for port in $VPS_SYSTEM_ALLOW_PORTS; do
|
77
|
+
announce-item "allow $port"
|
78
|
+
ufw allow $port
|
79
|
+
done
|
80
|
+
|
81
|
+
for port in $VPS_SYSTEM_LIMIT_PORTS; do
|
82
|
+
announce-item "limit $port"
|
83
|
+
ufw limit $port
|
84
|
+
done
|
85
|
+
|
86
|
+
for local_ip in $VPS_SYSTEM_ALLOW_PRIVATE_IPS; do
|
87
|
+
for port in $VPS_SYSTEM_ALLOW_PRIVATE_PORTS; do
|
88
|
+
announce-item "allow $port from $local_ip"
|
89
|
+
ufw allow $port from $local_ip
|
90
|
+
done
|
91
|
+
done
|
92
|
+
|
93
|
+
echo 'y' | ufw enable
|
94
|
+
}
|
95
|
+
|
96
|
+
function vps-system-configure-admin-user {
|
97
|
+
announce "Adding admin user: $VPS_SYSTEM_ADMIN_USER"
|
98
|
+
add-user $VPS_SYSTEM_ADMIN_USER sudo $VPS_SYSTEM_ADMIN_SUDO_PASSWORD
|
99
|
+
add-pubkeys-from-github $VPS_SYSTEM_ADMIN_USER "$VPS_SYSTEM_ADMIN_AUTHORIZED_GITHUB_USERS"
|
100
|
+
}
|
101
|
+
|
102
|
+
function vps-system-configure-interfaces {
|
103
|
+
announce "Resolving extenal IP address"
|
104
|
+
|
105
|
+
local ip_addr=$(get-vps-system-public-ip)
|
106
|
+
local gateway=$(get-vps-system-default-gateway)
|
107
|
+
local fqdn="$ip_addr $VPS_SYSTEM_HOSTNAME $VPS_SYSTEM_FQDN"
|
108
|
+
|
109
|
+
announce "Setting FQDN: $fqdn"
|
110
|
+
echo "$fqdn" >> /etc/hosts
|
111
|
+
|
112
|
+
announce "Writing /etc/network/interfaces"
|
113
|
+
tee /etc/network/interfaces <<EOT
|
114
|
+
auto lo
|
115
|
+
iface lo inet loopback
|
116
|
+
|
117
|
+
auto eth0 eth0:0 eth0:1
|
118
|
+
|
119
|
+
# Public interface
|
120
|
+
iface eth0 inet static
|
121
|
+
address $ip_addr
|
122
|
+
netmask 255.255.255.0
|
123
|
+
gateway $gateway
|
124
|
+
EOT
|
125
|
+
|
126
|
+
if [ $VPS_SYSTEM_PRIVATE_IP ]; then
|
127
|
+
tee -a /etc/network/interfaces <<EOT
|
128
|
+
|
129
|
+
# Private interface
|
130
|
+
iface eth0:1 inet static
|
131
|
+
address $VPS_SYSTEM_PRIVATE_IP
|
132
|
+
netmask $VPS_SYSTEM_PRIVATE_NETMASK
|
133
|
+
EOT
|
134
|
+
fi
|
135
|
+
|
136
|
+
announce "Restart networking"
|
137
|
+
/etc/init.d/networking restart
|
138
|
+
|
139
|
+
announce "Removing DHCP"
|
140
|
+
aptitude -q -y remove isc-dhcp-client dhcp3-client dhcpcd
|
141
|
+
}
|
142
|
+
|
143
|
+
function provision-vps-system {
|
144
|
+
section "VPS System"
|
145
|
+
system-upgrade
|
146
|
+
system-configure-timezone
|
147
|
+
vps-system-configure-hostname
|
148
|
+
system-configure-locale
|
149
|
+
system-install-packages
|
150
|
+
system-configure-shared-memory
|
151
|
+
system-install-sources
|
152
|
+
vps-system-configure-admin-user
|
153
|
+
vps-system-configure-interfaces
|
154
|
+
vps-system-configure-sshd
|
155
|
+
vps-system-configure-firewall
|
156
|
+
}
|
@@ -0,0 +1,21 @@
|
|
1
|
+
<%= Propro.comment_banner %>
|
2
|
+
#
|
3
|
+
# Example provisioner for <%= @desc %>
|
4
|
+
#
|
5
|
+
|
6
|
+
<%- @paths.each do |path| -%>
|
7
|
+
source :<%= path %>
|
8
|
+
<%- end -%>
|
9
|
+
|
10
|
+
<%- @sources.each do |source| -%>
|
11
|
+
<%- has_no_exports = source.specified_exports.empty? -%>
|
12
|
+
<%- next if has_no_exports && !source.can_provision? -%>
|
13
|
+
# <%= source.name %>
|
14
|
+
<%- source.specified_exports.each do |export| -%>
|
15
|
+
<%= export.to_ruby %>
|
16
|
+
<%- end -%>
|
17
|
+
<%- if source.can_provision? -%>
|
18
|
+
provision "<%= source.provisioner %>"
|
19
|
+
<%- end -%>
|
20
|
+
|
21
|
+
<%- end -%>
|