ソースを参照

Initial idea for deploying an image

Bob Mottram 9 年 前
コミット
d81e4ee6b0
共有1 個のファイルを変更した160 個の追加0 個の削除を含む
  1. 160
    0
      src/freedombone-deploy

+ 160
- 0
src/freedombone-deploy ファイルの表示

@@ -0,0 +1,160 @@
1
+#!/bin/bash
2
+#
3
+# .---.                  .              .
4
+# |                      |              |
5
+# |--- .--. .-.  .-.  .-.|  .-. .--.--. |.-.  .-. .--.  .-.
6
+# |    |   (.-' (.-' (   | (   )|  |  | |   )(   )|  | (.-'
7
+# '    '     --'  --'  -' -  -' '  '   -' -'   -' '   -  --'
8
+#
9
+#                    Freedom in the Cloud
10
+#
11
+# An initialisation script which can be run after installing
12
+# a disk image
13
+#
14
+# License
15
+# =======
16
+#
17
+# Copyright (C) 2015 Bob Mottram <bob@robotics.uk.to>
18
+#
19
+# This program is free software: you can redistribute it and/or modify
20
+# it under the terms of the GNU General Public License as published by
21
+# the Free Software Foundation, either version 3 of the License, or
22
+# (at your option) any later version.
23
+#
24
+# This program is distributed in the hope that it will be useful,
25
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
26
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27
+# GNU General Public License for more details.
28
+#
29
+# You should have received a copy of the GNU General Public License
30
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
31
+
32
+# Default username for disk images
33
+DEFAULT_IMAGE_USERNAME='freedom'
34
+
35
+MY_NAME='fbn'
36
+MY_USERNAME=$MY_NAME
37
+MY_EMAIL_ADDRESS=$MY_USERNAME@$(hostname)
38
+
39
+# various passwords
40
+CJDNS_PASSWORD=
41
+MARIADB_PASSWORD=
42
+MICROBLOG_ADMIN_PASSWORD=
43
+GIT_ADMIN_PASSWORD=
44
+HUBZILLA_ADMIN_PASSWORD=
45
+OWNCLOUD_ADMIN_PASSWORD=
46
+WIKI_ADMIN_PASSWORD=
47
+FULLBLOG_ADMIN_PASSWORD=
48
+VOIP_SERVER_PASSWORD=
49
+SIP_SERVER_PASSWORD=
50
+
51
+function create_backup_gpg_key {
52
+    echo 'Key-Type: 1' > /home/$MY_USERNAME/gpg-genkey.conf
53
+    echo 'Key-Length: 4096' >> /home/$MY_USERNAME/gpg-genkey.conf
54
+    echo 'Subkey-Type: 1' >> /home/$MY_USERNAME/gpg-genkey.conf
55
+    echo 'Subkey-Length: 4096' >> /home/$MY_USERNAME/gpg-genkey.conf
56
+    echo "Name-Real:  $MY_NAME" >> /home/$MY_USERNAME/gpg-genkey.conf
57
+    echo "Name-Email: $MY_EMAIL_ADDRESS" >> /home/$MY_USERNAME/gpg-genkey.conf
58
+    echo "Name-Comment: backup key" >> /home/$MY_USERNAME/gpg-genkey.conf
59
+    echo 'Expire-Date: 0' >> /home/$MY_USERNAME/gpg-genkey.conf
60
+    chown $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/gpg-genkey.conf
61
+    su -c "gpg --batch --gen-key /home/$MY_USERNAME/gpg-genkey.conf" - $MY_USERNAME
62
+    shred -zu /home/$MY_USERNAME/gpg-genkey.conf
63
+    BACKUP_KEY_EXISTS=$(su -c "gpg --list-keys \"$MY_NAME (backup key)\"" - $MY_USERNAME)
64
+    if [ ! "$?" = "0" ]; then
65
+        echo 'Backup key could not be created'
66
+        exit 43382
67
+    fi
68
+
69
+	MY_BACKUP_KEY_ID=$(su -c "gpg --list-keys \"$MY_NAME (backup key)\" | grep 'pub '" - $MY_USERNAME | awk -F ' ' '{print $2}' | awk -F '/' '{print $2}')
70
+	echo "Backup key: $MY_BACKUP_KEY_ID"
71
+	MY_BACKUP_KEY=/home/$MY_USERNAME/backup_key
72
+	su -c "gpg --output ${MY_BACKUP_KEY}_public.asc --armor --export $MY_BACKUP_KEY_ID" - $MY_USERNAME
73
+	su -c "gpg --output ${MY_BACKUP_KEY}_private.asc --armor --export-secret-key $MY_BACKUP_KEY_ID" - $MY_USERNAME
74
+	if [ ! -f ${MY_BACKUP_KEY}_public.asc ]; then
75
+		echo 'Public backup key could not be exported'
76
+		exit 36829
77
+	fi
78
+	if [ ! -f ${MY_BACKUP_KEY}_private.asc ]; then
79
+		echo 'Private backup key could not be exported'
80
+		exit 29235
81
+	fi
82
+
83
+	# import backup key to root user
84
+	gpg --import --import ${MY_BACKUP_KEY}_public.asc
85
+	gpg --allow-secret-key-import --import ${MY_BACKUP_KEY}_private.asc
86
+
87
+	shred -zu ${MY_BACKUP_KEY}_public.asc
88
+	shred -zu ${MY_BACKUP_KEY}_private.asc
89
+	echo 'New backup gpg key created'
90
+}
91
+
92
+function regenerate_ssh_host_keys {
93
+    rm -f /etc/ssh/ssh_host_*
94
+    dpkg-reconfigure openssh-server
95
+    echo 'ssh host keys regenerated'
96
+    # remove small moduli
97
+    awk '$5 > 2000' /etc/ssh/moduli > ~/moduli
98
+    mv ~/moduli /etc/ssh/moduli
99
+    echo 'ssh small moduli removed'
100
+    systemctl restart ssh
101
+}
102
+
103
+function get_passwords_from_readme {
104
+	readme_file=$1
105
+	if [ ! -f $readme_file ]; then
106
+		return
107
+	fi
108
+
109
+    if grep -q "cjdns password" $readme_file; then
110
+        if [ ! $CJDNS_PASSWORD ]; then
111
+            CJDNS_PASSWORD=$(cat $readme_file | grep "cjdns password" | awk -F ':' '{print $2}' | sed 's/^ *//')
112
+        fi
113
+    fi
114
+    if grep -q "MariaDB password" $readme_file; then
115
+        if [ -f $DATABASE_PASSWORD_FILE ]; then
116
+            MARIADB_PASSWORD=$(cat $DATABASE_PASSWORD_FILE)
117
+        else
118
+            MARIADB_PASSWORD=$(cat $readme_file | grep "MariaDB password" | awk -F ':' '{print $2}' | sed 's/^ *//')
119
+            echo "$MARIADB_PASSWORD" > $DATABASE_PASSWORD_FILE
120
+            chmod 600 $DATABASE_PASSWORD_FILE
121
+        fi
122
+    fi
123
+    if grep -q "MariaDB gnusocial admin password" $readme_file; then
124
+        MICROBLOG_ADMIN_PASSWORD=$(cat $readme_file | grep "MariaDB gnusocial admin password" | awk -F ':' '{print $2}' | sed 's/^ *//')
125
+    fi
126
+    if grep -q "Gogs admin user password" $readme_file; then
127
+        GIT_ADMIN_PASSWORD=$(cat $readme_file | grep "Gogs admin user password" | awk -F ':' '{print $2}' | sed 's/^ *//')
128
+    fi
129
+    if grep -q "MariaDB Hubzilla admin password" $readme_file; then
130
+        HUBZILLA_ADMIN_PASSWORD=$(cat $readme_file | grep "MariaDB Hubzilla admin password" | awk -F ':' '{print $2}' | sed 's/^ *//')
131
+    fi
132
+    if grep -q "Owncloud database password" $readme_file; then
133
+        OWNCLOUD_ADMIN_PASSWORD=$(cat $readme_file | grep "Owncloud database password" | awk -F ':' '{print $2}' | sed 's/^ *//')
134
+    fi
135
+    if grep -q "Wiki password" $readme_file; then
136
+        WIKI_ADMIN_PASSWORD=$(cat $readme_file | grep "Wiki password:" | awk -F ':' '{print $2}' | sed 's/^ *//')
137
+    fi
138
+}
139
+
140
+function set_admin_user {
141
+    sed -i "s|Admin user:.*|Admin user:$MY_USERNAME|g" $COMPLETION_FILE
142
+}
143
+
144
+if [ ! -d /home/$DEFAULT_IMAGE_USERNAME ]; then
145
+	echo "User $DEFAULT_IMAGE_USERNAME not found"
146
+	exit 52372
147
+fi
148
+
149
+if [ -d /home/$MY_USERNAME ]; then
150
+	echo "User $MY_USERNAME already exists"
151
+	exit 73538
152
+fi
153
+
154
+get_passwords_from_readme /home/$DEFAULT_IMAGE_USERNAME/README
155
+#freedombone-adduser $MY_USERNAME > ~/setup.txt
156
+#set_admin_user
157
+#create_backup_gpg_key
158
+#regenerate_ssh_host_keys
159
+
160
+exit 0