Bob Mottram 8 gadus atpakaļ
vecāks
revīzija
a8979e3bb7

+ 23
- 23
src/freedombone-app-batman Parādīt failu

@@ -35,10 +35,10 @@ BATMAN_CELLID='any'
35 35
 
36 36
 function configure_firewall_for_batma {
37 37
     if grep -Fxq "configure_firewall_for_batman" $COMPLETION_FILE; then
38
-	return
38
+		return
39 39
     fi
40 40
     if [[ $ENABLE_BATMAN != "yes" ]]; then
41
-	return
41
+		return
42 42
     fi
43 43
 
44 44
     function_check save_firewall_settings
@@ -72,13 +72,13 @@ function restore_remote_batman {
72 72
 
73 73
 function remove_batman {
74 74
     if ! grep -Fxq "install_batman" $COMPLETION_FILE; then
75
-	return
75
+		return
76 76
     fi
77 77
 
78 78
     ${PROJECT_NAME}-mesh-install -f batman --remove yes
79 79
     if [ ! "$?" = "0" ]; then
80
-	echo $'Failed to remove batman'
81
-	exit 79353
80
+		echo $'Failed to remove batman'
81
+		exit 79353
82 82
     fi
83 83
     sed -i '/install_batman/d' $COMPLETION_FILE
84 84
     sed -i '/configure_firewall_for_batman/d' $COMPLETION_FILE
@@ -90,15 +90,15 @@ function mesh_install_batman {
90 90
     chroot "$rootdir" apt-get -y install wireless-tools rfkill
91 91
 
92 92
     if ! grep -q "batman_adv" $rootdir/etc/modules; then
93
-	echo 'batman_adv' >> $rootdir/etc/modules
93
+		echo 'batman_adv' >> $rootdir/etc/modules
94 94
     fi
95 95
 
96 96
     BATMAN_SCRIPT=$rootdir/var/lib/batman
97 97
 
98 98
     if [ -f /usr/local/bin/${PROJECT_NAME}-mesh-batman ]; then
99
-	cp /usr/local/bin/${PROJECT_NAME}-mesh-batman $BATMAN_SCRIPT
99
+		cp /usr/local/bin/${PROJECT_NAME}-mesh-batman $BATMAN_SCRIPT
100 100
     else
101
-	cp /usr/bin/${PROJECT_NAME}-mesh-batman $BATMAN_SCRIPT
101
+		cp /usr/bin/${PROJECT_NAME}-mesh-batman $BATMAN_SCRIPT
102 102
     fi
103 103
 
104 104
     BATMAN_DAEMON=$rootdir/etc/systemd/system/batman.service
@@ -124,32 +124,32 @@ function mesh_install_batman {
124 124
 
125 125
 function install_batman {
126 126
     if [ $INSTALLING_MESH ]; then
127
-	mesh_install_batman
128
-	return
127
+		mesh_install_batman
128
+		return
129 129
     fi
130 130
     if grep -Fxq "install_batman" $COMPLETION_FILE; then
131
-	return
131
+		return
132 132
     fi
133 133
     if [[ $ENABLE_BATMAN != "yes" ]]; then
134
-	return
134
+		return
135 135
     fi
136 136
 
137 137
     ${PROJECT_NAME}-mesh-install -f batman
138 138
     if [ ! "$?" = "0" ]; then
139
-	echo $'Failed to install batman'
140
-	exit 72524
139
+		echo $'Failed to install batman'
140
+		exit 72524
141 141
     fi
142 142
 
143 143
     if ! grep -q "Mesh Networking (B.A.T.M.A.N)" /home/$MY_USERNAME/README; then
144
-	echo '' >> /home/$MY_USERNAME/README
145
-	echo '' >> /home/$MY_USERNAME/README
146
-	echo 'Mesh Networking (B.A.T.M.A.N)' >> /home/$MY_USERNAME/README
147
-	echo '=============================' >> /home/$MY_USERNAME/README
148
-	echo "Mesh ESSID: $WIFI_SSID" >> /home/$MY_USERNAME/README
149
-	echo "Mesh cell ID: $BATMAN_CELLID" >> /home/$MY_USERNAME/README
150
-	echo "Mesh wifi channel: $WIFI_CHANNEL" >> /home/$MY_USERNAME/README
151
-	chown $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/README
152
-	chmod 600 /home/$MY_USERNAME/README
144
+		echo '' >> /home/$MY_USERNAME/README
145
+		echo '' >> /home/$MY_USERNAME/README
146
+		echo 'Mesh Networking (B.A.T.M.A.N)' >> /home/$MY_USERNAME/README
147
+		echo '=============================' >> /home/$MY_USERNAME/README
148
+		echo "Mesh ESSID: $WIFI_SSID" >> /home/$MY_USERNAME/README
149
+		echo "Mesh cell ID: $BATMAN_CELLID" >> /home/$MY_USERNAME/README
150
+		echo "Mesh wifi channel: $WIFI_CHANNEL" >> /home/$MY_USERNAME/README
151
+		chown $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/README
152
+		chmod 600 /home/$MY_USERNAME/README
153 153
     fi
154 154
 
155 155
     function_check configure_firewall_for_batman

+ 401
- 401
src/freedombone-app-blog Parādīt failu

@@ -39,481 +39,481 @@ MY_BLOG_TITLE="My Blog"
39 39
 MY_BLOG_SUBTITLE="Another ${PROJECT_NAME} Blog"
40 40
 
41 41
 function reconfigure_blog {
42
-    echo -n ''
42
+	echo -n ''
43 43
 }
44 44
 
45 45
 function upgrade_blog {
46
-    if ! grep -Fxq "install_blog" $COMPLETION_FILE; then
47
-	return
48
-    fi
49
-    function_check set_repo_commit
50
-    set_repo_commit /var/www/$FULLBLOG_DOMAIN_NAME/htdocs "Blog commit" "$FULLBLOG_COMMIT" $FULLBLOG_REPO
51
-
52
-    # update blog avatar
53
-    ${PROJECT_NAME}-blog
46
+	if ! grep -Fxq "install_blog" $COMPLETION_FILE; then
47
+		return
48
+	fi
49
+	function_check set_repo_commit
50
+	set_repo_commit /var/www/$FULLBLOG_DOMAIN_NAME/htdocs "Blog commit" "$FULLBLOG_COMMIT" $FULLBLOG_REPO
51
+
52
+	# update blog avatar
53
+	${PROJECT_NAME}-blog
54 54
 }
55 55
 
56 56
 function backup_local_blog {
57
-    FULLBLOG_DOMAIN_NAME='blog'
58
-    if grep -q "Blog domain" $COMPLETION_FILE; then
59
-	FULLBLOG_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "Blog domain" | awk -F ':' '{print $2}')
60
-    fi
57
+	FULLBLOG_DOMAIN_NAME='blog'
58
+	if grep -q "Blog domain" $COMPLETION_FILE; then
59
+		FULLBLOG_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "Blog domain" | awk -F ':' '{print $2}')
60
+	fi
61 61
 
62
-    source_directory=/var/www/${FULLBLOG_DOMAIN_NAME}/htdocs
63
-    if [ -d $source_directory ]; then
64
-	dest_directory=blog
65
-	echo $"Backing up $source_directory to $dest_directory"
62
+	source_directory=/var/www/${FULLBLOG_DOMAIN_NAME}/htdocs
63
+	if [ -d $source_directory ]; then
64
+		dest_directory=blog
65
+		echo $"Backing up $source_directory to $dest_directory"
66 66
 
67
-	function_check suspend_site
68
-	suspend_site ${FULLBLOG_DOMAIN_NAME}
67
+		function_check suspend_site
68
+		suspend_site ${FULLBLOG_DOMAIN_NAME}
69 69
 
70
-	function_check backup_directory_to_usb
71
-	backup_directory_to_usb $source_directory $dest_directory
70
+		function_check backup_directory_to_usb
71
+		backup_directory_to_usb $source_directory $dest_directory
72 72
 
73
-	function_check restart_site
74
-	restart_site
73
+		function_check restart_site
74
+		restart_site
75 75
 
76
-	echo $"Backup to $dest_directory complete"
77
-    fi
76
+		echo $"Backup to $dest_directory complete"
77
+	fi
78 78
 }
79 79
 
80 80
 function restore_local_blog {
81
-    FULLBLOG_DOMAIN_NAME='blog'
82
-    if grep -q "Blog domain" $COMPLETION_FILE; then
83
-	FULLBLOG_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "Blog domain" | awk -F ':' '{print $2}')
84
-    fi
85
-    if [ $FULLBLOG_DOMAIN_NAME ]; then
86
-	echo $"Restoring blog installation"
87
-	temp_restore_dir=/root/tempblog
88
-	restore_directory_from_usb $temp_restore_dir blog
89
-	rm -rf /var/www/${FULLBLOG_DOMAIN_NAME}/htdocs
90
-	cp -r $temp_restore_dir/var/www/${FULLBLOG_DOMAIN_NAME}/htdocs /var/www/${FULLBLOG_DOMAIN_NAME}/
91
-	if [ ! "$?" = "0" ]; then
92
-	    set_user_permissions
93
-	    backup_unmount_drive
94
-	    exit 593
95
-	fi
96
-	rm -rf $temp_restore_dir
97
-	if [ ! -d /var/www/${FULLBLOG_DOMAIN_NAME}/htdocs/content ]; then
98
-	    echo $"No content directory found after restoring blog"
99
-	    set_user_permissions
100
-	    backup_unmount_drive
101
-	    exit 287
81
+	FULLBLOG_DOMAIN_NAME='blog'
82
+	if grep -q "Blog domain" $COMPLETION_FILE; then
83
+		FULLBLOG_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "Blog domain" | awk -F ':' '{print $2}')
102 84
 	fi
103
-	chown -R www-data:www-data /var/www/${FULLBLOG_DOMAIN_NAME}/htdocs
104
-	# Ensure that the bundled SSL cert is being used
105
-	if [ -f /etc/ssl/certs/${FULLBLOG_DOMAIN_NAME}.bundle.crt ]; then
106
-	    sed -i "s|${FULLBLOG_DOMAIN_NAME}.crt|${FULLBLOG_DOMAIN_NAME}.bundle.crt|g" /etc/nginx/sites-available/${FULLBLOG_DOMAIN_NAME}
107
-	fi
108
-	for d in /home/*/ ; do
109
-	    USERNAME=$(echo "$d" | awk -F '/' '{print $3}')
110
-	    if [[ $USERNAME != "git" && $USERNAME != "mirrors" && $USERNAME != "sync" ]]; then
111
-		if [ -d /var/www/${FULLBLOG_DOMAIN_NAME}/htdocs/content/$USERNAME/blog/uncategorized/post ]; then
112
-		    mv /var/www/${FULLBLOG_DOMAIN_NAME}/htdocs/content/$USERNAME/blog/*.md /var/www/${FULLBLOG_DOMAIN_NAME}/htdocs/content/$USERNAME/blog/uncategorized/post
85
+	if [ $FULLBLOG_DOMAIN_NAME ]; then
86
+		echo $"Restoring blog installation"
87
+		temp_restore_dir=/root/tempblog
88
+		restore_directory_from_usb $temp_restore_dir blog
89
+		rm -rf /var/www/${FULLBLOG_DOMAIN_NAME}/htdocs
90
+		cp -r $temp_restore_dir/var/www/${FULLBLOG_DOMAIN_NAME}/htdocs /var/www/${FULLBLOG_DOMAIN_NAME}/
91
+		if [ ! "$?" = "0" ]; then
92
+			set_user_permissions
93
+			backup_unmount_drive
94
+			exit 593
95
+		fi
96
+		rm -rf $temp_restore_dir
97
+		if [ ! -d /var/www/${FULLBLOG_DOMAIN_NAME}/htdocs/content ]; then
98
+			echo $"No content directory found after restoring blog"
99
+			set_user_permissions
100
+			backup_unmount_drive
101
+			exit 287
102
+		fi
103
+		chown -R www-data:www-data /var/www/${FULLBLOG_DOMAIN_NAME}/htdocs
104
+		# Ensure that the bundled SSL cert is being used
105
+		if [ -f /etc/ssl/certs/${FULLBLOG_DOMAIN_NAME}.bundle.crt ]; then
106
+			sed -i "s|${FULLBLOG_DOMAIN_NAME}.crt|${FULLBLOG_DOMAIN_NAME}.bundle.crt|g" /etc/nginx/sites-available/${FULLBLOG_DOMAIN_NAME}
107
+		fi
108
+		for d in /home/*/ ; do
109
+			USERNAME=$(echo "$d" | awk -F '/' '{print $3}')
110
+			if [[ $USERNAME != "git" && $USERNAME != "mirrors" && $USERNAME != "sync" ]]; then
111
+				if [ -d /var/www/${FULLBLOG_DOMAIN_NAME}/htdocs/content/$USERNAME/blog/uncategorized/post ]; then
112
+					mv /var/www/${FULLBLOG_DOMAIN_NAME}/htdocs/content/$USERNAME/blog/*.md /var/www/${FULLBLOG_DOMAIN_NAME}/htdocs/content/$USERNAME/blog/uncategorized/post
113
+				fi
114
+			fi
115
+		done
116
+		if [ -d /etc/letsencrypt/live/${FULLBLOG_DOMAIN_NAME} ]; then
117
+			ln -s /etc/letsencrypt/live/${FULLBLOG_DOMAIN_NAME}/privkey.pem /etc/ssl/private/${FULLBLOG_DOMAIN_NAME}.key
118
+			ln -s /etc/letsencrypt/live/${FULLBLOG_DOMAIN_NAME}/fullchain.pem /etc/ssl/certs/${FULLBLOG_DOMAIN_NAME}.pem
113 119
 		fi
114
-	    fi
115
-	done
116
-	if [ -d /etc/letsencrypt/live/${FULLBLOG_DOMAIN_NAME} ]; then
117
-	    ln -s /etc/letsencrypt/live/${FULLBLOG_DOMAIN_NAME}/privkey.pem /etc/ssl/private/${FULLBLOG_DOMAIN_NAME}.key
118
-	    ln -s /etc/letsencrypt/live/${FULLBLOG_DOMAIN_NAME}/fullchain.pem /etc/ssl/certs/${FULLBLOG_DOMAIN_NAME}.pem
119 120
 	fi
120
-    fi
121 121
 }
122 122
 
123 123
 function backup_remote_blog {
124
-    if grep -q "Blog domain" $COMPLETION_FILE; then
125
-	FULLBLOG_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "Blog domain" | awk -F ':' '{print $2}')
126
-	temp_backup_dir=/var/www/${FULLBLOG_DOMAIN_NAME}/htdocs
127
-	if [ -d $temp_backup_dir ]; then
128
-	    echo $"Backing up blog"
129
-	    backup_directory_to_friend $temp_backup_dir blog
130
-	    echo $"Backup of blog complete"
131
-	else
132
-	    echo $"Blog domain specified but not found in $temp_backup_dir"
133
-	    exit 2578
124
+	if grep -q "Blog domain" $COMPLETION_FILE; then
125
+		FULLBLOG_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "Blog domain" | awk -F ':' '{print $2}')
126
+		temp_backup_dir=/var/www/${FULLBLOG_DOMAIN_NAME}/htdocs
127
+		if [ -d $temp_backup_dir ]; then
128
+			echo $"Backing up blog"
129
+			backup_directory_to_friend $temp_backup_dir blog
130
+			echo $"Backup of blog complete"
131
+		else
132
+			echo $"Blog domain specified but not found in $temp_backup_dir"
133
+			exit 2578
134
+		fi
134 135
 	fi
135
-    fi
136 136
 }
137 137
 
138 138
 function restore_remote_blog {
139
-    if [ -d $SERVER_DIRECTORY/backup/blog ]; then
140
-	FULLBLOG_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "Blog domain" | awk -F ':' '{print $2}')
141
-	echo $"Restoring blog installation $FULLBLOG_DOMAIN_NAME"
142
-	temp_restore_dir=/root/tempblog
143
-	mkdir $temp_restore_dir
144
-	function_check restore_directory_from_friend
145
-	restore_directory_from_friend $temp_restore_dir blog
146
-	rm -rf /var/www/${FULLBLOG_DOMAIN_NAME}/htdocs
147
-	cp -r $temp_restore_dir/var/www/${FULLBLOG_DOMAIN_NAME}/htdocs /var/www/${FULLBLOG_DOMAIN_NAME}/
148
-	if [ ! "$?" = "0" ]; then
149
-	    exit 593
150
-	fi
151
-	rm -rf $temp_restore_dir
152
-	if [ ! -d /var/www/${FULLBLOG_DOMAIN_NAME}/htdocs/content ]; then
153
-	    echo $"No content directory found after restoring blog"
154
-	    exit 287
155
-	fi
156
-	# Ensure that the bundled SSL cert is being used
157
-	if [ -f /etc/ssl/certs/${FULLBLOG_DOMAIN_NAME}.bundle.crt ]; then
158
-	    sed -i "s|${FULLBLOG_DOMAIN_NAME}.crt|${FULLBLOG_DOMAIN_NAME}.bundle.crt|g" /etc/nginx/sites-available/${FULLBLOG_DOMAIN_NAME}
159
-	fi
160
-	for d in /home/*/ ; do
161
-	    USERNAME=$(echo "$d" | awk -F '/' '{print $3}')
162
-	    if [[ $USERNAME != "git" && $USERNAME != "mirrors" && $USERNAME != "sync" ]]; then
163
-		if [ -d /var/www/${FULLBLOG_DOMAIN_NAME}/htdocs/content/$USERNAME/blog/uncategorized/post ]; then
164
-		    mv /var/www/${FULLBLOG_DOMAIN_NAME}/htdocs/content/$USERNAME/blog/*.md /var/www/${FULLBLOG_DOMAIN_NAME}/htdocs/content/$USERNAME/blog/uncategorized/post
139
+	if [ -d $SERVER_DIRECTORY/backup/blog ]; then
140
+		FULLBLOG_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "Blog domain" | awk -F ':' '{print $2}')
141
+		echo $"Restoring blog installation $FULLBLOG_DOMAIN_NAME"
142
+		temp_restore_dir=/root/tempblog
143
+		mkdir $temp_restore_dir
144
+		function_check restore_directory_from_friend
145
+		restore_directory_from_friend $temp_restore_dir blog
146
+		rm -rf /var/www/${FULLBLOG_DOMAIN_NAME}/htdocs
147
+		cp -r $temp_restore_dir/var/www/${FULLBLOG_DOMAIN_NAME}/htdocs /var/www/${FULLBLOG_DOMAIN_NAME}/
148
+		if [ ! "$?" = "0" ]; then
149
+			exit 593
150
+		fi
151
+		rm -rf $temp_restore_dir
152
+		if [ ! -d /var/www/${FULLBLOG_DOMAIN_NAME}/htdocs/content ]; then
153
+			echo $"No content directory found after restoring blog"
154
+			exit 287
165 155
 		fi
166
-	    fi
167
-	done
168
-	if [ -d /etc/letsencrypt/live/${FULLBLOG_DOMAIN_NAME} ]; then
169
-	    ln -s /etc/letsencrypt/live/${FULLBLOG_DOMAIN_NAME}/privkey.pem /etc/ssl/private/${FULLBLOG_DOMAIN_NAME}.key
170
-	    ln -s /etc/letsencrypt/live/${FULLBLOG_DOMAIN_NAME}/fullchain.pem /etc/ssl/certs/${FULLBLOG_DOMAIN_NAME}.pem
156
+		# Ensure that the bundled SSL cert is being used
157
+		if [ -f /etc/ssl/certs/${FULLBLOG_DOMAIN_NAME}.bundle.crt ]; then
158
+			sed -i "s|${FULLBLOG_DOMAIN_NAME}.crt|${FULLBLOG_DOMAIN_NAME}.bundle.crt|g" /etc/nginx/sites-available/${FULLBLOG_DOMAIN_NAME}
159
+		fi
160
+		for d in /home/*/ ; do
161
+			USERNAME=$(echo "$d" | awk -F '/' '{print $3}')
162
+			if [[ $USERNAME != "git" && $USERNAME != "mirrors" && $USERNAME != "sync" ]]; then
163
+				if [ -d /var/www/${FULLBLOG_DOMAIN_NAME}/htdocs/content/$USERNAME/blog/uncategorized/post ]; then
164
+					mv /var/www/${FULLBLOG_DOMAIN_NAME}/htdocs/content/$USERNAME/blog/*.md /var/www/${FULLBLOG_DOMAIN_NAME}/htdocs/content/$USERNAME/blog/uncategorized/post
165
+				fi
166
+			fi
167
+		done
168
+		if [ -d /etc/letsencrypt/live/${FULLBLOG_DOMAIN_NAME} ]; then
169
+			ln -s /etc/letsencrypt/live/${FULLBLOG_DOMAIN_NAME}/privkey.pem /etc/ssl/private/${FULLBLOG_DOMAIN_NAME}.key
170
+			ln -s /etc/letsencrypt/live/${FULLBLOG_DOMAIN_NAME}/fullchain.pem /etc/ssl/certs/${FULLBLOG_DOMAIN_NAME}.pem
171
+		fi
172
+		echo $"Restore of blog complete"
171 173
 	fi
172
-	echo $"Restore of blog complete"
173
-    fi
174 174
 }
175 175
 
176 176
 function remove_blog {
177
-    if ! grep -Fxq "install_blog" $COMPLETION_FILE; then
178
-	return
179
-    fi
180
-    if [ ! -d /var/www/$FULLBLOG_DOMAIN_NAME ]; then
181
-	rm -rf /var/www/$FULLBLOG_DOMAIN_NAME
182
-    fi
183
-    nginx_dissite $FULLBLOG_DOMAIN_NAME
184
-    if [ ! -f /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME ]; then
185
-	rm -rf /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
186
-    fi
187
-    if [ $FULLBLOG_CODE ]; then
188
-	if [ -f /usr/bin/dynamicdns ]; then
189
-	    sed -i "/$FULLBLOG_DOMAIN_NAME/d" /usr/bin/dynamicdns
190
-	    sed -i "/$FULLBLOG_CODE/d" /usr/bin/dynamicdns
177
+	if ! grep -Fxq "install_blog" $COMPLETION_FILE; then
178
+		return
179
+	fi
180
+	if [ ! -d /var/www/$FULLBLOG_DOMAIN_NAME ]; then
181
+		rm -rf /var/www/$FULLBLOG_DOMAIN_NAME
191 182
 	fi
192
-    fi
193
-    function_check remove_onion_service
194
-    remove_onion_service blog ${FULLBLOG_ONION_PORT}
195
-    sed -i '/install_blog/d' $COMPLETION_FILE
196
-    sed -i '/Blog .*/d' $COMPLETION_FILE
183
+	nginx_dissite $FULLBLOG_DOMAIN_NAME
184
+	if [ ! -f /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME ]; then
185
+		rm -rf /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
186
+	fi
187
+	if [ $FULLBLOG_CODE ]; then
188
+		if [ -f /usr/bin/dynamicdns ]; then
189
+			sed -i "/$FULLBLOG_DOMAIN_NAME/d" /usr/bin/dynamicdns
190
+			sed -i "/$FULLBLOG_CODE/d" /usr/bin/dynamicdns
191
+		fi
192
+	fi
193
+	function_check remove_onion_service
194
+	remove_onion_service blog ${FULLBLOG_ONION_PORT}
195
+	sed -i '/install_blog/d' $COMPLETION_FILE
196
+	sed -i '/Blog .*/d' $COMPLETION_FILE
197 197
 }
198 198
 
199 199
 function get_blog_admin_password {
200
-    if [ -f /home/$MY_USERNAME/README ]; then
201
-	if grep -q "Your blog password is" /home/$MY_USERNAME/README; then
202
-	    FULLBLOG_ADMIN_PASSWORD=$(cat /home/$MY_USERNAME/README | grep "Your blog password is" | awk -F ':' '{print $2}' | sed 's/^ *//')
200
+	if [ -f /home/$MY_USERNAME/README ]; then
201
+		if grep -q "Your blog password is" /home/$MY_USERNAME/README; then
202
+			FULLBLOG_ADMIN_PASSWORD=$(cat /home/$MY_USERNAME/README | grep "Your blog password is" | awk -F ':' '{print $2}' | sed 's/^ *//')
203
+		fi
203 204
 	fi
204
-    fi
205 205
 }
206 206
 
207 207
 function install_blog_social_networks {
208
-    # set social networks
209
-    if grep -q "social.hubzilla" /var/www/$FULLBLOG_DOMAIN_NAME/htdocs/config/config.ini; then
210
-	sed -i "s|;social.hubzilla|social.hubzilla|g" /var/www/$FULLBLOG_DOMAIN_NAME/htdocs/config/config.ini
211
-	sed -i "s|social.hubzilla.*|social.hubzilla = \"$HUBZILLA_DOMAIN_NAME\"|g" /var/www/$FULLBLOG_DOMAIN_NAME/htdocs/config/config.ini
212
-    fi
213
-    if grep -q "social.gnusocial" /var/www/$FULLBLOG_DOMAIN_NAME/htdocs/config/config.ini; then
214
-	sed -i "s|;social.gnusocial|social.gnusocial|g" /var/www/$FULLBLOG_DOMAIN_NAME/htdocs/config/config.ini
215
-	sed -i "s|social.gnusocial.*|social.gnusocial = \"$MICROBLOG_DOMAIN_NAME\"|g" /var/www/$FULLBLOG_DOMAIN_NAME/htdocs/config/config.ini
216
-    fi
217
-
218
-    # clear proprietary social network strings
219
-    sed -i 's|social.facebook.*|social.facebook = ""|g' /var/www/$FULLBLOG_DOMAIN_NAME/htdocs/config/config.ini
220
-    sed -i 's|social.twitter.*|social.twitter = ""|g' /var/www/$FULLBLOG_DOMAIN_NAME/htdocs/config/config.ini
221
-    sed -i 's|social.google.*|social.google = ""|g' /var/www/$FULLBLOG_DOMAIN_NAME/htdocs/config/config.ini
208
+	# set social networks
209
+	if grep -q "social.hubzilla" /var/www/$FULLBLOG_DOMAIN_NAME/htdocs/config/config.ini; then
210
+		sed -i "s|;social.hubzilla|social.hubzilla|g" /var/www/$FULLBLOG_DOMAIN_NAME/htdocs/config/config.ini
211
+		sed -i "s|social.hubzilla.*|social.hubzilla = \"$HUBZILLA_DOMAIN_NAME\"|g" /var/www/$FULLBLOG_DOMAIN_NAME/htdocs/config/config.ini
212
+	fi
213
+	if grep -q "social.gnusocial" /var/www/$FULLBLOG_DOMAIN_NAME/htdocs/config/config.ini; then
214
+		sed -i "s|;social.gnusocial|social.gnusocial|g" /var/www/$FULLBLOG_DOMAIN_NAME/htdocs/config/config.ini
215
+		sed -i "s|social.gnusocial.*|social.gnusocial = \"$MICROBLOG_DOMAIN_NAME\"|g" /var/www/$FULLBLOG_DOMAIN_NAME/htdocs/config/config.ini
216
+	fi
217
+
218
+	# clear proprietary social network strings
219
+	sed -i 's|social.facebook.*|social.facebook = ""|g' /var/www/$FULLBLOG_DOMAIN_NAME/htdocs/config/config.ini
220
+	sed -i 's|social.twitter.*|social.twitter = ""|g' /var/www/$FULLBLOG_DOMAIN_NAME/htdocs/config/config.ini
221
+	sed -i 's|social.google.*|social.google = ""|g' /var/www/$FULLBLOG_DOMAIN_NAME/htdocs/config/config.ini
222 222
 }
223 223
 
224 224
 function install_blog_user {
225
-    # create a user password
226
-    function_check get_blog_admin_password
227
-    get_blog_admin_password
228
-    if [ ! $FULLBLOG_ADMIN_PASSWORD ]; then
229
-	if [ -f $IMAGE_PASSWORD_FILE ]; then
230
-	    FULLBLOG_ADMIN_PASSWORD="$(printf `cat $IMAGE_PASSWORD_FILE`)"
231
-	else
232
-	    FULLBLOG_ADMIN_PASSWORD="$(create_password ${MINIMUM_PASSWORD_LENGTH})"
225
+	# create a user password
226
+	function_check get_blog_admin_password
227
+	get_blog_admin_password
228
+	if [ ! $FULLBLOG_ADMIN_PASSWORD ]; then
229
+		if [ -f $IMAGE_PASSWORD_FILE ]; then
230
+			FULLBLOG_ADMIN_PASSWORD="$(printf `cat $IMAGE_PASSWORD_FILE`)"
231
+		else
232
+			FULLBLOG_ADMIN_PASSWORD="$(create_password ${MINIMUM_PASSWORD_LENGTH})"
233
+		fi
234
+		echo '' >> /home/$MY_USERNAME/README
235
+		echo '' >> /home/$MY_USERNAME/README
236
+		echo $'HTMLy Blog' >> /home/$MY_USERNAME/README
237
+		echo '==========' >> /home/$MY_USERNAME/README
238
+		echo $"Your blog username: $MY_USERNAME" >> /home/$MY_USERNAME/README
239
+		echo $"Your blog password is: $FULLBLOG_ADMIN_PASSWORD" >> /home/$MY_USERNAME/README
240
+		if [[ $ONION_ONLY == 'no' ]]; then
241
+			echo $"Log into your blog at https://$FULLBLOG_DOMAIN_NAME/login" >> /home/$MY_USERNAME/README
242
+		fi
243
+		chown $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/README
244
+		chmod 600 /home/$MY_USERNAME/README
233 245
 	fi
234
-	echo '' >> /home/$MY_USERNAME/README
235
-	echo '' >> /home/$MY_USERNAME/README
236
-	echo $'HTMLy Blog' >> /home/$MY_USERNAME/README
237
-	echo '==========' >> /home/$MY_USERNAME/README
238
-	echo $"Your blog username: $MY_USERNAME" >> /home/$MY_USERNAME/README
239
-	echo $"Your blog password is: $FULLBLOG_ADMIN_PASSWORD" >> /home/$MY_USERNAME/README
240
-	if [[ $ONION_ONLY == 'no' ]]; then
241
-	    echo $"Log into your blog at https://$FULLBLOG_DOMAIN_NAME/login" >> /home/$MY_USERNAME/README
246
+
247
+	# create a user
248
+	FULLBLOG_ADMIN_PASSWORD_HASH=$(${PROJECT_NAME}-sec --bloghash "$FULLBLOG_ADMIN_PASSWORD")
249
+	if [ ${#FULLBLOG_ADMIN_PASSWORD_HASH} -lt 8 ]; then
250
+		echo $'Blog admin password could not be hashed'
251
+		exit 625728
242 252
 	fi
243
-	chown $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/README
244
-	chmod 600 /home/$MY_USERNAME/README
245
-    fi
246
-
247
-    # create a user
248
-    FULLBLOG_ADMIN_PASSWORD_HASH=$(${PROJECT_NAME}-sec --bloghash "$FULLBLOG_ADMIN_PASSWORD")
249
-    if [ ${#FULLBLOG_ADMIN_PASSWORD_HASH} -lt 8 ]; then
250
-	echo $'Blog admin password could not be hashed'
251
-	exit 625728
252
-    fi
253
-    echo ';Password' > /var/www/$FULLBLOG_DOMAIN_NAME/htdocs/config/users/$MY_USERNAME.ini
254
-    echo "password = $FULLBLOG_ADMIN_PASSWORD_HASH" >> /var/www/$FULLBLOG_DOMAIN_NAME/htdocs/config/users/$MY_USERNAME.ini
255
-    echo 'encryption = password_hash' >> /var/www/$FULLBLOG_DOMAIN_NAME/htdocs/config/users/$MY_USERNAME.ini
256
-    echo ';Role' >> /var/www/$FULLBLOG_DOMAIN_NAME/htdocs/config/users/$MY_USERNAME.ini
257
-    echo 'role = admin' >> /var/www/$FULLBLOG_DOMAIN_NAME/htdocs/config/users/$MY_USERNAME.ini
253
+	echo ';Password' > /var/www/$FULLBLOG_DOMAIN_NAME/htdocs/config/users/$MY_USERNAME.ini
254
+	echo "password = $FULLBLOG_ADMIN_PASSWORD_HASH" >> /var/www/$FULLBLOG_DOMAIN_NAME/htdocs/config/users/$MY_USERNAME.ini
255
+	echo 'encryption = password_hash' >> /var/www/$FULLBLOG_DOMAIN_NAME/htdocs/config/users/$MY_USERNAME.ini
256
+	echo ';Role' >> /var/www/$FULLBLOG_DOMAIN_NAME/htdocs/config/users/$MY_USERNAME.ini
257
+	echo 'role = admin' >> /var/www/$FULLBLOG_DOMAIN_NAME/htdocs/config/users/$MY_USERNAME.ini
258 258
 }
259 259
 
260 260
 function install_blog_settings {
261
-    cp /var/www/$FULLBLOG_DOMAIN_NAME/htdocs/config/config.ini.example /var/www/$FULLBLOG_DOMAIN_NAME/htdocs/config/config.ini
262
-    sed -i "s|site.url.*|site.url = '/'|g" /var/www/$FULLBLOG_DOMAIN_NAME/htdocs/config/config.ini
263
-    sed -i "s|blog.title.*|blog.title = '$MY_BLOG_TITLE'|g" /var/www/$FULLBLOG_DOMAIN_NAME/htdocs/config/config.ini
264
-    sed -i "s|blog.tagline.*|blog.tagline = '$MY_BLOG_SUBTITLE'|g" /var/www/$FULLBLOG_DOMAIN_NAME/htdocs/config/config.ini
265
-    sed -i 's|timezone.*|timezone = "Europe/London"|g' /var/www/$FULLBLOG_DOMAIN_NAME/htdocs/config/config.ini
266
-    sed -i "s|Your name|$MY_NAME|g" /var/www/$FULLBLOG_DOMAIN_NAME/htdocs/config/config.ini
261
+	cp /var/www/$FULLBLOG_DOMAIN_NAME/htdocs/config/config.ini.example /var/www/$FULLBLOG_DOMAIN_NAME/htdocs/config/config.ini
262
+	sed -i "s|site.url.*|site.url = '/'|g" /var/www/$FULLBLOG_DOMAIN_NAME/htdocs/config/config.ini
263
+	sed -i "s|blog.title.*|blog.title = '$MY_BLOG_TITLE'|g" /var/www/$FULLBLOG_DOMAIN_NAME/htdocs/config/config.ini
264
+	sed -i "s|blog.tagline.*|blog.tagline = '$MY_BLOG_SUBTITLE'|g" /var/www/$FULLBLOG_DOMAIN_NAME/htdocs/config/config.ini
265
+	sed -i 's|timezone.*|timezone = "Europe/London"|g' /var/www/$FULLBLOG_DOMAIN_NAME/htdocs/config/config.ini
266
+	sed -i "s|Your name|$MY_NAME|g" /var/www/$FULLBLOG_DOMAIN_NAME/htdocs/config/config.ini
267 267
 }
268 268
 
269 269
 function install_blog_website {
270
-    function_check nginx_http_redirect
271
-    nginx_http_redirect $FULLBLOG_DOMAIN_NAME
272
-    echo 'server {' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
273
-    echo '    listen 443 ssl;' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
274
-    echo "    root /var/www/$FULLBLOG_DOMAIN_NAME/htdocs;" >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
275
-    echo "    server_name $FULLBLOG_DOMAIN_NAME;" >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
276
-    echo '    access_log off;' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
277
-    echo "    error_log /var/log/nginx/${FULLBLOG_DOMAIN_NAME}_error_ssl.log $WEBSERVER_LOG_LEVEL;" >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
278
-    echo '    index index.php;' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
279
-    echo '    charset utf-8;' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
280
-    echo '    proxy_read_timeout 86400s;' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
281
-    function_check nginx_limits
282
-    nginx_limits $FULLBLOG_DOMAIN_NAME
283
-    function_check nginx_ssl
284
-    nginx_ssl $FULLBLOG_DOMAIN_NAME
285
-    function_check nginx_disable_sniffing
286
-    nginx_disable_sniffing $FULLBLOG_DOMAIN_NAME
287
-    echo '    add_header Strict-Transport-Security "max-age=0;";' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
288
-    echo '' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
289
-    echo '    # rewrite to front controller as default rule' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
290
-    echo '    location / {' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
291
-    echo '        rewrite ^/(.*) /index.php?q=$uri&$args last;' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
292
-    echo '    }' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
293
-    echo '' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
294
-    echo "    # make sure webfinger and other well known services aren't blocked" >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
295
-    echo '    # by denying dot files and rewrite request to the front controller' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
296
-    echo '    location ^~ /.well-known/ {' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
297
-    echo '        allow all;' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
298
-    echo '    }' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
299
-    echo '' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
300
-    echo '    # statically serve these file types when possible' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
301
-    echo '    # otherwise fall back to front controller' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
302
-    echo '    # allow browser to cache them' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
303
-    echo '    # added .htm for advanced source code editor library' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
304
-    echo '    location ~* \.(jpg|jpeg|gif|png|ico|css|js|htm|html|ttf|woff|svg)$ {' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
305
-    echo '        expires 30d;' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
306
-    echo '        try_files $uri /index.php?q=$uri&$args;' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
307
-    echo '    }' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
308
-    echo '' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
309
-    echo '    # block these file types' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
310
-    echo '    location ~* \.(tpl|md|tgz|log|out)$ {' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
311
-    echo '        deny all;' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
312
-    echo '    }' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
313
-    echo '' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
314
-    echo '    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
315
-    echo '    # or a unix socket' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
316
-    echo '    location ~* \.php$ {' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
317
-    echo '        # Zero-day exploit defense.' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
318
-    echo '        # http://forum.nginx.org/read.php?2,88845,page=3' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
319
-    echo "        # Won't work properly (404 error) if the file is not stored on this" >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
320
-    echo "        # server, which is entirely possible with php-fpm/php-fcgi." >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
321
-    echo "        # Comment the 'try_files' line out if you set up php-fpm/php-fcgi on" >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
322
-    echo "        # another machine. And then cross your fingers that you won't get hacked." >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
323
-    echo '        try_files $uri $uri/ /index.php;' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
324
-    echo '        # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
325
-    echo '        fastcgi_split_path_info ^(.+\.php)(/.+)$;' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
326
-    echo '        # With php5-cgi alone:' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
327
-    echo '        # fastcgi_pass 127.0.0.1:9000;' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
328
-    echo '        # With php5-fpm:' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
329
-    echo '        fastcgi_pass unix:/var/run/php5-fpm.sock;' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
330
-    echo '        include fastcgi_params;' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
331
-    echo '        fastcgi_index index.php;' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
332
-    echo '        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
333
-    echo '    }' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
334
-    echo '' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
335
-    echo '    # deny access to all dot files' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
336
-    echo '    location ~ /\. {' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
337
-    echo '        deny all;' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
338
-    echo '    }' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
339
-    echo '' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
340
-    echo '    #deny access to store' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
341
-    echo '    location ~ /store {' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
342
-    echo '        deny all;' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
343
-    echo '    }' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
344
-    echo '    location ~ /(data|conf|bin|inc)/ {' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
345
-    echo '      deny all;' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
346
-    echo '    }' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
347
-    echo '    location ~ /\.ht {' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
348
-    echo '      deny  all;' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
349
-    echo '    }' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
350
-    echo '}' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
351
-    echo '' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
270
+	function_check nginx_http_redirect
271
+	nginx_http_redirect $FULLBLOG_DOMAIN_NAME
272
+	echo 'server {' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
273
+	echo '    listen 443 ssl;' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
274
+	echo "    root /var/www/$FULLBLOG_DOMAIN_NAME/htdocs;" >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
275
+	echo "    server_name $FULLBLOG_DOMAIN_NAME;" >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
276
+	echo '    access_log off;' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
277
+	echo "    error_log /var/log/nginx/${FULLBLOG_DOMAIN_NAME}_error_ssl.log $WEBSERVER_LOG_LEVEL;" >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
278
+	echo '    index index.php;' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
279
+	echo '    charset utf-8;' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
280
+	echo '    proxy_read_timeout 86400s;' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
281
+	function_check nginx_limits
282
+	nginx_limits $FULLBLOG_DOMAIN_NAME
283
+	function_check nginx_ssl
284
+	nginx_ssl $FULLBLOG_DOMAIN_NAME
285
+	function_check nginx_disable_sniffing
286
+	nginx_disable_sniffing $FULLBLOG_DOMAIN_NAME
287
+	echo '    add_header Strict-Transport-Security "max-age=0;";' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
288
+	echo '' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
289
+	echo '    # rewrite to front controller as default rule' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
290
+	echo '    location / {' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
291
+	echo '        rewrite ^/(.*) /index.php?q=$uri&$args last;' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
292
+	echo '    }' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
293
+	echo '' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
294
+	echo "    # make sure webfinger and other well known services aren't blocked" >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
295
+	echo '    # by denying dot files and rewrite request to the front controller' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
296
+	echo '    location ^~ /.well-known/ {' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
297
+	echo '        allow all;' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
298
+	echo '    }' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
299
+	echo '' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
300
+	echo '    # statically serve these file types when possible' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
301
+	echo '    # otherwise fall back to front controller' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
302
+	echo '    # allow browser to cache them' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
303
+	echo '    # added .htm for advanced source code editor library' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
304
+	echo '    location ~* \.(jpg|jpeg|gif|png|ico|css|js|htm|html|ttf|woff|svg)$ {' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
305
+	echo '        expires 30d;' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
306
+	echo '        try_files $uri /index.php?q=$uri&$args;' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
307
+	echo '    }' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
308
+	echo '' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
309
+	echo '    # block these file types' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
310
+	echo '    location ~* \.(tpl|md|tgz|log|out)$ {' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
311
+	echo '        deny all;' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
312
+	echo '    }' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
313
+	echo '' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
314
+	echo '    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
315
+	echo '    # or a unix socket' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
316
+	echo '    location ~* \.php$ {' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
317
+	echo '        # Zero-day exploit defense.' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
318
+	echo '        # http://forum.nginx.org/read.php?2,88845,page=3' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
319
+	echo "        # Won't work properly (404 error) if the file is not stored on this" >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
320
+	echo "        # server, which is entirely possible with php-fpm/php-fcgi." >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
321
+	echo "        # Comment the 'try_files' line out if you set up php-fpm/php-fcgi on" >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
322
+	echo "        # another machine. And then cross your fingers that you won't get hacked." >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
323
+	echo '        try_files $uri $uri/ /index.php;' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
324
+	echo '        # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
325
+	echo '        fastcgi_split_path_info ^(.+\.php)(/.+)$;' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
326
+	echo '        # With php5-cgi alone:' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
327
+	echo '        # fastcgi_pass 127.0.0.1:9000;' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
328
+	echo '        # With php5-fpm:' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
329
+	echo '        fastcgi_pass unix:/var/run/php5-fpm.sock;' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
330
+	echo '        include fastcgi_params;' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
331
+	echo '        fastcgi_index index.php;' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
332
+	echo '        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
333
+	echo '    }' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
334
+	echo '' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
335
+	echo '    # deny access to all dot files' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
336
+	echo '    location ~ /\. {' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
337
+	echo '        deny all;' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
338
+	echo '    }' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
339
+	echo '' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
340
+	echo '    #deny access to store' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
341
+	echo '    location ~ /store {' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
342
+	echo '        deny all;' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
343
+	echo '    }' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
344
+	echo '    location ~ /(data|conf|bin|inc)/ {' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
345
+	echo '      deny all;' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
346
+	echo '    }' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
347
+	echo '    location ~ /\.ht {' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
348
+	echo '      deny  all;' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
349
+	echo '    }' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
350
+	echo '}' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
351
+	echo '' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
352 352
 }
353 353
 
354 354
 function install_blog_website_onion {
355
-    echo 'server {' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
356
-    echo "    listen 127.0.0.1:${FULLBLOG_ONION_PORT} default_server;" >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
357
-    echo "    root /var/www/$FULLBLOG_DOMAIN_NAME/htdocs;" >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
358
-    echo "    server_name $FULLBLOG_DOMAIN_NAME;" >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
359
-    echo '    access_log off;' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
360
-    echo "    error_log /var/log/nginx/${FULLBLOG_DOMAIN_NAME}_error_ssl.log $WEBSERVER_LOG_LEVEL;" >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
361
-    echo '    index index.php;' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
362
-    echo '    charset utf-8;' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
363
-    echo '    proxy_read_timeout 86400s;' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
364
-    function_check nginx_limits
365
-    nginx_limits $FULLBLOG_DOMAIN_NAME
366
-    function_check nginx_disable_sniffing
367
-    nginx_disable_sniffing $FULLBLOG_DOMAIN_NAME
368
-    echo '    add_header Strict-Transport-Security "max-age=0;";' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
369
-    echo '' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
370
-    echo '    # rewrite to front controller as default rule' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
371
-    echo '    location / {' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
372
-    echo '        rewrite ^/(.*) /index.php?q=$uri&$args last;' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
373
-    echo '    }' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
374
-    echo '' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
375
-    echo "    # make sure webfinger and other well known services aren't blocked" >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
376
-    echo '    # by denying dot files and rewrite request to the front controller' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
377
-    echo '    location ^~ /.well-known/ {' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
378
-    echo '        allow all;' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
379
-    echo '    }' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
380
-    echo '' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
381
-    echo '    # statically serve these file types when possible' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
382
-    echo '    # otherwise fall back to front controller' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
383
-    echo '    # allow browser to cache them' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
384
-    echo '    # added .htm for advanced source code editor library' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
385
-    echo '    location ~* \.(jpg|jpeg|gif|png|ico|css|js|htm|html|ttf|woff|svg)$ {' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
386
-    echo '        expires 30d;' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
387
-    echo '        try_files $uri /index.php?q=$uri&$args;' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
388
-    echo '    }' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
389
-    echo '' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
390
-    echo '    # block these file types' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
391
-    echo '    location ~* \.(tpl|md|tgz|log|out)$ {' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
392
-    echo '        deny all;' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
393
-    echo '    }' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
394
-    echo '' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
395
-    echo '    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
396
-    echo '    # or a unix socket' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
397
-    echo '    location ~* \.php$ {' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
398
-    echo '        # Zero-day exploit defense.' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
399
-    echo '        # http://forum.nginx.org/read.php?2,88845,page=3' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
400
-    echo "        # Won't work properly (404 error) if the file is not stored on this" >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
401
-    echo "        # server, which is entirely possible with php-fpm/php-fcgi." >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
402
-    echo "        # Comment the 'try_files' line out if you set up php-fpm/php-fcgi on" >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
403
-    echo "        # another machine. And then cross your fingers that you won't get hacked." >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
404
-    echo '        try_files $uri $uri/ /index.php;' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
405
-    echo '        # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
406
-    echo '        fastcgi_split_path_info ^(.+\.php)(/.+)$;' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
407
-    echo '        # With php5-cgi alone:' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
408
-    echo '        # fastcgi_pass 127.0.0.1:9000;' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
409
-    echo '        # With php5-fpm:' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
410
-    echo '        fastcgi_pass unix:/var/run/php5-fpm.sock;' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
411
-    echo '        include fastcgi_params;' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
412
-    echo '        fastcgi_index index.php;' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
413
-    echo '        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
414
-    echo '    }' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
415
-    echo '' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
416
-    echo '    # deny access to all dot files' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
417
-    echo '    location ~ /\. {' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
418
-    echo '        deny all;' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
419
-    echo '    }' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
420
-    echo '' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
421
-    echo '    #deny access to store' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
422
-    echo '    location ~ /store {' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
423
-    echo '        deny all;' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
424
-    echo '    }' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
425
-    echo '    location ~ /(data|conf|bin|inc)/ {' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
426
-    echo '      deny all;' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
427
-    echo '    }' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
428
-    echo '    location ~ /\.ht {' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
429
-    echo '      deny  all;' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
430
-    echo '    }' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
431
-    echo '}' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
355
+	echo 'server {' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
356
+	echo "    listen 127.0.0.1:${FULLBLOG_ONION_PORT} default_server;" >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
357
+	echo "    root /var/www/$FULLBLOG_DOMAIN_NAME/htdocs;" >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
358
+	echo "    server_name $FULLBLOG_DOMAIN_NAME;" >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
359
+	echo '    access_log off;' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
360
+	echo "    error_log /var/log/nginx/${FULLBLOG_DOMAIN_NAME}_error_ssl.log $WEBSERVER_LOG_LEVEL;" >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
361
+	echo '    index index.php;' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
362
+	echo '    charset utf-8;' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
363
+	echo '    proxy_read_timeout 86400s;' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
364
+	function_check nginx_limits
365
+	nginx_limits $FULLBLOG_DOMAIN_NAME
366
+	function_check nginx_disable_sniffing
367
+	nginx_disable_sniffing $FULLBLOG_DOMAIN_NAME
368
+	echo '    add_header Strict-Transport-Security "max-age=0;";' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
369
+	echo '' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
370
+	echo '    # rewrite to front controller as default rule' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
371
+	echo '    location / {' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
372
+	echo '        rewrite ^/(.*) /index.php?q=$uri&$args last;' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
373
+	echo '    }' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
374
+	echo '' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
375
+	echo "    # make sure webfinger and other well known services aren't blocked" >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
376
+	echo '    # by denying dot files and rewrite request to the front controller' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
377
+	echo '    location ^~ /.well-known/ {' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
378
+	echo '        allow all;' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
379
+	echo '    }' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
380
+	echo '' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
381
+	echo '    # statically serve these file types when possible' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
382
+	echo '    # otherwise fall back to front controller' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
383
+	echo '    # allow browser to cache them' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
384
+	echo '    # added .htm for advanced source code editor library' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
385
+	echo '    location ~* \.(jpg|jpeg|gif|png|ico|css|js|htm|html|ttf|woff|svg)$ {' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
386
+	echo '        expires 30d;' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
387
+	echo '        try_files $uri /index.php?q=$uri&$args;' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
388
+	echo '    }' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
389
+	echo '' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
390
+	echo '    # block these file types' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
391
+	echo '    location ~* \.(tpl|md|tgz|log|out)$ {' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
392
+	echo '        deny all;' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
393
+	echo '    }' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
394
+	echo '' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
395
+	echo '    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
396
+	echo '    # or a unix socket' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
397
+	echo '    location ~* \.php$ {' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
398
+	echo '        # Zero-day exploit defense.' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
399
+	echo '        # http://forum.nginx.org/read.php?2,88845,page=3' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
400
+	echo "        # Won't work properly (404 error) if the file is not stored on this" >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
401
+	echo "        # server, which is entirely possible with php-fpm/php-fcgi." >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
402
+	echo "        # Comment the 'try_files' line out if you set up php-fpm/php-fcgi on" >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
403
+	echo "        # another machine. And then cross your fingers that you won't get hacked." >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
404
+	echo '        try_files $uri $uri/ /index.php;' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
405
+	echo '        # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
406
+	echo '        fastcgi_split_path_info ^(.+\.php)(/.+)$;' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
407
+	echo '        # With php5-cgi alone:' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
408
+	echo '        # fastcgi_pass 127.0.0.1:9000;' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
409
+	echo '        # With php5-fpm:' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
410
+	echo '        fastcgi_pass unix:/var/run/php5-fpm.sock;' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
411
+	echo '        include fastcgi_params;' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
412
+	echo '        fastcgi_index index.php;' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
413
+	echo '        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
414
+	echo '    }' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
415
+	echo '' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
416
+	echo '    # deny access to all dot files' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
417
+	echo '    location ~ /\. {' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
418
+	echo '        deny all;' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
419
+	echo '    }' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
420
+	echo '' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
421
+	echo '    #deny access to store' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
422
+	echo '    location ~ /store {' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
423
+	echo '        deny all;' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
424
+	echo '    }' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
425
+	echo '    location ~ /(data|conf|bin|inc)/ {' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
426
+	echo '      deny all;' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
427
+	echo '    }' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
428
+	echo '    location ~ /\.ht {' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
429
+	echo '      deny  all;' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
430
+	echo '    }' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
431
+	echo '}' >> /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
432 432
 }
433 433
 
434 434
 function install_blog_from_repo {
435
-    if [ ! -d /var/www/$FULLBLOG_DOMAIN_NAME ]; then
436
-	mkdir /var/www/$FULLBLOG_DOMAIN_NAME
437
-    fi
438
-
439
-    cd /var/www/$FULLBLOG_DOMAIN_NAME
440
-    git_clone $FULLBLOG_REPO htdocs
441
-    cd htdocs
442
-    git checkout $FULLBLOG_COMMIT -b $FULLBLOG_COMMIT
443
-    if ! grep -q "Blog commit" $COMPLETION_FILE; then
444
-	echo "Blog commit:$FULLBLOG_COMMIT" >> $COMPLETION_FILE
445
-    else
446
-	sed -i "s/Blog commit.*/Blog commit:$FULLBLOG_COMMIT/g" $COMPLETION_FILE
447
-    fi
435
+	if [ ! -d /var/www/$FULLBLOG_DOMAIN_NAME ]; then
436
+		mkdir /var/www/$FULLBLOG_DOMAIN_NAME
437
+	fi
438
+
439
+	cd /var/www/$FULLBLOG_DOMAIN_NAME
440
+	git_clone $FULLBLOG_REPO htdocs
441
+	cd htdocs
442
+	git checkout $FULLBLOG_COMMIT -b $FULLBLOG_COMMIT
443
+	if ! grep -q "Blog commit" $COMPLETION_FILE; then
444
+		echo "Blog commit:$FULLBLOG_COMMIT" >> $COMPLETION_FILE
445
+	else
446
+		sed -i "s/Blog commit.*/Blog commit:$FULLBLOG_COMMIT/g" $COMPLETION_FILE
447
+	fi
448 448
 }
449 449
 
450 450
 function install_blog {
451
-    if [ ! $FULLBLOG_DOMAIN_NAME ]; then
452
-	echo $'The blog domain name was not specified'
453
-	exit 5062
454
-    fi
451
+	if [ ! $FULLBLOG_DOMAIN_NAME ]; then
452
+		echo $'The blog domain name was not specified'
453
+		exit 5062
454
+	fi
455 455
 
456
-    if grep -Fxq "install_blog" $COMPLETION_FILE; then
457
-	return
458
-    fi
456
+	if grep -Fxq "install_blog" $COMPLETION_FILE; then
457
+		return
458
+	fi
459 459
 
460
-    # for the avatar changing command
461
-    apt-get -y install imagemagick
460
+	# for the avatar changing command
461
+	apt-get -y install imagemagick
462 462
 
463
-    function_check install_blog_from_repo
464
-    install_blog_from_repo
463
+	function_check install_blog_from_repo
464
+	install_blog_from_repo
465 465
 
466
-    if [[ $ONION_ONLY == "no" ]]; then
467
-	function_check install_blog_website
468
-	install_blog_website
469
-    else
470
-	echo -n '' > /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
471
-    fi
472
-    function_check install_blog_website_onion
473
-    install_blog_website_onion
466
+	if [[ $ONION_ONLY == "no" ]]; then
467
+		function_check install_blog_website
468
+		install_blog_website
469
+	else
470
+		echo -n '' > /etc/nginx/sites-available/$FULLBLOG_DOMAIN_NAME
471
+	fi
472
+	function_check install_blog_website_onion
473
+	install_blog_website_onion
474 474
 
475
-    function_check create_site_certificate
476
-    create_site_certificate $FULLBLOG_DOMAIN_NAME 'yes'
475
+	function_check create_site_certificate
476
+	create_site_certificate $FULLBLOG_DOMAIN_NAME 'yes'
477 477
 
478
-    function_check configure_php
479
-    configure_php
478
+	function_check configure_php
479
+	configure_php
480 480
 
481
-    function_check install_blog_settings
482
-    install_blog_settings
481
+	function_check install_blog_settings
482
+	install_blog_settings
483 483
 
484
-    function_check install_blog_social_networks
485
-    install_blog_social_networks
484
+	function_check install_blog_social_networks
485
+	install_blog_social_networks
486 486
 
487
-    function_check install_blog_user
488
-    install_blog_user
487
+	function_check install_blog_user
488
+	install_blog_user
489 489
 
490
-    chown -R www-data:www-data /var/www/$FULLBLOG_DOMAIN_NAME/htdocs
490
+	chown -R www-data:www-data /var/www/$FULLBLOG_DOMAIN_NAME/htdocs
491 491
 
492
-    FULLBLOG_ONION_HOSTNAME=$(add_onion_service blog 80 ${FULLBLOG_ONION_PORT})
492
+	FULLBLOG_ONION_HOSTNAME=$(add_onion_service blog 80 ${FULLBLOG_ONION_PORT})
493 493
 
494
-    function_check nginx_ensite
495
-    nginx_ensite $FULLBLOG_DOMAIN_NAME
494
+	function_check nginx_ensite
495
+	nginx_ensite $FULLBLOG_DOMAIN_NAME
496 496
 
497
-    systemctl restart php5-fpm
498
-    systemctl restart nginx
497
+	systemctl restart php5-fpm
498
+	systemctl restart nginx
499 499
 
500
-    if ! grep -q "Blog onion domain" /home/$MY_USERNAME/README; then
501
-	echo $"Blog onion domain: ${FULLBLOG_ONION_HOSTNAME}" >> /home/$MY_USERNAME/README
502
-	echo $"Log into your blog at https://${FULLBLOG_ONION_HOSTNAME}/login" >> /home/$MY_USERNAME/README
503
-	echo '' >> /home/$MY_USERNAME/README
504
-	chown $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/README
505
-	chmod 600 /home/$MY_USERNAME/README
506
-    fi
507
-    echo "Blog onion domain:${FULLBLOG_ONION_HOSTNAME}" >> $COMPLETION_FILE
500
+	if ! grep -q "Blog onion domain" /home/$MY_USERNAME/README; then
501
+		echo $"Blog onion domain: ${FULLBLOG_ONION_HOSTNAME}" >> /home/$MY_USERNAME/README
502
+		echo $"Log into your blog at https://${FULLBLOG_ONION_HOSTNAME}/login" >> /home/$MY_USERNAME/README
503
+		echo '' >> /home/$MY_USERNAME/README
504
+		chown $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/README
505
+		chmod 600 /home/$MY_USERNAME/README
506
+	fi
507
+	echo "Blog onion domain:${FULLBLOG_ONION_HOSTNAME}" >> $COMPLETION_FILE
508 508
 
509
-    function_check add_ddns_domain
510
-    add_ddns_domain $FULLBLOG_DOMAIN_NAME
509
+	function_check add_ddns_domain
510
+	add_ddns_domain $FULLBLOG_DOMAIN_NAME
511 511
 
512
-    if ! grep -q "Blog domain:" $COMPLETION_FILE; then
513
-	echo "Blog domain:$FULLBLOG_DOMAIN_NAME" >> $COMPLETION_FILE
514
-    fi
512
+	if ! grep -q "Blog domain:" $COMPLETION_FILE; then
513
+		echo "Blog domain:$FULLBLOG_DOMAIN_NAME" >> $COMPLETION_FILE
514
+	fi
515 515
 
516
-    echo 'install_blog' >> $COMPLETION_FILE
516
+	echo 'install_blog' >> $COMPLETION_FILE
517 517
 }
518 518
 
519 519
 # NOTE: deliberately no exit 0

+ 425
- 425
src/freedombone-app-cjdns Parādīt failu

@@ -42,498 +42,498 @@ CJDCMD_REPO="https://github.com/inhies/cjdcmd"
42 42
 CJDCMD_COMMIT='973cca6ed0eecf9041c3403a40193c0b1291b808'
43 43
 
44 44
 function reconfigure_cjdns {
45
-    echo -n ''
45
+	echo -n ''
46 46
 }
47 47
 
48 48
 function upgrade_cjdns {
49
-    if ! grep -Fxq "install_cjdns" $COMPLETION_FILE; then
50
-	return
51
-    fi
52
-    function_check set_repo_commit
53
-    set_repo_commit /etc/cjdns "cjdns commit" "$CJDNS_COMMIT" $CJDNS_REPO
49
+	if ! grep -Fxq "install_cjdns" $COMPLETION_FILE; then
50
+		return
51
+	fi
52
+	function_check set_repo_commit
53
+	set_repo_commit /etc/cjdns "cjdns commit" "$CJDNS_COMMIT" $CJDNS_REPO
54 54
 }
55 55
 
56 56
 function configure_firewall_for_cjdns {
57
-    if grep -Fxq "configure_firewall_for_cjdns" $COMPLETION_FILE; then
58
-	return
59
-    fi
60
-    if [[ $ENABLE_CJDNS != "yes" ]]; then
61
-	return
62
-    fi
63
-    ip6tables -t nat -A POSTROUTING -o tun0 -j MASQUERADE
64
-    ip6tables -A FORWARD -i tun0 -o eth0 -m state --state RELATED,ESTABLISHED -j ACCEPT
65
-    ip6tables -A INPUT -p udp --dport $CJDNS_PORT -j ACCEPT
66
-    ip6tables -A INPUT -p tcp --dport $CJDNS_PORT -j ACCEPT
67
-
68
-    function_check save_firewall_settings
69
-    save_firewall_settings
70
-    echo 'configure_firewall_for_cjdns' >> $COMPLETION_FILE
57
+	if grep -Fxq "configure_firewall_for_cjdns" $COMPLETION_FILE; then
58
+		return
59
+	fi
60
+	if [[ $ENABLE_CJDNS != "yes" ]]; then
61
+		return
62
+	fi
63
+	ip6tables -t nat -A POSTROUTING -o tun0 -j MASQUERADE
64
+	ip6tables -A FORWARD -i tun0 -o eth0 -m state --state RELATED,ESTABLISHED -j ACCEPT
65
+	ip6tables -A INPUT -p udp --dport $CJDNS_PORT -j ACCEPT
66
+	ip6tables -A INPUT -p tcp --dport $CJDNS_PORT -j ACCEPT
67
+
68
+	function_check save_firewall_settings
69
+	save_firewall_settings
70
+	echo 'configure_firewall_for_cjdns' >> $COMPLETION_FILE
71 71
 }
72 72
 
73 73
 function get_cjdns_public_key {
74
-    if [ -f /home/$MY_USERNAME/README ]; then
75
-	if grep -q "cjdns public key" /home/$MY_USERNAME/README; then
76
-	    if [ ! $CJDNS_PUBLIC_KEY ]; then
77
-		CJDNS_PUBLIC_KEY=$(cat /home/$MY_USERNAME/README | grep "cjdns public key" | awk -F ':' '{print $2}' | sed 's/^ *//')
78
-	    fi
74
+	if [ -f /home/$MY_USERNAME/README ]; then
75
+		if grep -q "cjdns public key" /home/$MY_USERNAME/README; then
76
+			if [ ! $CJDNS_PUBLIC_KEY ]; then
77
+				CJDNS_PUBLIC_KEY=$(cat /home/$MY_USERNAME/README | grep "cjdns public key" | awk -F ':' '{print $2}' | sed 's/^ *//')
78
+			fi
79
+		fi
79 80
 	fi
80
-    fi
81 81
 }
82 82
 
83 83
 function get_cjdns_private_key {
84
-    if [ -f /home/$MY_USERNAME/README ]; then
85
-	if grep -q "cjdns private key" /home/$MY_USERNAME/README; then
86
-	    if [ ! $CJDNS_PRIVATE_KEY ]; then
87
-		CJDNS_PRIVATE_KEY=$(cat /home/$MY_USERNAME/README | grep "cjdns private key" | awk -F ':' '{print $2}' | sed 's/^ *//')
88
-	    fi
84
+	if [ -f /home/$MY_USERNAME/README ]; then
85
+		if grep -q "cjdns private key" /home/$MY_USERNAME/README; then
86
+			if [ ! $CJDNS_PRIVATE_KEY ]; then
87
+				CJDNS_PRIVATE_KEY=$(cat /home/$MY_USERNAME/README | grep "cjdns private key" | awk -F ':' '{print $2}' | sed 's/^ *//')
88
+			fi
89
+		fi
89 90
 	fi
90
-    fi
91 91
 }
92 92
 
93 93
 function get_cjdns_ipv6_address {
94
-    if [ -f /home/$MY_USERNAME/README ]; then
95
-	if grep -q "cjdns IPv6 address" /home/$MY_USERNAME/README; then
96
-	    if [ ! $CJDNS_IPV6 ]; then
97
-		CJDNS_IPV6=$(cat /home/$MY_USERNAME/README | grep "cjdns IPv6 address" | awk -F ':' '{print $2}' | sed 's/^ *//')
98
-	    fi
94
+	if [ -f /home/$MY_USERNAME/README ]; then
95
+		if grep -q "cjdns IPv6 address" /home/$MY_USERNAME/README; then
96
+			if [ ! $CJDNS_IPV6 ]; then
97
+				CJDNS_IPV6=$(cat /home/$MY_USERNAME/README | grep "cjdns IPv6 address" | awk -F ':' '{print $2}' | sed 's/^ *//')
98
+			fi
99
+		fi
99 100
 	fi
100
-    fi
101 101
 }
102 102
 
103 103
 function get_cjdns_port {
104
-    if [ -f /home/$MY_USERNAME/README ]; then
105
-	if grep -q "cjdns port" /home/$MY_USERNAME/README; then
106
-	    if [ ! $CJDNS_PORT ]; then
107
-		CJDNS_PORT=$(cat /home/$MY_USERNAME/README | grep "cjdns port" | awk -F ':' '{print $2}' | sed 's/^ *//')
108
-	    fi
104
+	if [ -f /home/$MY_USERNAME/README ]; then
105
+		if grep -q "cjdns port" /home/$MY_USERNAME/README; then
106
+			if [ ! $CJDNS_PORT ]; then
107
+				CJDNS_PORT=$(cat /home/$MY_USERNAME/README | grep "cjdns port" | awk -F ':' '{print $2}' | sed 's/^ *//')
108
+			fi
109
+		fi
109 110
 	fi
110
-    fi
111 111
 }
112 112
 
113 113
 function get_cjdns_password {
114
-    if [ -f /home/$MY_USERNAME/README ]; then
115
-	if grep -q "cjdns password" /home/$MY_USERNAME/README; then
116
-	    if [ ! $CJDNS_PASSWORD ]; then
117
-		CJDNS_PASSWORD=$(cat /home/$MY_USERNAME/README | grep "cjdns password" | awk -F ':' '{print $2}' | sed 's/^ *//')
118
-	    fi
114
+	if [ -f /home/$MY_USERNAME/README ]; then
115
+		if grep -q "cjdns password" /home/$MY_USERNAME/README; then
116
+			if [ ! $CJDNS_PASSWORD ]; then
117
+				CJDNS_PASSWORD=$(cat /home/$MY_USERNAME/README | grep "cjdns password" | awk -F ':' '{print $2}' | sed 's/^ *//')
118
+			fi
119
+		fi
119 120
 	fi
120
-    fi
121 121
 }
122 122
 
123 123
 function backup_local_cjdns {
124
-    echo -n ''
124
+	echo -n ''
125 125
 }
126 126
 
127 127
 function restore_local_cjdns {
128
-    if [ -d $USB_MOUNT/backup/cjdns ]; then
129
-	echo $"Restoring cjdns installation"
130
-	temp_restore_dir=/root/tempcjdns
131
-	function_check restore_directory_from_usb
132
-	restore_directory_from_usb $temp_restore_dir cjdns
133
-	rm -rf /etc/cjdns
134
-	cp -r $temp_restore_dir/etc/cjdns /etc/
135
-	if [ ! "$?" = "0" ]; then
136
-	    function_check set_user_permissions
137
-	    set_user_permissions
138
-	    function_check backup_unmount_drive
139
-	    backup_unmount_drive
140
-	    exit 8472
141
-	fi
142
-	rm -rf $temp_restore_dir
143
-    fi
128
+	if [ -d $USB_MOUNT/backup/cjdns ]; then
129
+		echo $"Restoring cjdns installation"
130
+		temp_restore_dir=/root/tempcjdns
131
+		function_check restore_directory_from_usb
132
+		restore_directory_from_usb $temp_restore_dir cjdns
133
+		rm -rf /etc/cjdns
134
+		cp -r $temp_restore_dir/etc/cjdns /etc/
135
+		if [ ! "$?" = "0" ]; then
136
+			function_check set_user_permissions
137
+			set_user_permissions
138
+			function_check backup_unmount_drive
139
+			backup_unmount_drive
140
+			exit 8472
141
+		fi
142
+		rm -rf $temp_restore_dir
143
+	fi
144 144
 }
145 145
 
146 146
 function backup_remote_cjdns {
147
-    echo -n ''
147
+	echo -n ''
148 148
 }
149 149
 
150 150
 function restore_remote_cjdns {
151
-    if [ -d $SERVER_DIRECTORY/backup/cjdns ]; then
152
-	echo $"Restoring cjdns installation"
153
-	temp_restore_dir=/root/tempcjdns
154
-	function_check restore_directory_from_friend
155
-	restore_directory_from_friend $temp_restore_dir cjdns
156
-	rm -rf /etc/cjdns
157
-	cp -r $temp_restore_dir/etc/cjdns /etc/
158
-	if [ ! "$?" = "0" ]; then
159
-	    exit 7438
151
+	if [ -d $SERVER_DIRECTORY/backup/cjdns ]; then
152
+		echo $"Restoring cjdns installation"
153
+		temp_restore_dir=/root/tempcjdns
154
+		function_check restore_directory_from_friend
155
+		restore_directory_from_friend $temp_restore_dir cjdns
156
+		rm -rf /etc/cjdns
157
+		cp -r $temp_restore_dir/etc/cjdns /etc/
158
+		if [ ! "$?" = "0" ]; then
159
+			exit 7438
160
+		fi
161
+		rm -rf $temp_restore_dir
160 162
 	fi
161
-	rm -rf $temp_restore_dir
162
-    fi
163 163
 }
164 164
 
165 165
 function remove_cjdns {
166
-    if ! grep -Fxq "install_cjdns" $COMPLETION_FILE; then
167
-	return
168
-    fi
169
-    service cjdns stop
170
-    ip6tables -D nat -D POSTROUTING -o tun0 -j MASQUERADE
171
-    ip6tables -D FORWARD -i tun0 -o eth0 -m state --state RELATED,ESTABLISHED -j ACCEPT
172
-    ip6tables -D INPUT -p udp --dport $CJDNS_PORT -j ACCEPT
173
-    ip6tables -D INPUT -p tcp --dport $CJDNS_PORT -j ACCEPT
174
-    function_check save_firewall_settings
175
-    save_firewall_settings
176
-
177
-    rm -rf /etc/cjdns
178
-    sed -i '/install_cjdns/d' $COMPLETION_FILE
179
-    sed -i '/cjdns /d' $COMPLETION_FILE
180
-    sed -i '/configure_firewall_for_cjdns/d' $COMPLETION_FILE
166
+	if ! grep -Fxq "install_cjdns" $COMPLETION_FILE; then
167
+		return
168
+	fi
169
+	service cjdns stop
170
+	ip6tables -D nat -D POSTROUTING -o tun0 -j MASQUERADE
171
+	ip6tables -D FORWARD -i tun0 -o eth0 -m state --state RELATED,ESTABLISHED -j ACCEPT
172
+	ip6tables -D INPUT -p udp --dport $CJDNS_PORT -j ACCEPT
173
+	ip6tables -D INPUT -p tcp --dport $CJDNS_PORT -j ACCEPT
174
+	function_check save_firewall_settings
175
+	save_firewall_settings
176
+
177
+	rm -rf /etc/cjdns
178
+	sed -i '/install_cjdns/d' $COMPLETION_FILE
179
+	sed -i '/cjdns /d' $COMPLETION_FILE
180
+	sed -i '/configure_firewall_for_cjdns/d' $COMPLETION_FILE
181 181
 }
182 182
 
183 183
 function install_cjdns_main {
184
-    if [[ $ENABLE_CJDNS != "yes" ]]; then
185
-	return
186
-    fi
184
+	if [[ $ENABLE_CJDNS != "yes" ]]; then
185
+		return
186
+	fi
187
+
188
+	if grep -Fxq "install_cjdns_main" $COMPLETION_FILE; then
189
+		return
190
+	fi
187 191
 
188
-    if grep -Fxq "install_cjdns_main" $COMPLETION_FILE; then
189
-	return
190
-    fi
192
+	apt-get -y install nodejs git build-essential nmap
191 193
 
192
-    apt-get -y install nodejs git build-essential nmap
194
+	# if a README exists then obtain the cjdns parameters
195
+	function_check get_cjdns_ipv6_address
196
+	get_cjdns_ipv6_address
193 197
 
194
-    # if a README exists then obtain the cjdns parameters
195
-    function_check get_cjdns_ipv6_address
196
-    get_cjdns_ipv6_address
198
+	function_check get_cjdns_public_key
199
+	get_cjdns_public_key
197 200
 
198
-    function_check get_cjdns_public_key
199
-    get_cjdns_public_key
201
+	function_check get_cjdns_private_key
202
+	get_cjdns_private_key
200 203
 
201
-    function_check get_cjdns_private_key
202
-    get_cjdns_private_key
204
+	function_check get_cjdns_port
205
+	get_cjdns_port
203 206
 
204
-    function_check get_cjdns_port
205
-    get_cjdns_port
207
+	function_check get_cjdns_password
208
+	get_cjdns_password
206 209
 
207
-    function_check get_cjdns_password
208
-    get_cjdns_password
210
+	# special compile settings for running ./do on the Beaglebone Black
211
+	if [[ $INSTALLING_ON_BBB == "yes" ]]; then
212
+		CFLAGS="-O2 -march=armv7-a -mtune=cortex-a8 -mfpu=neon -ftree-vectorize -ffast-math -mfloat-abi=hard -marm -Wno-error=maybe-uninitialized"
213
+		export LDFLAGS="$CFLAGS"
214
+	fi
209 215
 
210
-    # special compile settings for running ./do on the Beaglebone Black
211
-    if [[ $INSTALLING_ON_BBB == "yes" ]]; then
212
-	CFLAGS="-O2 -march=armv7-a -mtune=cortex-a8 -mfpu=neon -ftree-vectorize -ffast-math -mfloat-abi=hard -marm -Wno-error=maybe-uninitialized"
213
-	export LDFLAGS="$CFLAGS"
214
-    fi
216
+	if [ ! -d /etc/cjdns ]; then
217
+		function_check git_pull
218
+		git_clone $CJDNS_REPO /etc/cjdns
219
+		cd /etc/cjdns
220
+
221
+		git checkout $CJDNS_COMMIT -b $CJDNS_COMMIT
222
+		if ! grep -q "cjdns commit" $COMPLETION_FILE; then
223
+			echo "cjdns commit:$CJDNS_COMMIT" >> $COMPLETION_FILE
224
+		else
225
+			sed -i "s/cjdns commit.*/cjdns commit:$CJDNS_COMMIT/g" $COMPLETION_FILE
226
+		fi
227
+
228
+		./do
229
+		if [ ! "$?" = "0" ]; then
230
+			exit 7439
231
+		fi
232
+		# create a configuration
233
+		if [ ! -f /etc/cjdns/cjdroute.conf ]; then
234
+			./cjdroute --genconf > /etc/cjdns/cjdroute.conf
235
+			if [ ! "$?" = "0" ]; then
236
+				exit 5922
237
+			fi
238
+		fi
239
+		# create a user to run as
240
+		useradd cjdns
241
+	else
242
+		cd /etc/cjdns
243
+		function_check git_pull
244
+		git_pull $CJDNS_REPO
245
+		./do
246
+		if [ ! "$?" = "0" ]; then
247
+			exit 9926
248
+		fi
249
+	fi
215 250
 
216
-    if [ ! -d /etc/cjdns ]; then
217
-	function_check git_pull
218
-	git_clone $CJDNS_REPO /etc/cjdns
219
-	cd /etc/cjdns
251
+	# set permissions
252
+	chown -R cjdns:cjdns /etc/cjdns
253
+	chmod 600 /etc/cjdns/cjdroute.conf
220 254
 
221
-	git checkout $CJDNS_COMMIT -b $CJDNS_COMMIT
222
-	if ! grep -q "cjdns commit" $COMPLETION_FILE; then
223
-	    echo "cjdns commit:$CJDNS_COMMIT" >> $COMPLETION_FILE
255
+	/sbin/ip tuntap add mode tun user cjdns dev cjdroute0
256
+
257
+	# insert values into the configuration file
258
+	if [ $CJDNS_PRIVATE_KEY ]; then
259
+		sed -i "s/\"privateKey\":.*/\"privateKey\": \"$CJDNS_PRIVATE_KEY\",/g" /etc/cjdns/cjdroute.conf
260
+	else
261
+		CJDNS_PRIVATE_KEY=$(cat /etc/cjdns/cjdroute.conf | grep '"privateKey"' | awk -F '"' '{print $4}' | sed -n 1p)
262
+	fi
263
+	if [ $CJDNS_PUBLIC_KEY ]; then
264
+		sed -i "s/\"publicKey\":.*/\"publicKey\": \"$CJDNS_PUBLIC_KEY\",/g" /etc/cjdns/cjdroute.conf
265
+	else
266
+		CJDNS_PUBLIC_KEY=$(cat /etc/cjdns/cjdroute.conf | grep '"publicKey"' | awk -F '"' '{print $4}' | sed -n 1p)
267
+	fi
268
+	if [ $CJDNS_IPV6 ]; then
269
+		sed -i "s/\"ipv6\":.*/\"ipv6\": \"$CJDNS_IPV6\",/g" /etc/cjdns/cjdroute.conf
270
+	else
271
+		CJDNS_IPV6=$(cat /etc/cjdns/cjdroute.conf | grep '"ipv6"' | awk -F '"' '{print $4}' | sed -n 1p)
272
+	fi
273
+	if [ $CJDNS_PASSWORD ]; then
274
+		sed -i "0,/{\"password\":.*/s//{\"password\": \"$CJDNS_PASSWORD\"}/g" /etc/cjdns/cjdroute.conf
275
+	else
276
+		CJDNS_PASSWORD=$(cat /etc/cjdns/cjdroute.conf | grep '"password"' | awk -F '"' '{print $4}' | sed -n 1p)
277
+	fi
278
+	if [ $CJDNS_PORT ]; then
279
+		sed -i "s/\"bind\": \"0.0.0.0:.*/\"bind\": \"0.0.0.0:$CJDNS_PORT\",/g" /etc/cjdns/cjdroute.conf
224 280
 	else
225
-	    sed -i "s/cjdns commit.*/cjdns commit:$CJDNS_COMMIT/g" $COMPLETION_FILE
281
+		CJDNS_PORT=$(cat /etc/cjdns/cjdroute.conf | grep '"bind": "0.0.0.0:' | awk -F '"' '{print $4}' | awk -F ':' '{print $2}' | sed -n 1p)
226 282
 	fi
227 283
 
228
-	./do
284
+	function_check enable_ipv6
285
+	enable_ipv6
286
+
287
+	echo '#!/bin/sh -e' > /etc/init.d/cjdns
288
+	echo '### BEGIN INIT INFO' >> /etc/init.d/cjdns
289
+	echo '# hyperboria.sh - An init script (/etc/init.d/) for cjdns' >> /etc/init.d/cjdns
290
+	echo '# Provides:          cjdroute' >> /etc/init.d/cjdns
291
+	echo '# Required-Start:    $remote_fs $network' >> /etc/init.d/cjdns
292
+	echo '# Required-Stop:     $remote_fs $network' >> /etc/init.d/cjdns
293
+	echo '# Default-Start:     2 3 4 5' >> /etc/init.d/cjdns
294
+	echo '# Default-Stop:      0 1 6' >> /etc/init.d/cjdns
295
+	echo '# Short-Description: Cjdns router' >> /etc/init.d/cjdns
296
+	echo '# Description:       A routing engine designed for security, scalability, speed and ease of use.' >> /etc/init.d/cjdns
297
+	echo '# cjdns git repo:    https://github.com/cjdelisle/cjdns/' >> /etc/init.d/cjdns
298
+	echo '### END INIT INFO' >> /etc/init.d/cjdns
299
+	echo '' >> /etc/init.d/cjdns
300
+	echo 'PROG="cjdroute"' >> /etc/init.d/cjdns
301
+	echo 'GIT_PATH="/etc/cjdns"' >> /etc/init.d/cjdns
302
+	echo 'PROG_PATH="/etc/cjdns"' >> /etc/init.d/cjdns
303
+	echo 'CJDNS_CONFIG="cjdroute.conf"' >> /etc/init.d/cjdns
304
+	echo 'CJDNS_USER="cjdns"' >> /etc/init.d/cjdns
305
+	echo "CJDNS_IP='$CJDNS_IPV6'" >> /etc/init.d/cjdns
306
+	echo '' >> /etc/init.d/cjdns
307
+	echo 'start() {' >> /etc/init.d/cjdns
308
+	echo '     # Start it up with the user cjdns' >> /etc/init.d/cjdns
309
+	echo '     if [ $(pgrep cjdroute | wc -l) != 0 ];' >> /etc/init.d/cjdns
310
+	echo '     then' >> /etc/init.d/cjdns
311
+	echo '         echo "cjdroute is already running. Doing nothing..."' >> /etc/init.d/cjdns
312
+	echo '     else' >> /etc/init.d/cjdns
313
+	echo '         echo " * Starting cjdroute"' >> /etc/init.d/cjdns
314
+	echo '         su -c "$PROG_PATH/$PROG < $PROG_PATH/$CJDNS_CONFIG" - $CJDNS_USER' >> /etc/init.d/cjdns
315
+	echo '         /sbin/ip addr add $CJDNS_IP/8 dev tun0' >> /etc/init.d/cjdns
316
+	echo '         /sbin/ip link set mtu 1312 dev tun0' >> /etc/init.d/cjdns
317
+	echo '         /sbin/ip link set tun0 up' >> /etc/init.d/cjdns
318
+	echo '         /sbin/ip tuntap add mode tun user cjdns dev tun0' >> /etc/init.d/cjdns
319
+	echo '     fi' >> /etc/init.d/cjdns
320
+	echo '}' >> /etc/init.d/cjdns
321
+	echo '' >> /etc/init.d/cjdns
322
+	echo 'stop() {' >> /etc/init.d/cjdns
323
+	echo '' >> /etc/init.d/cjdns
324
+	echo '     if [ $(pgrep cjdroute | wc -l) != 2 ];' >> /etc/init.d/cjdns
325
+	echo '     then' >> /etc/init.d/cjdns
326
+	echo '         echo "cjdns isnt running."' >> /etc/init.d/cjdns
327
+	echo '     else' >> /etc/init.d/cjdns
328
+	echo '         echo "Killing cjdroute"' >> /etc/init.d/cjdns
329
+	echo '         killall cjdroute' >> /etc/init.d/cjdns
330
+	echo '     fi' >> /etc/init.d/cjdns
331
+	echo '}' >> /etc/init.d/cjdns
332
+	echo '' >> /etc/init.d/cjdns
333
+	echo 'status() {' >> /etc/init.d/cjdns
334
+	echo '     if [ $(pgrep cjdroute | wc -l) != 0 ];' >> /etc/init.d/cjdns
335
+	echo '     then' >> /etc/init.d/cjdns
336
+	echo '         echo "Cjdns is running"' >> /etc/init.d/cjdns
337
+	echo '     else' >> /etc/init.d/cjdns
338
+	echo '         echo "Cjdns is not running"' >> /etc/init.d/cjdns
339
+	echo '     fi' >> /etc/init.d/cjdns
340
+	echo '}' >> /etc/init.d/cjdns
341
+	echo '' >> /etc/init.d/cjdns
342
+	echo ' update() {' >> /etc/init.d/cjdns
343
+	echo '     cd $GIT_PATH' >> /etc/init.d/cjdns
344
+	echo '     echo "Updating..."' >> /etc/init.d/cjdns
345
+	echo '     git pull' >> /etc/init.d/cjdns
346
+	echo '     ./do' >> /etc/init.d/cjdns
347
+	echo '}' >> /etc/init.d/cjdns
348
+	echo '' >> /etc/init.d/cjdns
349
+	echo '## Check to see if we are running as root first.' >> /etc/init.d/cjdns
350
+	echo 'if [ "$(id -u)" != "0" ]; then' >> /etc/init.d/cjdns
351
+	echo '    echo "This script must be run as root" 1>&2' >> /etc/init.d/cjdns
352
+	echo '    exit 1' >> /etc/init.d/cjdns
353
+	echo 'fi' >> /etc/init.d/cjdns
354
+	echo '' >> /etc/init.d/cjdns
355
+	echo 'case $1 in' >> /etc/init.d/cjdns
356
+	echo '     start)' >> /etc/init.d/cjdns
357
+	echo '         start' >> /etc/init.d/cjdns
358
+	echo '         exit 0' >> /etc/init.d/cjdns
359
+	echo '     ;;' >> /etc/init.d/cjdns
360
+	echo '     stop)' >> /etc/init.d/cjdns
361
+	echo '         stop' >> /etc/init.d/cjdns
362
+	echo '         exit 0' >> /etc/init.d/cjdns
363
+	echo '     ;;' >> /etc/init.d/cjdns
364
+	echo '     reload|restart|force-reload)' >> /etc/init.d/cjdns
365
+	echo '         stop' >> /etc/init.d/cjdns
366
+	echo '         sleep 1' >> /etc/init.d/cjdns
367
+	echo '         start' >> /etc/init.d/cjdns
368
+	echo '         exit 0' >> /etc/init.d/cjdns
369
+	echo '     ;;' >> /etc/init.d/cjdns
370
+	echo '     status)' >> /etc/init.d/cjdns
371
+	echo '         status' >> /etc/init.d/cjdns
372
+	echo '         exit 0' >> /etc/init.d/cjdns
373
+	echo '     ;;' >> /etc/init.d/cjdns
374
+	echo '     update|upgrade)' >> /etc/init.d/cjdns
375
+	echo '         update' >> /etc/init.d/cjdns
376
+	echo '         stop' >> /etc/init.d/cjdns
377
+	echo '         sleep 2' >> /etc/init.d/cjdns
378
+	echo '         start' >> /etc/init.d/cjdns
379
+	echo '         exit 0' >> /etc/init.d/cjdns
380
+	echo '     ;;' >> /etc/init.d/cjdns
381
+	echo '     **)' >> /etc/init.d/cjdns
382
+	echo '         echo "Usage: $0 (start|stop|restart|status|update)" 1>&2' >> /etc/init.d/cjdns
383
+	echo '         exit 1' >> /etc/init.d/cjdns
384
+	echo '     ;;' >> /etc/init.d/cjdns
385
+	echo 'esac' >> /etc/init.d/cjdns
386
+	chmod +x /etc/init.d/cjdns
387
+	update-rc.d cjdns defaults
388
+	service cjdns start
229 389
 	if [ ! "$?" = "0" ]; then
230
-	    exit 7439
231
-	fi
232
-	# create a configuration
233
-	if [ ! -f /etc/cjdns/cjdroute.conf ]; then
234
-	    ./cjdroute --genconf > /etc/cjdns/cjdroute.conf
235
-	    if [ ! "$?" = "0" ]; then
236
-		exit 5922
237
-	    fi
238
-	fi
239
-	# create a user to run as
240
-	useradd cjdns
241
-    else
242
-	cd /etc/cjdns
243
-	function_check git_pull
244
-	git_pull $CJDNS_REPO
245
-	./do
246
-	if [ ! "$?" = "0" ]; then
247
-	    exit 9926
248
-	fi
249
-    fi
250
-
251
-    # set permissions
252
-    chown -R cjdns:cjdns /etc/cjdns
253
-    chmod 600 /etc/cjdns/cjdroute.conf
254
-
255
-    /sbin/ip tuntap add mode tun user cjdns dev cjdroute0
256
-
257
-    # insert values into the configuration file
258
-    if [ $CJDNS_PRIVATE_KEY ]; then
259
-	sed -i "s/\"privateKey\":.*/\"privateKey\": \"$CJDNS_PRIVATE_KEY\",/g" /etc/cjdns/cjdroute.conf
260
-    else
261
-	CJDNS_PRIVATE_KEY=$(cat /etc/cjdns/cjdroute.conf | grep '"privateKey"' | awk -F '"' '{print $4}' | sed -n 1p)
262
-    fi
263
-    if [ $CJDNS_PUBLIC_KEY ]; then
264
-	sed -i "s/\"publicKey\":.*/\"publicKey\": \"$CJDNS_PUBLIC_KEY\",/g" /etc/cjdns/cjdroute.conf
265
-    else
266
-	CJDNS_PUBLIC_KEY=$(cat /etc/cjdns/cjdroute.conf | grep '"publicKey"' | awk -F '"' '{print $4}' | sed -n 1p)
267
-    fi
268
-    if [ $CJDNS_IPV6 ]; then
269
-	sed -i "s/\"ipv6\":.*/\"ipv6\": \"$CJDNS_IPV6\",/g" /etc/cjdns/cjdroute.conf
270
-    else
271
-	CJDNS_IPV6=$(cat /etc/cjdns/cjdroute.conf | grep '"ipv6"' | awk -F '"' '{print $4}' | sed -n 1p)
272
-    fi
273
-    if [ $CJDNS_PASSWORD ]; then
274
-	sed -i "0,/{\"password\":.*/s//{\"password\": \"$CJDNS_PASSWORD\"}/g" /etc/cjdns/cjdroute.conf
275
-    else
276
-	CJDNS_PASSWORD=$(cat /etc/cjdns/cjdroute.conf | grep '"password"' | awk -F '"' '{print $4}' | sed -n 1p)
277
-    fi
278
-    if [ $CJDNS_PORT ]; then
279
-	sed -i "s/\"bind\": \"0.0.0.0:.*/\"bind\": \"0.0.0.0:$CJDNS_PORT\",/g" /etc/cjdns/cjdroute.conf
280
-    else
281
-	CJDNS_PORT=$(cat /etc/cjdns/cjdroute.conf | grep '"bind": "0.0.0.0:' | awk -F '"' '{print $4}' | awk -F ':' '{print $2}' | sed -n 1p)
282
-    fi
283
-
284
-    function_check enable_ipv6
285
-    enable_ipv6
286
-
287
-    echo '#!/bin/sh -e' > /etc/init.d/cjdns
288
-    echo '### BEGIN INIT INFO' >> /etc/init.d/cjdns
289
-    echo '# hyperboria.sh - An init script (/etc/init.d/) for cjdns' >> /etc/init.d/cjdns
290
-    echo '# Provides:          cjdroute' >> /etc/init.d/cjdns
291
-    echo '# Required-Start:    $remote_fs $network' >> /etc/init.d/cjdns
292
-    echo '# Required-Stop:     $remote_fs $network' >> /etc/init.d/cjdns
293
-    echo '# Default-Start:     2 3 4 5' >> /etc/init.d/cjdns
294
-    echo '# Default-Stop:      0 1 6' >> /etc/init.d/cjdns
295
-    echo '# Short-Description: Cjdns router' >> /etc/init.d/cjdns
296
-    echo '# Description:       A routing engine designed for security, scalability, speed and ease of use.' >> /etc/init.d/cjdns
297
-    echo '# cjdns git repo:    https://github.com/cjdelisle/cjdns/' >> /etc/init.d/cjdns
298
-    echo '### END INIT INFO' >> /etc/init.d/cjdns
299
-    echo '' >> /etc/init.d/cjdns
300
-    echo 'PROG="cjdroute"' >> /etc/init.d/cjdns
301
-    echo 'GIT_PATH="/etc/cjdns"' >> /etc/init.d/cjdns
302
-    echo 'PROG_PATH="/etc/cjdns"' >> /etc/init.d/cjdns
303
-    echo 'CJDNS_CONFIG="cjdroute.conf"' >> /etc/init.d/cjdns
304
-    echo 'CJDNS_USER="cjdns"' >> /etc/init.d/cjdns
305
-    echo "CJDNS_IP='$CJDNS_IPV6'" >> /etc/init.d/cjdns
306
-    echo '' >> /etc/init.d/cjdns
307
-    echo 'start() {' >> /etc/init.d/cjdns
308
-    echo '     # Start it up with the user cjdns' >> /etc/init.d/cjdns
309
-    echo '     if [ $(pgrep cjdroute | wc -l) != 0 ];' >> /etc/init.d/cjdns
310
-    echo '     then' >> /etc/init.d/cjdns
311
-    echo '         echo "cjdroute is already running. Doing nothing..."' >> /etc/init.d/cjdns
312
-    echo '     else' >> /etc/init.d/cjdns
313
-    echo '         echo " * Starting cjdroute"' >> /etc/init.d/cjdns
314
-    echo '         su -c "$PROG_PATH/$PROG < $PROG_PATH/$CJDNS_CONFIG" - $CJDNS_USER' >> /etc/init.d/cjdns
315
-    echo '         /sbin/ip addr add $CJDNS_IP/8 dev tun0' >> /etc/init.d/cjdns
316
-    echo '         /sbin/ip link set mtu 1312 dev tun0' >> /etc/init.d/cjdns
317
-    echo '         /sbin/ip link set tun0 up' >> /etc/init.d/cjdns
318
-    echo '         /sbin/ip tuntap add mode tun user cjdns dev tun0' >> /etc/init.d/cjdns
319
-    echo '     fi' >> /etc/init.d/cjdns
320
-    echo '}' >> /etc/init.d/cjdns
321
-    echo '' >> /etc/init.d/cjdns
322
-    echo 'stop() {' >> /etc/init.d/cjdns
323
-    echo '' >> /etc/init.d/cjdns
324
-    echo '     if [ $(pgrep cjdroute | wc -l) != 2 ];' >> /etc/init.d/cjdns
325
-    echo '     then' >> /etc/init.d/cjdns
326
-    echo '         echo "cjdns isnt running."' >> /etc/init.d/cjdns
327
-    echo '     else' >> /etc/init.d/cjdns
328
-    echo '         echo "Killing cjdroute"' >> /etc/init.d/cjdns
329
-    echo '         killall cjdroute' >> /etc/init.d/cjdns
330
-    echo '     fi' >> /etc/init.d/cjdns
331
-    echo '}' >> /etc/init.d/cjdns
332
-    echo '' >> /etc/init.d/cjdns
333
-    echo 'status() {' >> /etc/init.d/cjdns
334
-    echo '     if [ $(pgrep cjdroute | wc -l) != 0 ];' >> /etc/init.d/cjdns
335
-    echo '     then' >> /etc/init.d/cjdns
336
-    echo '         echo "Cjdns is running"' >> /etc/init.d/cjdns
337
-    echo '     else' >> /etc/init.d/cjdns
338
-    echo '         echo "Cjdns is not running"' >> /etc/init.d/cjdns
339
-    echo '     fi' >> /etc/init.d/cjdns
340
-    echo '}' >> /etc/init.d/cjdns
341
-    echo '' >> /etc/init.d/cjdns
342
-    echo ' update() {' >> /etc/init.d/cjdns
343
-    echo '     cd $GIT_PATH' >> /etc/init.d/cjdns
344
-    echo '     echo "Updating..."' >> /etc/init.d/cjdns
345
-    echo '     git pull' >> /etc/init.d/cjdns
346
-    echo '     ./do' >> /etc/init.d/cjdns
347
-    echo '}' >> /etc/init.d/cjdns
348
-    echo '' >> /etc/init.d/cjdns
349
-    echo '## Check to see if we are running as root first.' >> /etc/init.d/cjdns
350
-    echo 'if [ "$(id -u)" != "0" ]; then' >> /etc/init.d/cjdns
351
-    echo '    echo "This script must be run as root" 1>&2' >> /etc/init.d/cjdns
352
-    echo '    exit 1' >> /etc/init.d/cjdns
353
-    echo 'fi' >> /etc/init.d/cjdns
354
-    echo '' >> /etc/init.d/cjdns
355
-    echo 'case $1 in' >> /etc/init.d/cjdns
356
-    echo '     start)' >> /etc/init.d/cjdns
357
-    echo '         start' >> /etc/init.d/cjdns
358
-    echo '         exit 0' >> /etc/init.d/cjdns
359
-    echo '     ;;' >> /etc/init.d/cjdns
360
-    echo '     stop)' >> /etc/init.d/cjdns
361
-    echo '         stop' >> /etc/init.d/cjdns
362
-    echo '         exit 0' >> /etc/init.d/cjdns
363
-    echo '     ;;' >> /etc/init.d/cjdns
364
-    echo '     reload|restart|force-reload)' >> /etc/init.d/cjdns
365
-    echo '         stop' >> /etc/init.d/cjdns
366
-    echo '         sleep 1' >> /etc/init.d/cjdns
367
-    echo '         start' >> /etc/init.d/cjdns
368
-    echo '         exit 0' >> /etc/init.d/cjdns
369
-    echo '     ;;' >> /etc/init.d/cjdns
370
-    echo '     status)' >> /etc/init.d/cjdns
371
-    echo '         status' >> /etc/init.d/cjdns
372
-    echo '         exit 0' >> /etc/init.d/cjdns
373
-    echo '     ;;' >> /etc/init.d/cjdns
374
-    echo '     update|upgrade)' >> /etc/init.d/cjdns
375
-    echo '         update' >> /etc/init.d/cjdns
376
-    echo '         stop' >> /etc/init.d/cjdns
377
-    echo '         sleep 2' >> /etc/init.d/cjdns
378
-    echo '         start' >> /etc/init.d/cjdns
379
-    echo '         exit 0' >> /etc/init.d/cjdns
380
-    echo '     ;;' >> /etc/init.d/cjdns
381
-    echo '     **)' >> /etc/init.d/cjdns
382
-    echo '         echo "Usage: $0 (start|stop|restart|status|update)" 1>&2' >> /etc/init.d/cjdns
383
-    echo '         exit 1' >> /etc/init.d/cjdns
384
-    echo '     ;;' >> /etc/init.d/cjdns
385
-    echo 'esac' >> /etc/init.d/cjdns
386
-    chmod +x /etc/init.d/cjdns
387
-    update-rc.d cjdns defaults
388
-    service cjdns start
389
-    if [ ! "$?" = "0" ]; then
390
-	systemctl status cjdns.service
391
-	exit 8260
392
-    fi
393
-
394
-    apt-get -y install radvd
395
-    echo 'interface eth0' > /etc/radvd.conf
396
-    echo '{' >> /etc/radvd.conf
397
-    echo '    AdvSendAdvert on;' >> /etc/radvd.conf
398
-    echo '    prefix fdfc::1/64' >> /etc/radvd.conf
399
-    echo '    {' >> /etc/radvd.conf
400
-    echo '        AdvRouterAddr on;' >> /etc/radvd.conf
401
-    echo '    };' >> /etc/radvd.conf
402
-    echo '};' >> /etc/radvd.conf
403
-    systemctl restart radvd
404
-    if [ ! "$?" = "0" ]; then
405
-	systemctl status radvd.service
406
-	exit 4395
407
-    fi
408
-
409
-    if ! grep -q "# Mesh Networking (cjdns)" /etc/network/interfaces; then
410
-	echo '' >> /etc/network/interfaces
411
-	echo '# Mesh Networking (cjdns)' >> /etc/network/interfaces
412
-	echo 'iface eth0 inet6 static' >> /etc/network/interfaces
413
-	echo '    pre-up modprobe ipv6' >> /etc/network/interfaces
414
-	echo '    address fdfc:0000:0000:0000:0000:0000:0000:0001' >> /etc/network/interfaces
415
-	echo '    netmask 64' >> /etc/network/interfaces
416
-	service network-manager restart
390
+		systemctl status cjdns.service
391
+		exit 8260
392
+	fi
393
+
394
+	apt-get -y install radvd
395
+	echo 'interface eth0' > /etc/radvd.conf
396
+	echo '{' >> /etc/radvd.conf
397
+	echo '    AdvSendAdvert on;' >> /etc/radvd.conf
398
+	echo '    prefix fdfc::1/64' >> /etc/radvd.conf
399
+	echo '    {' >> /etc/radvd.conf
400
+	echo '        AdvRouterAddr on;' >> /etc/radvd.conf
401
+	echo '    };' >> /etc/radvd.conf
402
+	echo '};' >> /etc/radvd.conf
403
+	systemctl restart radvd
417 404
 	if [ ! "$?" = "0" ]; then
418
-	    systemctl status networking.service
419
-	    exit 6949
420
-	fi
421
-    fi
422
-
423
-    if ! grep -q $"Mesh Networking (cjdns)" /home/$MY_USERNAME/README; then
424
-	CURRENT_IP_ADDRESS=$(ip addr show | grep "inet " | sed -n 2p | awk -F ' ' '{print $2}' | awk -F '/' '{print $1}')
425
-
426
-	echo '' >> /home/$MY_USERNAME/README
427
-	echo '' >> /home/$MY_USERNAME/README
428
-	echo $'Mesh Networking (cjdns)' >> /home/$MY_USERNAME/README
429
-	echo '=======================' >> /home/$MY_USERNAME/README
430
-	echo $"cjdns IPv6 address: $CJDNS_IPV6" >> /home/$MY_USERNAME/README
431
-	echo $"cjdns public key: $CJDNS_PUBLIC_KEY" >> /home/$MY_USERNAME/README
432
-	echo $"cjdns private key: $CJDNS_PRIVATE_KEY" >> /home/$MY_USERNAME/README
433
-	echo $"cjdns password: $CJDNS_PASSWORD" >> /home/$MY_USERNAME/README
434
-	echo $"cjdns port: $CJDNS_PORT" >> /home/$MY_USERNAME/README
435
-	echo '' >> /home/$MY_USERNAME/README
436
-	echo $"Forward port $CJDNS_PORT from your internet router to the ${PROJECT_NAME}" >> /home/$MY_USERNAME/README
437
-	echo '' >> /home/$MY_USERNAME/README
438
-	echo $'Below is an example of your connection credentials' >> /home/$MY_USERNAME/README
439
-	echo $'that you can give to other people so they can connect' >> /home/$MY_USERNAME/README
440
-	echo $'to you using your default password' >> /home/$MY_USERNAME/README
441
-	echo $'Adding a unique password for each user is advisable' >> /home/$MY_USERNAME/README
442
-	echo $'so that leaks can be isolated.' >> /home/$MY_USERNAME/README
443
-	echo '' >> /home/$MY_USERNAME/README
444
-	echo "\"$CURRENT_IP_ADDRESS:$CJDNS_PORT\":{\"password\":\"$CJDNS_PASSWORD\",\"publicKey\":\"$CJDNS_PUBLIC_KEY\"}" >> /home/$MY_USERNAME/README
445
-	echo '' >> /home/$MY_USERNAME/README
446
-	echo $'More is not better. 3-5 cjdns peers is good. 30 peers is bad.' >> /home/$MY_USERNAME/README
447
-	echo '' >> /home/$MY_USERNAME/README
448
-	echo $'NEVER USE A PUBLIC PEER. These degrade the network and make it centralized.' >> /home/$MY_USERNAME/README
449
-	echo $'Each node can handle many peers, but no node can handle the entire internet.' >> /home/$MY_USERNAME/README
450
-	echo $'As this network grows any public peer will simply become saturated and' >> /home/$MY_USERNAME/README
451
-	echo $'useless causing issues for the entire network.' >> /home/$MY_USERNAME/README
452
-	echo $'Please report anyone offering you a public peer as they are promoting shared' >> /home/$MY_USERNAME/README
453
-	echo $'passwords which could lead to people pretending to be you. A peering pass' >> /home/$MY_USERNAME/README
454
-	echo $'should not contain someone elses nickname or info but should contain yours' >> /home/$MY_USERNAME/README
455
-	echo $'to ensure it is not shared. It also helps when editing the conf to know who' >> /home/$MY_USERNAME/README
456
-	echo $'each password is for.' >> /home/$MY_USERNAME/README
457
-	echo '' >> /home/$MY_USERNAME/README
458
-	echo $'Possible cjdns destinations of interest:' >> /home/$MY_USERNAME/README
459
-	echo '    http://transitiontech.ca/faq' >> /home/$MY_USERNAME/README
460
-	echo '    http://cjdns.ca/hypeirc.txt' >> /home/$MY_USERNAME/README
461
-	chown $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/README
462
-	chmod 600 /home/$MY_USERNAME/README
463
-    fi
464
-
465
-    function_check configure_firewall_for_cjdns
466
-    configure_firewall_for_cjdns
467
-
468
-    echo 'install_cjdns_main' >> $COMPLETION_FILE
405
+		systemctl status radvd.service
406
+		exit 4395
407
+	fi
408
+
409
+	if ! grep -q "# Mesh Networking (cjdns)" /etc/network/interfaces; then
410
+		echo '' >> /etc/network/interfaces
411
+		echo '# Mesh Networking (cjdns)' >> /etc/network/interfaces
412
+		echo 'iface eth0 inet6 static' >> /etc/network/interfaces
413
+		echo '    pre-up modprobe ipv6' >> /etc/network/interfaces
414
+		echo '    address fdfc:0000:0000:0000:0000:0000:0000:0001' >> /etc/network/interfaces
415
+		echo '    netmask 64' >> /etc/network/interfaces
416
+		service network-manager restart
417
+		if [ ! "$?" = "0" ]; then
418
+			systemctl status networking.service
419
+			exit 6949
420
+		fi
421
+	fi
422
+
423
+	if ! grep -q $"Mesh Networking (cjdns)" /home/$MY_USERNAME/README; then
424
+		CURRENT_IP_ADDRESS=$(ip addr show | grep "inet " | sed -n 2p | awk -F ' ' '{print $2}' | awk -F '/' '{print $1}')
425
+
426
+		echo '' >> /home/$MY_USERNAME/README
427
+		echo '' >> /home/$MY_USERNAME/README
428
+		echo $'Mesh Networking (cjdns)' >> /home/$MY_USERNAME/README
429
+		echo '=======================' >> /home/$MY_USERNAME/README
430
+		echo $"cjdns IPv6 address: $CJDNS_IPV6" >> /home/$MY_USERNAME/README
431
+		echo $"cjdns public key: $CJDNS_PUBLIC_KEY" >> /home/$MY_USERNAME/README
432
+		echo $"cjdns private key: $CJDNS_PRIVATE_KEY" >> /home/$MY_USERNAME/README
433
+		echo $"cjdns password: $CJDNS_PASSWORD" >> /home/$MY_USERNAME/README
434
+		echo $"cjdns port: $CJDNS_PORT" >> /home/$MY_USERNAME/README
435
+		echo '' >> /home/$MY_USERNAME/README
436
+		echo $"Forward port $CJDNS_PORT from your internet router to the ${PROJECT_NAME}" >> /home/$MY_USERNAME/README
437
+		echo '' >> /home/$MY_USERNAME/README
438
+		echo $'Below is an example of your connection credentials' >> /home/$MY_USERNAME/README
439
+		echo $'that you can give to other people so they can connect' >> /home/$MY_USERNAME/README
440
+		echo $'to you using your default password' >> /home/$MY_USERNAME/README
441
+		echo $'Adding a unique password for each user is advisable' >> /home/$MY_USERNAME/README
442
+		echo $'so that leaks can be isolated.' >> /home/$MY_USERNAME/README
443
+		echo '' >> /home/$MY_USERNAME/README
444
+		echo "\"$CURRENT_IP_ADDRESS:$CJDNS_PORT\":{\"password\":\"$CJDNS_PASSWORD\",\"publicKey\":\"$CJDNS_PUBLIC_KEY\"}" >> /home/$MY_USERNAME/README
445
+		echo '' >> /home/$MY_USERNAME/README
446
+		echo $'More is not better. 3-5 cjdns peers is good. 30 peers is bad.' >> /home/$MY_USERNAME/README
447
+		echo '' >> /home/$MY_USERNAME/README
448
+		echo $'NEVER USE A PUBLIC PEER. These degrade the network and make it centralized.' >> /home/$MY_USERNAME/README
449
+		echo $'Each node can handle many peers, but no node can handle the entire internet.' >> /home/$MY_USERNAME/README
450
+		echo $'As this network grows any public peer will simply become saturated and' >> /home/$MY_USERNAME/README
451
+		echo $'useless causing issues for the entire network.' >> /home/$MY_USERNAME/README
452
+		echo $'Please report anyone offering you a public peer as they are promoting shared' >> /home/$MY_USERNAME/README
453
+		echo $'passwords which could lead to people pretending to be you. A peering pass' >> /home/$MY_USERNAME/README
454
+		echo $'should not contain someone elses nickname or info but should contain yours' >> /home/$MY_USERNAME/README
455
+		echo $'to ensure it is not shared. It also helps when editing the conf to know who' >> /home/$MY_USERNAME/README
456
+		echo $'each password is for.' >> /home/$MY_USERNAME/README
457
+		echo '' >> /home/$MY_USERNAME/README
458
+		echo $'Possible cjdns destinations of interest:' >> /home/$MY_USERNAME/README
459
+		echo '    http://transitiontech.ca/faq' >> /home/$MY_USERNAME/README
460
+		echo '    http://cjdns.ca/hypeirc.txt' >> /home/$MY_USERNAME/README
461
+		chown $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/README
462
+		chmod 600 /home/$MY_USERNAME/README
463
+	fi
464
+
465
+	function_check configure_firewall_for_cjdns
466
+	configure_firewall_for_cjdns
467
+
468
+	echo 'install_cjdns_main' >> $COMPLETION_FILE
469 469
 }
470 470
 
471 471
 function install_cjdns_tools {
472
-    if grep -Fxq "install_cjdns_tools" $COMPLETION_FILE; then
473
-	return
474
-    fi
475
-    if [[ $ENABLE_CJDNS != "yes" ]]; then
476
-	return
477
-    fi
478
-    if [ ! -d /etc/cjdns ]; then
479
-	install_cjdns
480
-    fi
481
-
482
-    function_check select_go_version
483
-    select_go_version
484
-
485
-    apt-get -y install golang mercurial
486
-    if [ ! -f ~/.bashrc ]; then
487
-	touch ~/.bashrc
488
-    fi
489
-
490
-    if [ ! -d /home/git ]; then
491
-	# add a gogs user account
492
-	adduser --disabled-login --gecos 'Gogs' git
493
-
494
-	# install Go
472
+	if grep -Fxq "install_cjdns_tools" $COMPLETION_FILE; then
473
+		return
474
+	fi
475
+	if [[ $ENABLE_CJDNS != "yes" ]]; then
476
+		return
477
+	fi
478
+	if [ ! -d /etc/cjdns ]; then
479
+		install_cjdns
480
+	fi
481
+
482
+	function_check select_go_version
483
+	select_go_version
484
+
485
+	apt-get -y install golang mercurial
486
+	if [ ! -f ~/.bashrc ]; then
487
+		touch ~/.bashrc
488
+	fi
489
+
490
+	if [ ! -d /home/git ]; then
491
+		# add a gogs user account
492
+		adduser --disabled-login --gecos 'Gogs' git
493
+
494
+		# install Go
495
+		if ! grep -q "export GOPATH=" ~/.bashrc; then
496
+			echo "export GOPATH=$GOPATH" >> ~/.bashrc
497
+		fi
498
+		systemctl set-environment GOPATH=$GOPATH
499
+		if ! grep -q "systemctl set-environment GOPATH=" ~/.bashrc; then
500
+			echo "systemctl set-environment GOPATH=$GOPATH" >> ~/.bashrc
501
+		fi
502
+		if [ ! -d $GOPATH ]; then
503
+			mkdir -p $GOPATH
504
+		fi
505
+	fi
506
+
495 507
 	if ! grep -q "export GOPATH=" ~/.bashrc; then
496
-	    echo "export GOPATH=$GOPATH" >> ~/.bashrc
497
-	fi
498
-	systemctl set-environment GOPATH=$GOPATH
499
-	if ! grep -q "systemctl set-environment GOPATH=" ~/.bashrc; then
500
-	    echo "systemctl set-environment GOPATH=$GOPATH" >> ~/.bashrc
501
-	fi
502
-	if [ ! -d $GOPATH ]; then
503
-	    mkdir -p $GOPATH
504
-	fi
505
-    fi
506
-
507
-    if ! grep -q "export GOPATH=" ~/.bashrc; then
508
-	echo "export GOPATH=$GOPATH" >> ~/.bashrc
509
-    fi
510
-    expected_go_path='export PATH=$PATH:'${GOPATH}'/bin'
511
-    export PATH=$PATH:${GOPATH}/bin
512
-    if ! grep -q "$expected_go_path" ~/.bashrc; then
513
-	echo "$expected_go_path" >> ~/.bashrc
514
-    fi
515
-    export PATH=$PATH:$GOPATH/bin
516
-    CJDCMD_REPO2=$(echo "$CJDCMD_REPO" | sed 's|https://||g')
517
-    go get $CJDCMD_REPO2
518
-    if [ ! -f $GOPATH/bin/cjdcmd ]; then
519
-	echo $'cjdcmd was not compiled. Check your golang installation'
520
-	exit 7439
521
-    fi
522
-    cp $GOPATH/bin/cjdcmd /usr/bin
523
-
524
-    # initialise from the cjdns config
525
-    /usr/bin/cjdcmd cjdnsadmin -file /etc/cjdns/cjdroute.conf
526
-
527
-    echo 'install_cjdns_tools' >> $COMPLETION_FILE
508
+		echo "export GOPATH=$GOPATH" >> ~/.bashrc
509
+	fi
510
+	expected_go_path='export PATH=$PATH:'${GOPATH}'/bin'
511
+	export PATH=$PATH:${GOPATH}/bin
512
+	if ! grep -q "$expected_go_path" ~/.bashrc; then
513
+		echo "$expected_go_path" >> ~/.bashrc
514
+	fi
515
+	export PATH=$PATH:$GOPATH/bin
516
+	CJDCMD_REPO2=$(echo "$CJDCMD_REPO" | sed 's|https://||g')
517
+	go get $CJDCMD_REPO2
518
+	if [ ! -f $GOPATH/bin/cjdcmd ]; then
519
+		echo $'cjdcmd was not compiled. Check your golang installation'
520
+		exit 7439
521
+	fi
522
+	cp $GOPATH/bin/cjdcmd /usr/bin
523
+
524
+	# initialise from the cjdns config
525
+	/usr/bin/cjdcmd cjdnsadmin -file /etc/cjdns/cjdroute.conf
526
+
527
+	echo 'install_cjdns_tools' >> $COMPLETION_FILE
528 528
 }
529 529
 
530 530
 function install_cjdns {
531
-    if grep -Fxq "install_cjdns" $COMPLETION_FILE; then
532
-	return
533
-    fi
534
-    install_cjdns_main
535
-    install_cjdns_tools
536
-    echo 'install_cjdns' >> $COMPLETION_FILE
531
+	if grep -Fxq "install_cjdns" $COMPLETION_FILE; then
532
+		return
533
+	fi
534
+	install_cjdns_main
535
+	install_cjdns_tools
536
+	echo 'install_cjdns' >> $COMPLETION_FILE
537 537
 }
538 538
 
539 539
 # NOTE: deliberately no exit 0

+ 167
- 167
src/freedombone-app-dlna Parādīt failu

@@ -31,205 +31,205 @@
31 31
 VARIANTS='full media'
32 32
 
33 33
 function reconfigure_dlna {
34
-    echo ''
34
+	echo ''
35 35
 }
36 36
 
37 37
 function upgrade_dlna {
38
-    echo ''
38
+	echo ''
39 39
 }
40 40
 
41 41
 function configure_firewall_for_dlna {
42
-    if grep -Fxq "configure_firewall_for_dlna" $COMPLETION_FILE; then
43
-	return
44
-    fi
45
-    if [[ $INSTALLED_WITHIN_DOCKER == "yes" ]]; then
46
-	# docker does its own firewalling
47
-	return
48
-    fi
49
-    iptables -A INPUT -p udp --dport 1900 -j ACCEPT
50
-    iptables -A INPUT -p tcp --dport 8200 -j ACCEPT
51
-    function_check save_firewall_settings
52
-    save_firewall_settings
53
-
54
-    OPEN_PORTS+=('DLNA     1900')
55
-    OPEN_PORTS+=('DLNA     8200')
56
-    echo 'configure_firewall_for_dlna' >> $COMPLETION_FILE
42
+	if grep -Fxq "configure_firewall_for_dlna" $COMPLETION_FILE; then
43
+		return
44
+	fi
45
+	if [[ $INSTALLED_WITHIN_DOCKER == "yes" ]]; then
46
+		# docker does its own firewalling
47
+		return
48
+	fi
49
+	iptables -A INPUT -p udp --dport 1900 -j ACCEPT
50
+	iptables -A INPUT -p tcp --dport 8200 -j ACCEPT
51
+	function_check save_firewall_settings
52
+	save_firewall_settings
53
+
54
+	OPEN_PORTS+=('DLNA     1900')
55
+	OPEN_PORTS+=('DLNA     8200')
56
+	echo 'configure_firewall_for_dlna' >> $COMPLETION_FILE
57 57
 }
58 58
 
59 59
 function backup_local_dlna {
60
-    source_directory=/var/cache/minidlna
61
-    if [ -d $source_directory ]; then
62
-	dest_directory=dlna
63
-	echo $"Backing up $source_directory to $dest_directory"
60
+	source_directory=/var/cache/minidlna
61
+	if [ -d $source_directory ]; then
62
+		dest_directory=dlna
63
+		echo $"Backing up $source_directory to $dest_directory"
64 64
 
65
-	function_check backup_directory_to_usb
66
-	backup_directory_to_usb $source_directory $dest_directory
65
+		function_check backup_directory_to_usb
66
+		backup_directory_to_usb $source_directory $dest_directory
67 67
 
68
-	echo $"Backup to $dest_directory complete"
69
-    fi
68
+		echo $"Backup to $dest_directory complete"
69
+	fi
70 70
 }
71 71
 
72 72
 function restore_local_dlna {
73
-    if [ -d /var/cache/minidlna ]; then
74
-	if [ -d $USB_MOUNT/backup/dlna ]; then
75
-	    echo $"Restoring DLNA cache"
76
-	    temp_restore_dir=/root/tempdlna
77
-	    function_check restore_directory_from_usb
78
-	    restore_directory_from_usb $temp_restore_dir dlna
79
-	    cp -r $temp_restore_dir/var/cache/minidlna/* /var/cache/minidlna/
80
-	    if [ ! "$?" = "0" ]; then
81
-		rm -rf $temp_restore_dir
82
-		function_check set_user_permissions
83
-		set_user_permissions
84
-		function_check backup_unmount_drive
85
-		backup_unmount_drive
86
-		exit 982572
87
-	    fi
88
-	    rm -rf $temp_restore_dir
89
-	fi
90
-    fi
73
+	if [ -d /var/cache/minidlna ]; then
74
+		if [ -d $USB_MOUNT/backup/dlna ]; then
75
+			echo $"Restoring DLNA cache"
76
+			temp_restore_dir=/root/tempdlna
77
+			function_check restore_directory_from_usb
78
+			restore_directory_from_usb $temp_restore_dir dlna
79
+			cp -r $temp_restore_dir/var/cache/minidlna/* /var/cache/minidlna/
80
+			if [ ! "$?" = "0" ]; then
81
+				rm -rf $temp_restore_dir
82
+				function_check set_user_permissions
83
+				set_user_permissions
84
+				function_check backup_unmount_drive
85
+				backup_unmount_drive
86
+				exit 982572
87
+			fi
88
+			rm -rf $temp_restore_dir
89
+		fi
90
+	fi
91 91
 }
92 92
 
93 93
 function backup_remote_dlna {
94
-    if [ -d /var/cache/minidlna ]; then
95
-	echo $"Backing up DLNA cache"
96
-	backup_directory_to_friend /var/cache/minidlna dlna
97
-	echo $"Backup of DLNA cache complete"
98
-    fi
94
+	if [ -d /var/cache/minidlna ]; then
95
+		echo $"Backing up DLNA cache"
96
+		backup_directory_to_friend /var/cache/minidlna dlna
97
+		echo $"Backup of DLNA cache complete"
98
+	fi
99 99
 }
100 100
 
101 101
 function restore_remote_dlna {
102
-    if [ -d /var/cache/minidlna ]; then
103
-	if [ -d $SERVER_DIRECTORY/backup/dlna ]; then
104
-	    echo $"Restoring DLNA cache"
105
-	    temp_restore_dir=/root/tempdlna
106
-	    function_check restore_directory_from_friend
107
-	    restore_directory_from_friend $temp_restore_dir dlna
108
-	    cp -r $temp_restore_dir/var/cache/minidlna/* /var/cache/minidlna/
109
-	    if [ ! "$?" = "0" ]; then
110
-		exit 982
111
-	    fi
112
-	    rm -rf $temp_restore_dir
113
-	    echo $"Restore of DLNA complete"
114
-	fi
115
-    fi
102
+	if [ -d /var/cache/minidlna ]; then
103
+		if [ -d $SERVER_DIRECTORY/backup/dlna ]; then
104
+			echo $"Restoring DLNA cache"
105
+			temp_restore_dir=/root/tempdlna
106
+			function_check restore_directory_from_friend
107
+			restore_directory_from_friend $temp_restore_dir dlna
108
+			cp -r $temp_restore_dir/var/cache/minidlna/* /var/cache/minidlna/
109
+			if [ ! "$?" = "0" ]; then
110
+				exit 982
111
+			fi
112
+			rm -rf $temp_restore_dir
113
+			echo $"Restore of DLNA complete"
114
+		fi
115
+	fi
116 116
 }
117 117
 
118 118
 function remove_dlna {
119
-    if ! grep -Fxq "install_dlna" $COMPLETION_FILE; then
120
-	return
121
-    fi
122
-    service minidlna stop
123
-    apt-get -y remove --purge minidlna
124
-    if [ -f /etc/minidlna.conf ]; then
125
-	rm /etc/minidlna.conf
126
-    fi
127
-    iptables -D INPUT -p udp --dport 1900 -j ACCEPT
128
-    iptables -D INPUT -p tcp --dport 8200 -j ACCEPT
129
-    function_check save_firewall_settings
130
-    save_firewall_settings
131
-    sed -i '/install_dlna/d' $COMPLETION_FILE
119
+	if ! grep -Fxq "install_dlna" $COMPLETION_FILE; then
120
+		return
121
+	fi
122
+	service minidlna stop
123
+	apt-get -y remove --purge minidlna
124
+	if [ -f /etc/minidlna.conf ]; then
125
+		rm /etc/minidlna.conf
126
+	fi
127
+	iptables -D INPUT -p udp --dport 1900 -j ACCEPT
128
+	iptables -D INPUT -p tcp --dport 8200 -j ACCEPT
129
+	function_check save_firewall_settings
130
+	save_firewall_settings
131
+	sed -i '/install_dlna/d' $COMPLETION_FILE
132 132
 }
133 133
 
134 134
 function install_dlna_main {
135
-    if grep -Fxq "install_dlna_main" $COMPLETION_FILE; then
136
-	return
137
-    fi
138
-
139
-    apt-get -y install minidlna
140
-
141
-    if [ ! -f /etc/minidlna.conf ]; then
142
-	echo $"ERROR: minidlna does not appear to have installed. $CHECK_MESSAGE"
143
-	exit 55
144
-    fi
145
-
146
-    sed -i "s|media_dir=/var/lib/minidlna|media_dir=A,/home/$MY_USERNAME/Music|g" /etc/minidlna.conf
147
-    if ! grep -q "/home/$MY_USERNAME/Pictures" /etc/minidlna.conf; then
148
-	echo "media_dir=P,/home/$MY_USERNAME/Pictures" >> /etc/minidlna.conf
149
-    fi
150
-    if ! grep -q "/home/$MY_USERNAME/Videos" /etc/minidlna.conf; then
151
-	echo "media_dir=V,/home/$MY_USERNAME/Videos" >> /etc/minidlna.conf
152
-    fi
153
-    if ! grep -q "$USB_MOUNT/Music" /etc/minidlna.conf; then
154
-	echo "media_dir=A,$USB_MOUNT/Music" >> /etc/minidlna.conf
155
-    fi
156
-    if ! grep -q "$USB_MOUNT/Pictures" /etc/minidlna.conf; then
157
-	echo "media_dir=P,$USB_MOUNT/Pictures" >> /etc/minidlna.conf
158
-    fi
159
-    if ! grep -q "$USB_MOUNT/Videos" /etc/minidlna.conf; then
160
-	echo "media_dir=V,$USB_MOUNT/Videos" >> /etc/minidlna.conf
161
-    fi
162
-    sed -i 's/#root_container=./root_container=B/g' /etc/minidlna.conf
163
-    if [[ $SYSTEM_TYPE != "$VARIANT_MESH" ]]; then
164
-	sed -i 's/#network_interface=/network_interface=eth0/g' /etc/minidlna.conf
165
-    else
166
-	sed -i 's/#network_interface=/network_interface=$WIFI_INTERFACE/g' /etc/minidlna.conf
167
-    fi
168
-    sed -i "s/#friendly_name=/friendly_name=\"${PROJECT_NAME} Media\"/g" /etc/minidlna.conf
169
-    sed -i 's|#db_dir=/var/cache/minidlna|db_dir=/var/cache/minidlna|g' /etc/minidlna.conf
170
-    sed -i 's/#inotify=yes/inotify=yes/g' /etc/minidlna.conf
171
-    sed -i 's/#notify_interval=895/notify_interval=300/g' /etc/minidlna.conf
172
-    sed -i "s|#presentation_url=/|presentation_url=http://localhost:8200|g" /etc/minidlna.conf
173
-    service minidlna force-reload
174
-    service minidlna reload
175
-
176
-    sed -i 's/fs.inotify.max_user_watches*/fs.inotify.max_user_watches=65536/g' /etc/sysctl.conf
177
-    if ! grep -q "max_user_watches" $COMPLETION_FILE; then
178
-	echo 'fs.inotify.max_user_watches=65536' >> /etc/sysctl.conf
179
-    fi
180
-    /sbin/sysctl -p
181
-
182
-    function_check configure_firewall_for_dlna
183
-    configure_firewall_for_dlna
184
-    echo 'install_dlna_main' >> $COMPLETION_FILE
135
+	if grep -Fxq "install_dlna_main" $COMPLETION_FILE; then
136
+		return
137
+	fi
138
+
139
+	apt-get -y install minidlna
140
+
141
+	if [ ! -f /etc/minidlna.conf ]; then
142
+		echo $"ERROR: minidlna does not appear to have installed. $CHECK_MESSAGE"
143
+		exit 55
144
+	fi
145
+
146
+	sed -i "s|media_dir=/var/lib/minidlna|media_dir=A,/home/$MY_USERNAME/Music|g" /etc/minidlna.conf
147
+	if ! grep -q "/home/$MY_USERNAME/Pictures" /etc/minidlna.conf; then
148
+		echo "media_dir=P,/home/$MY_USERNAME/Pictures" >> /etc/minidlna.conf
149
+	fi
150
+	if ! grep -q "/home/$MY_USERNAME/Videos" /etc/minidlna.conf; then
151
+		echo "media_dir=V,/home/$MY_USERNAME/Videos" >> /etc/minidlna.conf
152
+	fi
153
+	if ! grep -q "$USB_MOUNT/Music" /etc/minidlna.conf; then
154
+		echo "media_dir=A,$USB_MOUNT/Music" >> /etc/minidlna.conf
155
+	fi
156
+	if ! grep -q "$USB_MOUNT/Pictures" /etc/minidlna.conf; then
157
+		echo "media_dir=P,$USB_MOUNT/Pictures" >> /etc/minidlna.conf
158
+	fi
159
+	if ! grep -q "$USB_MOUNT/Videos" /etc/minidlna.conf; then
160
+		echo "media_dir=V,$USB_MOUNT/Videos" >> /etc/minidlna.conf
161
+	fi
162
+	sed -i 's/#root_container=./root_container=B/g' /etc/minidlna.conf
163
+	if [[ $SYSTEM_TYPE != "$VARIANT_MESH" ]]; then
164
+		sed -i 's/#network_interface=/network_interface=eth0/g' /etc/minidlna.conf
165
+	else
166
+		sed -i 's/#network_interface=/network_interface=$WIFI_INTERFACE/g' /etc/minidlna.conf
167
+	fi
168
+	sed -i "s/#friendly_name=/friendly_name=\"${PROJECT_NAME} Media\"/g" /etc/minidlna.conf
169
+	sed -i 's|#db_dir=/var/cache/minidlna|db_dir=/var/cache/minidlna|g' /etc/minidlna.conf
170
+	sed -i 's/#inotify=yes/inotify=yes/g' /etc/minidlna.conf
171
+	sed -i 's/#notify_interval=895/notify_interval=300/g' /etc/minidlna.conf
172
+	sed -i "s|#presentation_url=/|presentation_url=http://localhost:8200|g" /etc/minidlna.conf
173
+	service minidlna force-reload
174
+	service minidlna reload
175
+
176
+	sed -i 's/fs.inotify.max_user_watches*/fs.inotify.max_user_watches=65536/g' /etc/sysctl.conf
177
+	if ! grep -q "max_user_watches" $COMPLETION_FILE; then
178
+		echo 'fs.inotify.max_user_watches=65536' >> /etc/sysctl.conf
179
+	fi
180
+	/sbin/sysctl -p
181
+
182
+	function_check configure_firewall_for_dlna
183
+	configure_firewall_for_dlna
184
+	echo 'install_dlna_main' >> $COMPLETION_FILE
185 185
 }
186 186
 
187 187
 function script_for_attaching_usb_drive {
188
-    if grep -Fxq "script_for_attaching_usb_drive" $COMPLETION_FILE; then
189
-	return
190
-    fi
191
-    echo '#!/bin/bash' > /usr/bin/attach-music
192
-    echo 'remove-music' >> /usr/bin/attach-music
193
-    echo "if [ ! -d $USB_MOUNT ]; then" >> /usr/bin/attach-music
194
-    echo "  mkdir $USB_MOUNT" >> /usr/bin/attach-music
195
-    echo 'fi' >> /usr/bin/attach-music
196
-    echo "mount /dev/sda1 $USB_MOUNT" >> /usr/bin/attach-music
197
-    echo "chown root:root $USB_MOUNT" >> /usr/bin/attach-music
198
-    echo "chown -R minidlna:minidlna $USB_MOUNT/*" >> /usr/bin/attach-music
199
-    echo 'service minidlna restart' >> /usr/bin/attach-music
200
-    echo 'minidlnad -R' >> /usr/bin/attach-music
201
-    chmod +x /usr/bin/attach-music
202
-    ln -s /usr/bin/attach-music /usr/bin/attach-usb
203
-    ln -s /usr/bin/attach-music /usr/bin/attach-videos
204
-    ln -s /usr/bin/attach-music /usr/bin/attach-pictures
205
-    ln -s /usr/bin/attach-music /usr/bin/attach-media
206
-
207
-    echo '#!/bin/bash' > /usr/bin/remove-music
208
-    echo "if [ -d $USB_MOUNT ]; then" >> /usr/bin/remove-music
209
-    echo "  umount $USB_MOUNT" >> /usr/bin/remove-music
210
-    echo "  rm -rf $USB_MOUNT" >> /usr/bin/remove-music
211
-    echo 'fi' >> /usr/bin/remove-music
212
-    chmod +x /usr/bin/remove-music
213
-    ln -s /usr/bin/remove-music /usr/bin/detach-music
214
-    ln -s /usr/bin/remove-music /usr/bin/detach-usb
215
-    ln -s /usr/bin/remove-music /usr/bin/remove-usb
216
-    ln -s /usr/bin/remove-music /usr/bin/detach-media
217
-    ln -s /usr/bin/remove-music /usr/bin/remove-media
218
-    ln -s /usr/bin/remove-music /usr/bin/detach-videos
219
-    ln -s /usr/bin/remove-music /usr/bin/remove-videos
220
-    ln -s /usr/bin/remove-music /usr/bin/detach-pictures
221
-    ln -s /usr/bin/remove-music /usr/bin/remove-pictures
222
-
223
-    echo 'script_for_attaching_usb_drive' >> $COMPLETION_FILE
188
+	if grep -Fxq "script_for_attaching_usb_drive" $COMPLETION_FILE; then
189
+		return
190
+	fi
191
+	echo '#!/bin/bash' > /usr/bin/attach-music
192
+	echo 'remove-music' >> /usr/bin/attach-music
193
+	echo "if [ ! -d $USB_MOUNT ]; then" >> /usr/bin/attach-music
194
+	echo "  mkdir $USB_MOUNT" >> /usr/bin/attach-music
195
+	echo 'fi' >> /usr/bin/attach-music
196
+	echo "mount /dev/sda1 $USB_MOUNT" >> /usr/bin/attach-music
197
+	echo "chown root:root $USB_MOUNT" >> /usr/bin/attach-music
198
+	echo "chown -R minidlna:minidlna $USB_MOUNT/*" >> /usr/bin/attach-music
199
+	echo 'service minidlna restart' >> /usr/bin/attach-music
200
+	echo 'minidlnad -R' >> /usr/bin/attach-music
201
+	chmod +x /usr/bin/attach-music
202
+	ln -s /usr/bin/attach-music /usr/bin/attach-usb
203
+	ln -s /usr/bin/attach-music /usr/bin/attach-videos
204
+	ln -s /usr/bin/attach-music /usr/bin/attach-pictures
205
+	ln -s /usr/bin/attach-music /usr/bin/attach-media
206
+
207
+	echo '#!/bin/bash' > /usr/bin/remove-music
208
+	echo "if [ -d $USB_MOUNT ]; then" >> /usr/bin/remove-music
209
+	echo "  umount $USB_MOUNT" >> /usr/bin/remove-music
210
+	echo "  rm -rf $USB_MOUNT" >> /usr/bin/remove-music
211
+	echo 'fi' >> /usr/bin/remove-music
212
+	chmod +x /usr/bin/remove-music
213
+	ln -s /usr/bin/remove-music /usr/bin/detach-music
214
+	ln -s /usr/bin/remove-music /usr/bin/detach-usb
215
+	ln -s /usr/bin/remove-music /usr/bin/remove-usb
216
+	ln -s /usr/bin/remove-music /usr/bin/detach-media
217
+	ln -s /usr/bin/remove-music /usr/bin/remove-media
218
+	ln -s /usr/bin/remove-music /usr/bin/detach-videos
219
+	ln -s /usr/bin/remove-music /usr/bin/remove-videos
220
+	ln -s /usr/bin/remove-music /usr/bin/detach-pictures
221
+	ln -s /usr/bin/remove-music /usr/bin/remove-pictures
222
+
223
+	echo 'script_for_attaching_usb_drive' >> $COMPLETION_FILE
224 224
 }
225 225
 
226 226
 function install_dlna {
227
-    if grep -Fxq "install_dlna" $COMPLETION_FILE; then
228
-	return
229
-    fi
230
-    install_dlna_main
231
-    script_for_attaching_usb_drive
232
-    echo 'install_dlna' >> $COMPLETION_FILE
227
+	if grep -Fxq "install_dlna" $COMPLETION_FILE; then
228
+		return
229
+	fi
230
+	install_dlna_main
231
+	script_for_attaching_usb_drive
232
+	echo 'install_dlna' >> $COMPLETION_FILE
233 233
 }
234 234
 
235 235
 # NOTE: deliberately no exit 0

+ 124
- 124
src/freedombone-app-emacs Parādīt failu

@@ -31,154 +31,154 @@
31 31
 VARIANTS='all'
32 32
 
33 33
 function reconfigure_emacs {
34
-    echo -n ''
34
+	echo -n ''
35 35
 }
36 36
 
37 37
 function upgrade_emacs {
38
-    echo -n ''
38
+	echo -n ''
39 39
 }
40 40
 
41 41
 function backup_local_emacs {
42
-    for d in /home/*/ ; do
43
-	USERNAME=$(echo "$d" | awk -F '/' '{print $3}')
44
-	if [[ $USERNAME != "git" && $USERNAME != "mirrors" && $USERNAME != "sync" ]]; then
45
-	    if [ -d /home/$USERNAME/.emacs.d ]; then
46
-		echo $"Backing up Emacs config for $USERNAME"
47
-		if [ -f /home/$USERNAME/.emacs ]; then
48
-		    cp /home/$USERNAME/.emacs /home/$USERNAME/.emacs.d/dotemacs
42
+	for d in /home/*/ ; do
43
+		USERNAME=$(echo "$d" | awk -F '/' '{print $3}')
44
+		if [[ $USERNAME != "git" && $USERNAME != "mirrors" && $USERNAME != "sync" ]]; then
45
+			if [ -d /home/$USERNAME/.emacs.d ]; then
46
+				echo $"Backing up Emacs config for $USERNAME"
47
+				if [ -f /home/$USERNAME/.emacs ]; then
48
+					cp /home/$USERNAME/.emacs /home/$USERNAME/.emacs.d/dotemacs
49
+				fi
50
+				function_check backup_directory_to_usb
51
+				backup_directory_to_usb /home/$USERNAME/.emacs.d config/$USERNAME
52
+			fi
49 53
 		fi
50
-		function_check backup_directory_to_usb
51
-		backup_directory_to_usb /home/$USERNAME/.emacs.d config/$USERNAME
52
-	    fi
53
-	fi
54
-    done
54
+	done
55 55
 }
56 56
 
57 57
 function restore_local_emacs {
58
-    temp_restore_dir=/root/tempemacs
59
-    if [ -d $USB_MOUNT/backup/emacs ]; then
60
-	for d in $USB_MOUNT/backup/emacs/*/ ; do
61
-	    USERNAME=$(echo "$d" | awk -F '/' '{print $6}')
62
-	    if [[ $USERNAME != "git" && $USERNAME != "mirrors" && $USERNAME != "sync" ]]; then
63
-		if [ ! -d /home/$USERNAME ]; then
64
-		    ${PROJECT_NAME}-adduser $USERNAME
65
-		fi
66
-		echo $"Restoring Emacs config for $USERNAME"
67
-		function_check restore_directory_from_usb
68
-		restore_directory_from_usb $temp_restore_dir emacs/$USERNAME
69
-		cp -r $temp_restore_dir/home/$USERNAME/.emacs.d /home/$USERNAME/
70
-		if [ ! "$?" = "0" ]; then
71
-		    rm -rf $temp_restore_dir
72
-		    function_check set_user_permissions
73
-		    set_user_permissions
74
-		    function_check backup_unmount_drive
75
-		    backup_unmount_drive
76
-		    exit 664
77
-		fi
78
-		cp -f $temp_restore_dir/home/$USERNAME/.emacs.d/dotemacs /home/$USERNAME/.emacs
79
-		rm -rf $temp_restore_dir
80
-	    fi
81
-	done
82
-    fi
58
+	temp_restore_dir=/root/tempemacs
59
+	if [ -d $USB_MOUNT/backup/emacs ]; then
60
+		for d in $USB_MOUNT/backup/emacs/*/ ; do
61
+			USERNAME=$(echo "$d" | awk -F '/' '{print $6}')
62
+			if [[ $USERNAME != "git" && $USERNAME != "mirrors" && $USERNAME != "sync" ]]; then
63
+				if [ ! -d /home/$USERNAME ]; then
64
+					${PROJECT_NAME}-adduser $USERNAME
65
+				fi
66
+				echo $"Restoring Emacs config for $USERNAME"
67
+				function_check restore_directory_from_usb
68
+				restore_directory_from_usb $temp_restore_dir emacs/$USERNAME
69
+				cp -r $temp_restore_dir/home/$USERNAME/.emacs.d /home/$USERNAME/
70
+				if [ ! "$?" = "0" ]; then
71
+					rm -rf $temp_restore_dir
72
+					function_check set_user_permissions
73
+					set_user_permissions
74
+					function_check backup_unmount_drive
75
+					backup_unmount_drive
76
+					exit 664
77
+				fi
78
+				cp -f $temp_restore_dir/home/$USERNAME/.emacs.d/dotemacs /home/$USERNAME/.emacs
79
+				rm -rf $temp_restore_dir
80
+			fi
81
+		done
82
+	fi
83 83
 }
84 84
 
85 85
 function backup_remote_emacs {
86
-    echo -n ''
86
+	echo -n ''
87 87
 }
88 88
 
89 89
 function restore_remote_emacs {
90
-    echo -n ''
90
+	echo -n ''
91 91
 }
92 92
 
93 93
 function remove_emacs {
94
-    if ! grep -Fxq "install_emacs" $COMPLETION_FILE; then
95
-	return
96
-    fi
97
-    apt-get -y remove --purge emacs24
98
-    update-alternatives --set editor /usr/bin/nano
99
-    sed -i '/install_emacs/d' $COMPLETION_FILE
94
+	if ! grep -Fxq "install_emacs" $COMPLETION_FILE; then
95
+		return
96
+	fi
97
+	apt-get -y remove --purge emacs24
98
+	update-alternatives --set editor /usr/bin/nano
99
+	sed -i '/install_emacs/d' $COMPLETION_FILE
100 100
 }
101 101
 
102 102
 function install_emacs {
103
-    if grep -Fxq "install_emacs" $COMPLETION_FILE; then
104
-	return
105
-    fi
106
-    update-alternatives --set editor /usr/bin/emacs24
103
+	if grep -Fxq "install_emacs" $COMPLETION_FILE; then
104
+		return
105
+	fi
106
+	update-alternatives --set editor /usr/bin/emacs24
107 107
 
108
-    # A minimal emacs configuration
109
-    #echo -n "(add-to-list 'load-path " > /home/$MY_USERNAME/.emacs
110
-    #echo '"~/.emacs.d/")' >> /home/$MY_USERNAME/.emacs
111
-    #echo '' >> /home/$MY_USERNAME/.emacs
112
-    echo $';; ===== Remove trailing whitepace ======================================' >> /home/$MY_USERNAME/.emacs
113
-    echo '' >> /home/$MY_USERNAME/.emacs
114
-    echo ";;(add-hook 'before-save-hook 'delete-trailing-whitespace)" >> /home/$MY_USERNAME/.emacs
115
-    echo '' >> /home/$MY_USERNAME/.emacs
116
-    echo ';; Goto a line number with CTRL-l' >> /home/$MY_USERNAME/.emacs
117
-    echo -n '(global-set-key "\C-l" ' >> /home/$MY_USERNAME/.emacs
118
-    echo "'goto-line)" >> /home/$MY_USERNAME/.emacs
119
-    echo '' >> /home/$MY_USERNAME/.emacs
120
-    echo $';; ===== Show line numbers ==============================================' >> /home/$MY_USERNAME/.emacs
121
-    echo '' >> /home/$MY_USERNAME/.emacs
122
-    echo "(add-hook 'find-file-hook (lambda () (linum-mode 1)))" >> /home/$MY_USERNAME/.emacs
123
-    echo '' >> /home/$MY_USERNAME/.emacs
124
-    echo $';; ===== Enable line wrapping in org-mode ===============================' >> /home/$MY_USERNAME/.emacs
125
-    echo '' >> /home/$MY_USERNAME/.emacs
126
-    echo " (add-hook 'org-mode-hook" >> /home/$MY_USERNAME/.emacs
127
-    echo "           '(lambda ()" >> /home/$MY_USERNAME/.emacs
128
-    echo "              (visual-line-mode 1)))" >> /home/$MY_USERNAME/.emacs
129
-    echo '' >> /home/$MY_USERNAME/.emacs
130
-    echo $';; ===== Enable shift select in org mode ================================' >> /home/$MY_USERNAME/.emacs
131
-    echo '' >> /home/$MY_USERNAME/.emacs
132
-    echo '(setq org-support-shift-select t)' >> /home/$MY_USERNAME/.emacs
133
-    echo '' >> /home/$MY_USERNAME/.emacs
134
-    echo $';; ===== Set standard indent to 4 rather that 4 =========================' >> /home/$MY_USERNAME/.emacs
135
-    echo '' >> /home/$MY_USERNAME/.emacs
136
-    echo '(setq standard-indent 4)' >> /home/$MY_USERNAME/.emacs
137
-    echo '(setq-default tab-width 4)' >> /home/$MY_USERNAME/.emacs
138
-    echo '(setq c-basic-offset 4)' >> /home/$MY_USERNAME/.emacs
139
-    echo '' >> /home/$MY_USERNAME/.emacs
140
-    echo $';; ===== Support Wheel Mouse Scrolling ==================================' >> /home/$MY_USERNAME/.emacs
141
-    echo '' >> /home/$MY_USERNAME/.emacs
142
-    echo '(mouse-wheel-mode t)' >> /home/$MY_USERNAME/.emacs
143
-    echo '' >> /home/$MY_USERNAME/.emacs
144
-    echo $';; ===== Place Backup Files in Specific Directory =======================' >> /home/$MY_USERNAME/.emacs
145
-    echo '' >> /home/$MY_USERNAME/.emacs
146
-    echo '(setq make-backup-files t)' >> /home/$MY_USERNAME/.emacs
147
-    echo '(setq version-control t)' >> /home/$MY_USERNAME/.emacs
148
-    echo '(setq backup-directory-alist (quote ((".*" . "~/.emacs_backups/"))))' >> /home/$MY_USERNAME/.emacs
149
-    echo '' >> /home/$MY_USERNAME/.emacs
150
-    echo $';; ===== Make Text mode the default mode for new buffers ================' >> /home/$MY_USERNAME/.emacs
151
-    echo '' >> /home/$MY_USERNAME/.emacs
152
-    echo "(setq default-major-mode 'text-mode)" >> /home/$MY_USERNAME/.emacs
153
-    echo '' >> /home/$MY_USERNAME/.emacs
154
-    echo $';; ===== Line length ====================================================' >> /home/$MY_USERNAME/.emacs
155
-    echo '' >> /home/$MY_USERNAME/.emacs
156
-    echo '(setq-default fill-column 72)' >> /home/$MY_USERNAME/.emacs
157
-    echo '' >> /home/$MY_USERNAME/.emacs
158
-    echo $';; ===== Enable Line and Column Numbering ===============================' >> /home/$MY_USERNAME/.emacs
159
-    echo '' >> /home/$MY_USERNAME/.emacs
160
-    echo '(line-number-mode 1)' >> /home/$MY_USERNAME/.emacs
161
-    echo '(column-number-mode 1)' >> /home/$MY_USERNAME/.emacs
162
-    echo '' >> /home/$MY_USERNAME/.emacs
163
-    echo $';; ===== Turn on Auto Fill mode automatically in all modes ==============' >> /home/$MY_USERNAME/.emacs
164
-    echo '' >> /home/$MY_USERNAME/.emacs
165
-    echo ';; Auto-fill-mode the the automatic wrapping of lines and insertion of' >> /home/$MY_USERNAME/.emacs
166
-    echo ';; newlines when the cursor goes over the column limit.' >> /home/$MY_USERNAME/.emacs
167
-    echo '' >> /home/$MY_USERNAME/.emacs
168
-    echo ';; This should actually turn on auto-fill-mode by default in all major' >> /home/$MY_USERNAME/.emacs
169
-    echo ';; modes. The other way to do this is to turn on the fill for specific modes' >> /home/$MY_USERNAME/.emacs
170
-    echo ';; via hooks.' >> /home/$MY_USERNAME/.emacs
171
-    echo '' >> /home/$MY_USERNAME/.emacs
172
-    echo '(setq auto-fill-mode 1)' >> /home/$MY_USERNAME/.emacs
173
-    echo '' >> /home/$MY_USERNAME/.emacs
174
-    echo $';; ===== Enable GPG encryption =========================================' >> /home/$MY_USERNAME/.emacs
175
-    echo '' >> /home/$MY_USERNAME/.emacs
176
-    echo "(require 'epa)" >> /home/$MY_USERNAME/.emacs
177
-    echo '(epa-file-enable)' >> /home/$MY_USERNAME/.emacs
178
-    cp /home/$MY_USERNAME/.emacs /root/.emacs
179
-    chown $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/.emacs
108
+	# A minimal emacs configuration
109
+	#echo -n "(add-to-list 'load-path " > /home/$MY_USERNAME/.emacs
110
+	#echo '"~/.emacs.d/")' >> /home/$MY_USERNAME/.emacs
111
+	#echo '' >> /home/$MY_USERNAME/.emacs
112
+	echo $';; ===== Remove trailing whitepace ======================================' >> /home/$MY_USERNAME/.emacs
113
+	echo '' >> /home/$MY_USERNAME/.emacs
114
+	echo ";;(add-hook 'before-save-hook 'delete-trailing-whitespace)" >> /home/$MY_USERNAME/.emacs
115
+	echo '' >> /home/$MY_USERNAME/.emacs
116
+	echo ';; Goto a line number with CTRL-l' >> /home/$MY_USERNAME/.emacs
117
+	echo -n '(global-set-key "\C-l" ' >> /home/$MY_USERNAME/.emacs
118
+	echo "'goto-line)" >> /home/$MY_USERNAME/.emacs
119
+	echo '' >> /home/$MY_USERNAME/.emacs
120
+	echo $';; ===== Show line numbers ==============================================' >> /home/$MY_USERNAME/.emacs
121
+	echo '' >> /home/$MY_USERNAME/.emacs
122
+	echo "(add-hook 'find-file-hook (lambda () (linum-mode 1)))" >> /home/$MY_USERNAME/.emacs
123
+	echo '' >> /home/$MY_USERNAME/.emacs
124
+	echo $';; ===== Enable line wrapping in org-mode ===============================' >> /home/$MY_USERNAME/.emacs
125
+	echo '' >> /home/$MY_USERNAME/.emacs
126
+	echo " (add-hook 'org-mode-hook" >> /home/$MY_USERNAME/.emacs
127
+	echo "           '(lambda ()" >> /home/$MY_USERNAME/.emacs
128
+	echo "              (visual-line-mode 1)))" >> /home/$MY_USERNAME/.emacs
129
+	echo '' >> /home/$MY_USERNAME/.emacs
130
+	echo $';; ===== Enable shift select in org mode ================================' >> /home/$MY_USERNAME/.emacs
131
+	echo '' >> /home/$MY_USERNAME/.emacs
132
+	echo '(setq org-support-shift-select t)' >> /home/$MY_USERNAME/.emacs
133
+	echo '' >> /home/$MY_USERNAME/.emacs
134
+	echo $';; ===== Set standard indent to 4 rather that 4 =========================' >> /home/$MY_USERNAME/.emacs
135
+	echo '' >> /home/$MY_USERNAME/.emacs
136
+	echo '(setq standard-indent 4)' >> /home/$MY_USERNAME/.emacs
137
+	echo '(setq-default tab-width 4)' >> /home/$MY_USERNAME/.emacs
138
+	echo '(setq c-basic-offset 4)' >> /home/$MY_USERNAME/.emacs
139
+	echo '' >> /home/$MY_USERNAME/.emacs
140
+	echo $';; ===== Support Wheel Mouse Scrolling ==================================' >> /home/$MY_USERNAME/.emacs
141
+	echo '' >> /home/$MY_USERNAME/.emacs
142
+	echo '(mouse-wheel-mode t)' >> /home/$MY_USERNAME/.emacs
143
+	echo '' >> /home/$MY_USERNAME/.emacs
144
+	echo $';; ===== Place Backup Files in Specific Directory =======================' >> /home/$MY_USERNAME/.emacs
145
+	echo '' >> /home/$MY_USERNAME/.emacs
146
+	echo '(setq make-backup-files t)' >> /home/$MY_USERNAME/.emacs
147
+	echo '(setq version-control t)' >> /home/$MY_USERNAME/.emacs
148
+	echo '(setq backup-directory-alist (quote ((".*" . "~/.emacs_backups/"))))' >> /home/$MY_USERNAME/.emacs
149
+	echo '' >> /home/$MY_USERNAME/.emacs
150
+	echo $';; ===== Make Text mode the default mode for new buffers ================' >> /home/$MY_USERNAME/.emacs
151
+	echo '' >> /home/$MY_USERNAME/.emacs
152
+	echo "(setq default-major-mode 'text-mode)" >> /home/$MY_USERNAME/.emacs
153
+	echo '' >> /home/$MY_USERNAME/.emacs
154
+	echo $';; ===== Line length ====================================================' >> /home/$MY_USERNAME/.emacs
155
+	echo '' >> /home/$MY_USERNAME/.emacs
156
+	echo '(setq-default fill-column 72)' >> /home/$MY_USERNAME/.emacs
157
+	echo '' >> /home/$MY_USERNAME/.emacs
158
+	echo $';; ===== Enable Line and Column Numbering ===============================' >> /home/$MY_USERNAME/.emacs
159
+	echo '' >> /home/$MY_USERNAME/.emacs
160
+	echo '(line-number-mode 1)' >> /home/$MY_USERNAME/.emacs
161
+	echo '(column-number-mode 1)' >> /home/$MY_USERNAME/.emacs
162
+	echo '' >> /home/$MY_USERNAME/.emacs
163
+	echo $';; ===== Turn on Auto Fill mode automatically in all modes ==============' >> /home/$MY_USERNAME/.emacs
164
+	echo '' >> /home/$MY_USERNAME/.emacs
165
+	echo ';; Auto-fill-mode the the automatic wrapping of lines and insertion of' >> /home/$MY_USERNAME/.emacs
166
+	echo ';; newlines when the cursor goes over the column limit.' >> /home/$MY_USERNAME/.emacs
167
+	echo '' >> /home/$MY_USERNAME/.emacs
168
+	echo ';; This should actually turn on auto-fill-mode by default in all major' >> /home/$MY_USERNAME/.emacs
169
+	echo ';; modes. The other way to do this is to turn on the fill for specific modes' >> /home/$MY_USERNAME/.emacs
170
+	echo ';; via hooks.' >> /home/$MY_USERNAME/.emacs
171
+	echo '' >> /home/$MY_USERNAME/.emacs
172
+	echo '(setq auto-fill-mode 1)' >> /home/$MY_USERNAME/.emacs
173
+	echo '' >> /home/$MY_USERNAME/.emacs
174
+	echo $';; ===== Enable GPG encryption =========================================' >> /home/$MY_USERNAME/.emacs
175
+	echo '' >> /home/$MY_USERNAME/.emacs
176
+	echo "(require 'epa)" >> /home/$MY_USERNAME/.emacs
177
+	echo '(epa-file-enable)' >> /home/$MY_USERNAME/.emacs
178
+	cp /home/$MY_USERNAME/.emacs /root/.emacs
179
+	chown $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/.emacs
180 180
 
181
-    echo 'install_emacs' >> $COMPLETION_FILE
181
+	echo 'install_emacs' >> $COMPLETION_FILE
182 182
 }
183 183
 
184 184
 # NOTE: deliberately no exit 0

+ 207
- 207
src/freedombone-app-ipfs Parādīt failu

@@ -35,251 +35,251 @@ IPFS_COMMIT='20b06a4cbce8884f5b194da6e98cb11f2c77f166'
35 35
 IPFS_PORT=4001
36 36
 
37 37
 function reconfigure_ipfs {
38
-    echo -n ''
38
+	echo -n ''
39 39
 }
40 40
 
41 41
 function upgrade_ipfs {
42
-    if ! grep -Fxq "install_ipfs" $COMPLETION_FILE; then
43
-	return
44
-    fi
42
+	if ! grep -Fxq "install_ipfs" $COMPLETION_FILE; then
43
+		return
44
+	fi
45 45
 
46
-    function_check select_go_version
47
-    select_go_version
46
+	function_check select_go_version
47
+	select_go_version
48 48
 
49
-    function_check set_repo_commit
50
-    set_repo_commit $GOPATH/src/github.com/ipfs/go-ipfs "ipfs commit" "$IPFS_COMMIT" $IPFS_REPO
49
+	function_check set_repo_commit
50
+	set_repo_commit $GOPATH/src/github.com/ipfs/go-ipfs "ipfs commit" "$IPFS_COMMIT" $IPFS_REPO
51 51
 }
52 52
 
53 53
 function backup_local_ipfs {
54
-    if ! grep -q "Admin user" $COMPLETION_FILE; then
55
-	return
56
-    fi
57
-    ADMIN_USERNAME=$(cat $COMPLETION_FILE | grep "Admin user" | awk -F ':' '{print $2}')
58
-    source_directory=/home/$ADMIN_USERNAME/.ipfs
59
-    if [ -d $source_directory ]; then
60
-	dest_directory=ipfs
61
-	echo $"Backing up $source_directory to $dest_directory"
62
-
63
-	function_check backup_directory_to_usb
64
-	backup_directory_to_usb $source_directory $dest_directory
65
-
66
-	echo $"Backup to $dest_directory complete"
67
-    fi
54
+	if ! grep -q "Admin user" $COMPLETION_FILE; then
55
+		return
56
+	fi
57
+	ADMIN_USERNAME=$(cat $COMPLETION_FILE | grep "Admin user" | awk -F ':' '{print $2}')
58
+	source_directory=/home/$ADMIN_USERNAME/.ipfs
59
+	if [ -d $source_directory ]; then
60
+		dest_directory=ipfs
61
+		echo $"Backing up $source_directory to $dest_directory"
62
+
63
+		function_check backup_directory_to_usb
64
+		backup_directory_to_usb $source_directory $dest_directory
65
+
66
+		echo $"Backup to $dest_directory complete"
67
+	fi
68 68
 }
69 69
 
70 70
 function restore_local_ipfs {
71
-    if ! grep -q "Admin user" $COMPLETION_FILE; then
72
-	return
73
-    fi
74
-    if [ -d $USB_MOUNT/backup/ipfs ]; then
75
-	echo $"Restoring IPFS"
76
-	temp_restore_dir=/root/tempipfs
77
-	function_check restore_directory_from_usb
78
-	restore_directory_from_usb $temp_restore_dir ipfs
79
-	ADMIN_USERNAME=$(cat $COMPLETION_FILE | grep "Admin user" | awk -F ':' '{print $2}')
80
-	cp -rf $temp_restore_dir/home/$ADMIN_USERNAME/.ipfs/* /home/$ADMIN_USERNAME/.ipfs
81
-	if [ ! "$?" = "0" ]; then
82
-	    rm -rf $temp_restore_dir
83
-	    function_check set_user_permissions
84
-	    set_user_permissions
85
-	    function_check backup_unmount_drive
86
-	    backup_unmount_drive
87
-	    exit 27627
71
+	if ! grep -q "Admin user" $COMPLETION_FILE; then
72
+		return
73
+	fi
74
+	if [ -d $USB_MOUNT/backup/ipfs ]; then
75
+		echo $"Restoring IPFS"
76
+		temp_restore_dir=/root/tempipfs
77
+		function_check restore_directory_from_usb
78
+		restore_directory_from_usb $temp_restore_dir ipfs
79
+		ADMIN_USERNAME=$(cat $COMPLETION_FILE | grep "Admin user" | awk -F ':' '{print $2}')
80
+		cp -rf $temp_restore_dir/home/$ADMIN_USERNAME/.ipfs/* /home/$ADMIN_USERNAME/.ipfs
81
+		if [ ! "$?" = "0" ]; then
82
+			rm -rf $temp_restore_dir
83
+			function_check set_user_permissions
84
+			set_user_permissions
85
+			function_check backup_unmount_drive
86
+			backup_unmount_drive
87
+			exit 27627
88
+		fi
89
+		rm -rf $temp_restore_dir
90
+		echo $"Restore of IPFS complete"
88 91
 	fi
89
-	rm -rf $temp_restore_dir
90
-	echo $"Restore of IPFS complete"
91
-    fi
92 92
 }
93 93
 
94 94
 function backup_remote_ipfs {
95
-    if ! grep -q "Admin user" $COMPLETION_FILE; then
96
-	return
97
-    fi
98
-    ADMIN_USERNAME=$(cat $COMPLETION_FILE | grep "Admin user" | awk -F ':' '{print $2}')
99
-    if [ -d /home/$ADMIN_USERNAME/.ipfs ]; then
100
-	echo $"Backing up IPFS"
101
-	backup_directory_to_friend /home/$ADMIN_USERNAME/.ipfs ipfs
102
-	echo $"Backup of IPFS complete"
103
-    fi
95
+	if ! grep -q "Admin user" $COMPLETION_FILE; then
96
+		return
97
+	fi
98
+	ADMIN_USERNAME=$(cat $COMPLETION_FILE | grep "Admin user" | awk -F ':' '{print $2}')
99
+	if [ -d /home/$ADMIN_USERNAME/.ipfs ]; then
100
+		echo $"Backing up IPFS"
101
+		backup_directory_to_friend /home/$ADMIN_USERNAME/.ipfs ipfs
102
+		echo $"Backup of IPFS complete"
103
+	fi
104 104
 }
105 105
 
106 106
 function restore_remote_ipfs {
107
-    if [ -d $SERVER_DIRECTORY/backup/ipfs ]; then
108
-	echo $"Restoring IPFS"
109
-	temp_restore_dir=/root/tempipfs
110
-	function_check restore_directory_from_friend
111
-	restore_directory_from_friend $temp_restore_dir ipfs
112
-	cp -rf $temp_restore_dir/home/$ADMIN_USERNAME/.ipfs/* /home/$ADMIN_USERNAME/.ipfs
113
-	if [ ! "$?" = "0" ]; then
114
-	    function_check set_user_permissions
115
-	    set_user_permissions
116
-	    rm -rf $temp_restore_dir
117
-	    exit 276357
107
+	if [ -d $SERVER_DIRECTORY/backup/ipfs ]; then
108
+		echo $"Restoring IPFS"
109
+		temp_restore_dir=/root/tempipfs
110
+		function_check restore_directory_from_friend
111
+		restore_directory_from_friend $temp_restore_dir ipfs
112
+		cp -rf $temp_restore_dir/home/$ADMIN_USERNAME/.ipfs/* /home/$ADMIN_USERNAME/.ipfs
113
+		if [ ! "$?" = "0" ]; then
114
+			function_check set_user_permissions
115
+			set_user_permissions
116
+			rm -rf $temp_restore_dir
117
+			exit 276357
118
+		fi
119
+		rm -rf $temp_restore_dir
120
+		echo $"Restore of IPFS complete"
118 121
 	fi
119
-	rm -rf $temp_restore_dir
120
-	echo $"Restore of IPFS complete"
121
-    fi
122 122
 }
123 123
 
124 124
 function remove_ipfs {
125
-    if ! grep -Fxq "install_ipfs" $COMPLETION_FILE; then
126
-	return
127
-    fi
128
-    function_check select_go_version
129
-    select_go_version
130
-    systemctl stop ipfs
131
-    systemctl disable ipfs
132
-    systemctl daemon-reload
133
-    rm /etc/systemd/system/ipfs.service
134
-    rm -rf $GOPATH/src/github.com/ipfs
135
-    iptables -D INPUT -p tcp --dport $IPFS_PORT -j ACCEPT
136
-    function_check save_firewall_settings
137
-    save_firewall_settings
138
-    sed -i '/install_ipfs/d' $COMPLETION_FILE
139
-    sed -i '/ipfs /d' $COMPLETION_FILE
140
-    sed -i '/configure_firewall_for_ipfs/d' $COMPLETION_FILE
125
+	if ! grep -Fxq "install_ipfs" $COMPLETION_FILE; then
126
+		return
127
+	fi
128
+	function_check select_go_version
129
+	select_go_version
130
+	systemctl stop ipfs
131
+	systemctl disable ipfs
132
+	systemctl daemon-reload
133
+	rm /etc/systemd/system/ipfs.service
134
+	rm -rf $GOPATH/src/github.com/ipfs
135
+	iptables -D INPUT -p tcp --dport $IPFS_PORT -j ACCEPT
136
+	function_check save_firewall_settings
137
+	save_firewall_settings
138
+	sed -i '/install_ipfs/d' $COMPLETION_FILE
139
+	sed -i '/ipfs /d' $COMPLETION_FILE
140
+	sed -i '/configure_firewall_for_ipfs/d' $COMPLETION_FILE
141 141
 }
142 142
 
143 143
 function configure_firewall_for_ipfs {
144
-    if grep -Fxq "configure_firewall_for_ipfs" $COMPLETION_FILE; then
145
-	return
146
-    fi
147
-    if [[ $ONION_ONLY != "no" ]]; then
148
-	return
149
-    fi
150
-    iptables -A INPUT -p tcp --dport $IPFS_PORT -j ACCEPT
151
-    function_check save_firewall_settings
152
-    save_firewall_settings
153
-
154
-    OPEN_PORTS+=("IPFS     $IPFS_PORT")
155
-    echo 'configure_firewall_for_ipfs' >> $COMPLETION_FILE
144
+	if grep -Fxq "configure_firewall_for_ipfs" $COMPLETION_FILE; then
145
+		return
146
+	fi
147
+	if [[ $ONION_ONLY != "no" ]]; then
148
+		return
149
+	fi
150
+	iptables -A INPUT -p tcp --dport $IPFS_PORT -j ACCEPT
151
+	function_check save_firewall_settings
152
+	save_firewall_settings
153
+
154
+	OPEN_PORTS+=("IPFS     $IPFS_PORT")
155
+	echo 'configure_firewall_for_ipfs' >> $COMPLETION_FILE
156 156
 }
157 157
 
158 158
 function install_ipfs {
159
-    if grep -Fxq "install_ipfs" $COMPLETION_FILE; then
160
-	return
161
-    fi
162
-
163
-    function_check select_go_version
164
-    select_go_version
159
+	if grep -Fxq "install_ipfs" $COMPLETION_FILE; then
160
+		return
161
+	fi
165 162
 
166
-    apt-get -y install golang libpam0g-dev fuse
163
+	function_check select_go_version
164
+	select_go_version
165
+
166
+	apt-get -y install golang libpam0g-dev fuse
167
+
168
+	if [ ! -d /home/git ]; then
169
+		# add a gogs user account
170
+		adduser --disabled-login --gecos 'Gogs' git
171
+
172
+		# install Go
173
+		if ! grep -q "export GOPATH=" ~/.bashrc; then
174
+			echo "export GOPATH=$GOPATH" >> ~/.bashrc
175
+		else
176
+			sed -i "s|export GOPATH=.*|export GOPATH=$GOPATH|g" ~/.bashrc
177
+		fi
178
+		systemctl set-environment GOPATH=$GOPATH
179
+		if ! grep -q "systemctl set-environment GOPATH=" ~/.bashrc; then
180
+			echo "systemctl set-environment GOPATH=$GOPATH" >> ~/.bashrc
181
+		else
182
+			sed -i "s|systemctl set-environment GOPATH=.*|systemctl set-environment GOPATH=$GOPATH|g" ~/.bashrc
183
+		fi
184
+		if [ ! -d $GOPATH ]; then
185
+			mkdir -p $GOPATH
186
+		fi
187
+	fi
167 188
 
168
-    if [ ! -d /home/git ]; then
169
-	# add a gogs user account
170
-	adduser --disabled-login --gecos 'Gogs' git
189
+	IPFS_PATH=$GOPATH/bin
190
+	export PATH="$GOPATH/bin:$PATH:"
191
+	if ! grep -q 'GOPATH/bin' ~/.bashrc; then
192
+		echo 'export PATH="$GOPATH/bin:$PATH:";' >> ~/.bashrc
193
+	else
194
+		sed -i "s|systemctl set-environment GOPATH=.*|systemctl set-environment GOPATH=$GOPATH|g" ~/.bashrc
195
+	fi
171 196
 
172
-	# install Go
173
-	if ! grep -q "export GOPATH=" ~/.bashrc; then
174
-	    echo "export GOPATH=$GOPATH" >> ~/.bashrc
197
+	# set gopath for the user
198
+	if ! grep -q "GOPATH=" /home/$MY_USERNAME/.bashrc; then
199
+		echo "export GOPATH=$GOPATH" >> /home/$MY_USERNAME/.bashrc
200
+		echo 'export PATH="$GOPATH/bin:$PATH:";' >> /home/$MY_USERNAME/.bashrc
175 201
 	else
176
-	    sed -i "s|export GOPATH=.*|export GOPATH=$GOPATH|g" ~/.bashrc
202
+		sed -i "s|export GOPATH=.*|export GOPATH=$GOPATH|g" /home/$MY_USERNAME/.bashrc
203
+	fi
204
+	chown $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/.bashrc
205
+
206
+	IPFS_GO_REPO2=$(echo "$IPFS_GO_REPO" | sed 's|https://||g')
207
+	go get -u ${IPFS_GO_REPO2}/cmd/ipfs
208
+	if [ ! "$?" = "0" ]; then
209
+		exit 8242
177 210
 	fi
178
-	systemctl set-environment GOPATH=$GOPATH
179
-	if ! grep -q "systemctl set-environment GOPATH=" ~/.bashrc; then
180
-	    echo "systemctl set-environment GOPATH=$GOPATH" >> ~/.bashrc
211
+
212
+	cd $GOPATH/src/$IPFS_GO_REPO2
213
+	git checkout $IPFS_COMMIT -b $IPFS_COMMIT
214
+	if ! grep -q "ipfs commit" $COMPLETION_FILE; then
215
+		echo "ipfs commit:$IPFS_COMMIT" >> $COMPLETION_FILE
181 216
 	else
182
-	    sed -i "s|systemctl set-environment GOPATH=.*|systemctl set-environment GOPATH=$GOPATH|g" ~/.bashrc
217
+		sed -i "s/ipfs commit.*/ipfs commit:$IPFS_COMMIT/g" $COMPLETION_FILE
218
+	fi
219
+
220
+	# initialise
221
+	su -c "$IPFS_PATH/ipfs init -b 4096" - $MY_USERNAME
222
+	if [ ! -d /home/$MY_USERNAME/.ipfs ]; then
223
+		echo "IPFS could not be initialised for user $MY_USERNAME"
224
+		exit 7358
183 225
 	fi
184
-	if [ ! -d $GOPATH ]; then
185
-	    mkdir -p $GOPATH
226
+
227
+	# directories to mount to
228
+	if [ ! -d /ipfs ]; then
229
+		mkdir /ipfs
230
+		mkdir /ipns
231
+		chown $MY_USERNAME:$MY_USERNAME /ipfs
232
+		chown $MY_USERNAME:$MY_USERNAME /ipns
233
+	fi
234
+
235
+	if [ -f /etc/fuse.conf ]; then
236
+		chown $MY_USERNAME:$MY_USERNAME /etc/fuse.conf
186 237
 	fi
187
-    fi
188
-
189
-    IPFS_PATH=$GOPATH/bin
190
-    export PATH="$GOPATH/bin:$PATH:"
191
-    if ! grep -q 'GOPATH/bin' ~/.bashrc; then
192
-	echo 'export PATH="$GOPATH/bin:$PATH:";' >> ~/.bashrc
193
-    else
194
-	sed -i "s|systemctl set-environment GOPATH=.*|systemctl set-environment GOPATH=$GOPATH|g" ~/.bashrc
195
-    fi
196
-
197
-    # set gopath for the user
198
-    if ! grep -q "GOPATH=" /home/$MY_USERNAME/.bashrc; then
199
-	echo "export GOPATH=$GOPATH" >> /home/$MY_USERNAME/.bashrc
200
-	echo 'export PATH="$GOPATH/bin:$PATH:";' >> /home/$MY_USERNAME/.bashrc
201
-    else
202
-	sed -i "s|export GOPATH=.*|export GOPATH=$GOPATH|g" /home/$MY_USERNAME/.bashrc
203
-    fi
204
-    chown $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/.bashrc
205
-
206
-    IPFS_GO_REPO2=$(echo "$IPFS_GO_REPO" | sed 's|https://||g')
207
-    go get -u ${IPFS_GO_REPO2}/cmd/ipfs
208
-    if [ ! "$?" = "0" ]; then
209
-	exit 8242
210
-    fi
211
-
212
-    cd $GOPATH/src/$IPFS_GO_REPO2
213
-    git checkout $IPFS_COMMIT -b $IPFS_COMMIT
214
-    if ! grep -q "ipfs commit" $COMPLETION_FILE; then
215
-	echo "ipfs commit:$IPFS_COMMIT" >> $COMPLETION_FILE
216
-    else
217
-	sed -i "s/ipfs commit.*/ipfs commit:$IPFS_COMMIT/g" $COMPLETION_FILE
218
-    fi
219
-
220
-    # initialise
221
-    su -c "$IPFS_PATH/ipfs init -b 4096" - $MY_USERNAME
222
-    if [ ! -d /home/$MY_USERNAME/.ipfs ]; then
223
-	echo "IPFS could not be initialised for user $MY_USERNAME"
224
-	exit 7358
225
-    fi
226
-
227
-    # directories to mount to
228
-    if [ ! -d /ipfs ]; then
229
-	mkdir /ipfs
230
-	mkdir /ipns
231
-	chown $MY_USERNAME:$MY_USERNAME /ipfs
232
-	chown $MY_USERNAME:$MY_USERNAME /ipns
233
-    fi
234
-
235
-    if [ -f /etc/fuse.conf ]; then
236
-	chown $MY_USERNAME:$MY_USERNAME /etc/fuse.conf
237
-    fi
238
-    if [ -f /dev/fuse ]; then
239
-	chown $MY_USERNAME:$MY_USERNAME /dev/fuse
240
-    fi
241
-
242
-    echo '[Unit]' > /etc/systemd/system/ipfs.service
243
-    echo 'Description=IPFS daemon' >> /etc/systemd/system/ipfs.service
244
-    echo 'After=syslog.target' >> /etc/systemd/system/ipfs.service
245
-    echo 'After=network.target' >> /etc/systemd/system/ipfs.service
246
-    echo '' >> /etc/systemd/system/ipfs.service
247
-    echo '[Service]' >> /etc/systemd/system/ipfs.service
248
-    echo 'Type=simple' >> /etc/systemd/system/ipfs.service
249
-    echo "User=$MY_USERNAME" >> /etc/systemd/system/ipfs.service
250
-    echo "Group=$MY_USERNAME" >> /etc/systemd/system/ipfs.service
251
-    echo "WorkingDirectory=/home/$MY_USERNAME" >> /etc/systemd/system/ipfs.service
252
-    echo "ExecStart=$IPFS_PATH/ipfs daemon --mount" >> /etc/systemd/system/ipfs.service
253
-    echo 'Restart=on-failure' >> /etc/systemd/system/ipfs.service
254
-    echo "Environment=\"USER=$MY_USERNAME\" \"HOME=/home/$MY_USERNAME\" \"GOPATH=$GOPATH\" \"GVM_ROOT=$GVM_HOME\"" >> /etc/systemd/system/ipfs.service
255
-    echo '' >> /etc/systemd/system/ipfs.service
256
-    echo '[Install]' >> /etc/systemd/system/ipfs.service
257
-    echo 'WantedBy=multi-user.target' >> /etc/systemd/system/ipfs.service
258
-
259
-    systemctl enable ipfs
260
-    systemctl daemon-reload
261
-    systemctl restart ipfs
262
-
263
-    if [ -d /etc/avahi ]; then
264
-	su -c "echo $($IPFS_PATH/ipfs id | grep '\"ID\":' | awk -F '\"' '{print $4}') > /tmp/ipfsid" - $MY_USERNAME
265
-	if [ ! -f /tmp/ipfsid ]; then
266
-	    echo 'No IPFS identity was created'
267
-	    exit 37895
238
+	if [ -f /dev/fuse ]; then
239
+		chown $MY_USERNAME:$MY_USERNAME /dev/fuse
268 240
 	fi
269
-	IPFS_PEER_ID=$(cat /tmp/ipfsid)
270
-	if [ ${#IPFS_PEER_ID} -lt 10 ]; then
271
-	    echo 'Invalid IPFS peer ID'
272
-	    echo "$IPFS_PEER_ID"
273
-	    exit 74782
241
+
242
+	echo '[Unit]' > /etc/systemd/system/ipfs.service
243
+	echo 'Description=IPFS daemon' >> /etc/systemd/system/ipfs.service
244
+	echo 'After=syslog.target' >> /etc/systemd/system/ipfs.service
245
+	echo 'After=network.target' >> /etc/systemd/system/ipfs.service
246
+	echo '' >> /etc/systemd/system/ipfs.service
247
+	echo '[Service]' >> /etc/systemd/system/ipfs.service
248
+	echo 'Type=simple' >> /etc/systemd/system/ipfs.service
249
+	echo "User=$MY_USERNAME" >> /etc/systemd/system/ipfs.service
250
+	echo "Group=$MY_USERNAME" >> /etc/systemd/system/ipfs.service
251
+	echo "WorkingDirectory=/home/$MY_USERNAME" >> /etc/systemd/system/ipfs.service
252
+	echo "ExecStart=$IPFS_PATH/ipfs daemon --mount" >> /etc/systemd/system/ipfs.service
253
+	echo 'Restart=on-failure' >> /etc/systemd/system/ipfs.service
254
+	echo "Environment=\"USER=$MY_USERNAME\" \"HOME=/home/$MY_USERNAME\" \"GOPATH=$GOPATH\" \"GVM_ROOT=$GVM_HOME\"" >> /etc/systemd/system/ipfs.service
255
+	echo '' >> /etc/systemd/system/ipfs.service
256
+	echo '[Install]' >> /etc/systemd/system/ipfs.service
257
+	echo 'WantedBy=multi-user.target' >> /etc/systemd/system/ipfs.service
258
+
259
+	systemctl enable ipfs
260
+	systemctl daemon-reload
261
+	systemctl restart ipfs
262
+
263
+	if [ -d /etc/avahi ]; then
264
+		su -c "echo $($IPFS_PATH/ipfs id | grep '\"ID\":' | awk -F '\"' '{print $4}') > /tmp/ipfsid" - $MY_USERNAME
265
+		if [ ! -f /tmp/ipfsid ]; then
266
+			echo 'No IPFS identity was created'
267
+			exit 37895
268
+		fi
269
+		IPFS_PEER_ID=$(cat /tmp/ipfsid)
270
+		if [ ${#IPFS_PEER_ID} -lt 10 ]; then
271
+			echo 'Invalid IPFS peer ID'
272
+			echo "$IPFS_PEER_ID"
273
+			exit 74782
274
+		fi
275
+		# Add an avahi service
276
+		function_check create_avahi_service
277
+		create_avahi_service ipfs "ipfs" udp $IPFS_PORT "$IPFS_PEER_ID"
278
+		rm /tmp/ipfsid
274 279
 	fi
275
-	# Add an avahi service
276
-	function_check create_avahi_service
277
-	create_avahi_service ipfs "ipfs" udp $IPFS_PORT "$IPFS_PEER_ID"
278
-	rm /tmp/ipfsid
279
-    fi
280 280
 
281
-    function_check configure_firewall_for_ipfs
282
-    configure_firewall_for_ipfs
281
+	function_check configure_firewall_for_ipfs
282
+	configure_firewall_for_ipfs
283 283
 
284
-    echo 'install_ipfs' >> $COMPLETION_FILE
284
+	echo 'install_ipfs' >> $COMPLETION_FILE
285 285
 }

+ 224
- 224
src/freedombone-app-irc Parādīt failu

@@ -37,276 +37,276 @@ IRC_ONION_PORT=6697
37 37
 IRC_PASSWORD=
38 38
 
39 39
 function reconfigure_irc {
40
-    echo -n ''
40
+	echo -n ''
41 41
 }
42 42
 
43 43
 function upgrade_irc {
44
-    echo -n ''
44
+	echo -n ''
45 45
 }
46 46
 
47 47
 function backup_local_irc {
48
-    echo -n ''
48
+	echo -n ''
49 49
 }
50 50
 
51 51
 function restore_local_irc {
52
-    echo -n ''
52
+	echo -n ''
53 53
 }
54 54
 
55 55
 function backup_remote_irc {
56
-    echo -n ''
56
+	echo -n ''
57 57
 }
58 58
 
59 59
 function restore_remote_irc {
60
-    echo -n ''
60
+	echo -n ''
61 61
 }
62 62
 
63 63
 function remove_irc {
64
-    if ! grep -Fxq "install_irc" $COMPLETION_FILE; then
65
-	return
66
-    fi
67
-    systemctl stop ngircd
68
-    apt-get -y remove --purge ngircd
69
-    apt-get -y remove --purge irssi
70
-    if [ -d /etc/ngircd ]; then
71
-	rm -rf /etc/ngircd
72
-    fi
73
-    iptables -D INPUT -p tcp --dport $IRC_PORT  -j ACCEPT
74
-    iptables -D INPUT -p tcp --dport 1024:65535 --sport $IRC_PORT -j ACCEPT
75
-    function_check save_firewall_settings
76
-    save_firewall_settings
77
-    function_check remove_onion_service
78
-    remove_onion_service irc ${IRC_ONION_PORT}
79
-    sed -i '/install_irc/d' $COMPLETION_FILE
80
-    sed -i '/IRC /d' $COMPLETION_FILE
81
-    sed -i '/configure_firewall_for_irc/d' $COMPLETION_FILE
64
+	if ! grep -Fxq "install_irc" $COMPLETION_FILE; then
65
+		return
66
+	fi
67
+	systemctl stop ngircd
68
+	apt-get -y remove --purge ngircd
69
+	apt-get -y remove --purge irssi
70
+	if [ -d /etc/ngircd ]; then
71
+		rm -rf /etc/ngircd
72
+	fi
73
+	iptables -D INPUT -p tcp --dport $IRC_PORT  -j ACCEPT
74
+	iptables -D INPUT -p tcp --dport 1024:65535 --sport $IRC_PORT -j ACCEPT
75
+	function_check save_firewall_settings
76
+	save_firewall_settings
77
+	function_check remove_onion_service
78
+	remove_onion_service irc ${IRC_ONION_PORT}
79
+	sed -i '/install_irc/d' $COMPLETION_FILE
80
+	sed -i '/IRC /d' $COMPLETION_FILE
81
+	sed -i '/configure_firewall_for_irc/d' $COMPLETION_FILE
82 82
 }
83 83
 
84 84
 function configure_firewall_for_irc {
85
-    if [ ! -d /etc/ngircd ]; then
86
-	return
87
-    fi
88
-    if grep -Fxq "configure_firewall_for_irc" $COMPLETION_FILE; then
89
-	return
90
-    fi
91
-    if [[ $INSTALLED_WITHIN_DOCKER == "yes" ]]; then
92
-	# docker does its own firewalling
93
-	return
94
-    fi
95
-    if [[ $ONION_ONLY != "no" ]]; then
96
-	return
97
-    fi
98
-    iptables -A INPUT -p tcp --dport $IRC_PORT  -j ACCEPT
99
-    iptables -I INPUT -p tcp --dport 1024:65535 --sport $IRC_PORT -j ACCEPT
100
-    function_check save_firewall_settings
101
-    save_firewall_settings
85
+	if [ ! -d /etc/ngircd ]; then
86
+		return
87
+	fi
88
+	if grep -Fxq "configure_firewall_for_irc" $COMPLETION_FILE; then
89
+		return
90
+	fi
91
+	if [[ $INSTALLED_WITHIN_DOCKER == "yes" ]]; then
92
+		# docker does its own firewalling
93
+		return
94
+	fi
95
+	if [[ $ONION_ONLY != "no" ]]; then
96
+		return
97
+	fi
98
+	iptables -A INPUT -p tcp --dport $IRC_PORT  -j ACCEPT
99
+	iptables -I INPUT -p tcp --dport 1024:65535 --sport $IRC_PORT -j ACCEPT
100
+	function_check save_firewall_settings
101
+	save_firewall_settings
102 102
 
103
-    OPEN_PORTS+=("IRC      $IRC_PORT")
104
-    echo 'configure_firewall_for_irc' >> $COMPLETION_FILE
103
+	OPEN_PORTS+=("IRC      $IRC_PORT")
104
+	echo 'configure_firewall_for_irc' >> $COMPLETION_FILE
105 105
 }
106 106
 
107 107
 function install_irc_server {
108
-    if grep -Fxq "install_irc_server" $COMPLETION_FILE; then
109
-	return
110
-    fi
111
-    apt-get -y install ngircd
108
+	if grep -Fxq "install_irc_server" $COMPLETION_FILE; then
109
+		return
110
+	fi
111
+	apt-get -y install ngircd
112 112
 
113
-    if [ ! -d /etc/ngircd ]; then
114
-	echo $"ERROR: ngircd does not appear to have installed. $CHECK_MESSAGE"
115
-	exit 53
116
-    fi
113
+	if [ ! -d /etc/ngircd ]; then
114
+		echo $"ERROR: ngircd does not appear to have installed. $CHECK_MESSAGE"
115
+		exit 53
116
+	fi
117 117
 
118
-    if [ ! -f /etc/ssl/certs/ngircd.dhparam ]; then
119
-	${PROJECT_NAME}-addcert -h ngircd --dhkey $DH_KEYLENGTH
120
-	function_check check_certificates
121
-	check_certificates ngircd
122
-    fi
118
+	if [ ! -f /etc/ssl/certs/ngircd.dhparam ]; then
119
+		${PROJECT_NAME}-addcert -h ngircd --dhkey $DH_KEYLENGTH
120
+		function_check check_certificates
121
+		check_certificates ngircd
122
+	fi
123 123
 
124
-    DEFAULTDOMAIN=$DEFAULT_DOMAIN_NAME
125
-    if [[ $SYSTEM_TYPE == "$VARIANT_MESH" ]]; then
126
-	DEFAULTDOMAIN="${DEFAULT_DOMAIN_NAME}.local"
127
-    fi
124
+	DEFAULTDOMAIN=$DEFAULT_DOMAIN_NAME
125
+	if [[ $SYSTEM_TYPE == "$VARIANT_MESH" ]]; then
126
+		DEFAULTDOMAIN="${DEFAULT_DOMAIN_NAME}.local"
127
+	fi
128 128
 
129
-    # create a login password if needed
130
-    if [ ! $IRC_PASSWORD ]; then
131
-	IRC_PASSWORD="$(create_password ${MINIMUM_PASSWORD_LENGTH})"
132
-    fi
129
+	# create a login password if needed
130
+	if [ ! $IRC_PASSWORD ]; then
131
+		IRC_PASSWORD="$(create_password ${MINIMUM_PASSWORD_LENGTH})"
132
+	fi
133 133
 
134
-    echo '**************************************************' > /etc/ngircd/motd
135
-    echo $'*           F R E E D O M B O N E   I R C        *' >> /etc/ngircd/motd
136
-    echo '*                                                *' >> /etc/ngircd/motd
137
-    echo $'*               Freedom in the Cloud             *' >> /etc/ngircd/motd
138
-    echo '**************************************************' >> /etc/ngircd/motd
139
-    sed -i 's|MotdFile = /etc/ngircd/ngircd.motd|MotdFile = /etc/ngircd/motd|g' /etc/ngircd/ngircd.conf
140
-    sed -i "s/irc@irc.example.com/$MY_EMAIL_ADDRESS/g" /etc/ngircd/ngircd.conf
141
-    sed -i "s/irc.example.net/$DEFAULTDOMAIN/g" /etc/ngircd/ngircd.conf
142
-    sed -i "s|Yet another IRC Server running on Debian GNU/Linux|IRC Server of $DEFAULTDOMAIN|g" /etc/ngircd/ngircd.conf
143
-    sed -i 's/;Password = wealllikedebian/Password =/g' /etc/ngircd/ngircd.conf
144
-    sed -i 's|;CertFile = /etc/ssl/certs/server.crt|CertFile = /etc/ssl/certs/ngircd.crt|g' /etc/ngircd/ngircd.conf
145
-    sed -i 's|;DHFile = /etc/ngircd/dhparams.pem|DHFile = /etc/ssl/certs/ngircd.dhparam|g' /etc/ngircd/ngircd.conf
146
-    sed -i 's|;KeyFile = /etc/ssl/private/server.key|KeyFile = /etc/ssl/private/ngircd.key|g' /etc/ngircd/ngircd.conf
147
-    sed -i "s/;Ports =.*/Ports = $IRC_PORT/1" /etc/ngircd/ngircd.conf
148
-    sed -i "s/;Ports =.*/Ports = $IRC_PORT/2" /etc/ngircd/ngircd.conf
149
-    sed -i "s/;Name = #ngircd/Name = #${PROJECT_NAME}/g" /etc/ngircd/ngircd.conf
150
-    sed -i "s/;Topic = Our ngircd testing channel/Topic = ${PROJECT_NAME} chat channel/g" /etc/ngircd/ngircd.conf
151
-    sed -i 's/;MaxUsers = 23/MaxUsers = 23/g' /etc/ngircd/ngircd.conf
152
-    sed -i "s|;KeyFile = /etc/ngircd/#chan.key|KeyFile = /etc/ngircd/#${PROJECT_NAME}.key|g" /etc/ngircd/ngircd.conf
153
-    sed -i "s/;CloakHost = cloaked.host/CloakHost = ${PROJECT_NAME}/g" /etc/ngircd/ngircd.conf
154
-    IRC_SALT="$(create_password 30)"
155
-    if [ -f $IMAGE_PASSWORD_FILE ]; then
156
-	IRC_OPERATOR_PASSWORD="$(printf `cat $IMAGE_PASSWORD_FILE`)"
157
-    else
158
-	IRC_OPERATOR_PASSWORD="$(create_password ${MINIMUM_PASSWORD_LENGTH})"
159
-    fi
160
-    sed -i "s|;CloakHostSalt = abcdefghijklmnopqrstuvwxyz|CloakHostSalt = $IRC_SALT|g" /etc/ngircd/ngircd.conf
161
-    sed -i 's/;ConnectIPv4 = yes/ConnectIPv4 = yes/g' /etc/ngircd/ngircd.conf
162
-    sed -i 's/;MorePrivacy = no/MorePrivacy = yes/g' /etc/ngircd/ngircd.conf
163
-    sed -i 's/;RequireAuthPing = no/RequireAuthPing = no/g' /etc/ngircd/ngircd.conf
164
-    sed -i "s/;Name = TheOper/Name = $MY_USERNAME/g" /etc/ngircd/ngircd.conf
165
-    sed -i "s/;Password = ThePwd/Password = $IRC_OPERATOR_PASSWORD/g" /etc/ngircd/ngircd.conf
166
-    sed -i 's|;Listen =.*|Listen = 0.0.0.0,0.0.0.0:9050,127.0.0.1,127.0.0.1:9050|g' /etc/ngircd/ngircd.conf
167
-    if [ $IRC_PASSWORD ]; then
168
-	sed -i "0,/RE/s/Password =.*/Password =$IRC_PASSWORD/" /etc/ngircd/ngircd.conf
169
-    fi
170
-    # If we are on a mesh then DNS is not available
171
-    if [[ $SYSTEM_TYPE == "$VARIANT_MESH" ]]; then
172
-	sed -i "s/;DNS =.*/DNS = no/g" /etc/ngircd/ngircd.conf
173
-    fi
174
-    # upgrade a cypher
175
-    sed -i 's|SECURE128|SECURE256|g' /etc/ngircd/ngircd.conf
176
-    mkdir /var/run/ircd
177
-    chown -R irc:irc /var/run/ircd
178
-    mkdir /var/run/ngircd
179
-    touch /var/run/ngircd/ngircd.pid
180
-    chown -R irc:irc /var/run/ngircd
134
+	echo '**************************************************' > /etc/ngircd/motd
135
+	echo $'*           F R E E D O M B O N E   I R C        *' >> /etc/ngircd/motd
136
+	echo '*                                                *' >> /etc/ngircd/motd
137
+	echo $'*               Freedom in the Cloud             *' >> /etc/ngircd/motd
138
+	echo '**************************************************' >> /etc/ngircd/motd
139
+	sed -i 's|MotdFile = /etc/ngircd/ngircd.motd|MotdFile = /etc/ngircd/motd|g' /etc/ngircd/ngircd.conf
140
+	sed -i "s/irc@irc.example.com/$MY_EMAIL_ADDRESS/g" /etc/ngircd/ngircd.conf
141
+	sed -i "s/irc.example.net/$DEFAULTDOMAIN/g" /etc/ngircd/ngircd.conf
142
+	sed -i "s|Yet another IRC Server running on Debian GNU/Linux|IRC Server of $DEFAULTDOMAIN|g" /etc/ngircd/ngircd.conf
143
+	sed -i 's/;Password = wealllikedebian/Password =/g' /etc/ngircd/ngircd.conf
144
+	sed -i 's|;CertFile = /etc/ssl/certs/server.crt|CertFile = /etc/ssl/certs/ngircd.crt|g' /etc/ngircd/ngircd.conf
145
+	sed -i 's|;DHFile = /etc/ngircd/dhparams.pem|DHFile = /etc/ssl/certs/ngircd.dhparam|g' /etc/ngircd/ngircd.conf
146
+	sed -i 's|;KeyFile = /etc/ssl/private/server.key|KeyFile = /etc/ssl/private/ngircd.key|g' /etc/ngircd/ngircd.conf
147
+	sed -i "s/;Ports =.*/Ports = $IRC_PORT/1" /etc/ngircd/ngircd.conf
148
+	sed -i "s/;Ports =.*/Ports = $IRC_PORT/2" /etc/ngircd/ngircd.conf
149
+	sed -i "s/;Name = #ngircd/Name = #${PROJECT_NAME}/g" /etc/ngircd/ngircd.conf
150
+	sed -i "s/;Topic = Our ngircd testing channel/Topic = ${PROJECT_NAME} chat channel/g" /etc/ngircd/ngircd.conf
151
+	sed -i 's/;MaxUsers = 23/MaxUsers = 23/g' /etc/ngircd/ngircd.conf
152
+	sed -i "s|;KeyFile = /etc/ngircd/#chan.key|KeyFile = /etc/ngircd/#${PROJECT_NAME}.key|g" /etc/ngircd/ngircd.conf
153
+	sed -i "s/;CloakHost = cloaked.host/CloakHost = ${PROJECT_NAME}/g" /etc/ngircd/ngircd.conf
154
+	IRC_SALT="$(create_password 30)"
155
+	if [ -f $IMAGE_PASSWORD_FILE ]; then
156
+		IRC_OPERATOR_PASSWORD="$(printf `cat $IMAGE_PASSWORD_FILE`)"
157
+	else
158
+		IRC_OPERATOR_PASSWORD="$(create_password ${MINIMUM_PASSWORD_LENGTH})"
159
+	fi
160
+	sed -i "s|;CloakHostSalt = abcdefghijklmnopqrstuvwxyz|CloakHostSalt = $IRC_SALT|g" /etc/ngircd/ngircd.conf
161
+	sed -i 's/;ConnectIPv4 = yes/ConnectIPv4 = yes/g' /etc/ngircd/ngircd.conf
162
+	sed -i 's/;MorePrivacy = no/MorePrivacy = yes/g' /etc/ngircd/ngircd.conf
163
+	sed -i 's/;RequireAuthPing = no/RequireAuthPing = no/g' /etc/ngircd/ngircd.conf
164
+	sed -i "s/;Name = TheOper/Name = $MY_USERNAME/g" /etc/ngircd/ngircd.conf
165
+	sed -i "s/;Password = ThePwd/Password = $IRC_OPERATOR_PASSWORD/g" /etc/ngircd/ngircd.conf
166
+	sed -i 's|;Listen =.*|Listen = 0.0.0.0,0.0.0.0:9050,127.0.0.1,127.0.0.1:9050|g' /etc/ngircd/ngircd.conf
167
+	if [ $IRC_PASSWORD ]; then
168
+		sed -i "0,/RE/s/Password =.*/Password =$IRC_PASSWORD/" /etc/ngircd/ngircd.conf
169
+	fi
170
+	# If we are on a mesh then DNS is not available
171
+	if [[ $SYSTEM_TYPE == "$VARIANT_MESH" ]]; then
172
+		sed -i "s/;DNS =.*/DNS = no/g" /etc/ngircd/ngircd.conf
173
+	fi
174
+	# upgrade a cypher
175
+	sed -i 's|SECURE128|SECURE256|g' /etc/ngircd/ngircd.conf
176
+	mkdir /var/run/ircd
177
+	chown -R irc:irc /var/run/ircd
178
+	mkdir /var/run/ngircd
179
+	touch /var/run/ngircd/ngircd.pid
180
+	chown -R irc:irc /var/run/ngircd
181 181
 
182
-    IRC_ONION_HOSTNAME=$(add_onion_service irc ${IRC_PORT} ${IRC_ONION_PORT})
183
-    if ! grep -q $"IRC onion domain" $COMPLETION_FILE; then
184
-	echo "IRC onion domain:$IRC_ONION_HOSTNAME" >> $COMPLETION_FILE
185
-    fi
182
+	IRC_ONION_HOSTNAME=$(add_onion_service irc ${IRC_PORT} ${IRC_ONION_PORT})
183
+	if ! grep -q $"IRC onion domain" $COMPLETION_FILE; then
184
+		echo "IRC onion domain:$IRC_ONION_HOSTNAME" >> $COMPLETION_FILE
185
+	fi
186 186
 
187
-    systemctl restart ngircd
187
+	systemctl restart ngircd
188 188
 
189
-    # keep the daemon running
190
-    echo '' >> /usr/bin/$WATCHDOG_SCRIPT_NAME
191
-    echo '# keep irc daemon running' >> /usr/bin/$WATCHDOG_SCRIPT_NAME
192
-    echo 'IRC_RUNNING=$(pgrep ngircd > /dev/null && echo Running)' >> /usr/bin/$WATCHDOG_SCRIPT_NAME
193
-    echo 'if [ ! $IRC_RUNNING ]; then' >> /usr/bin/$WATCHDOG_SCRIPT_NAME
194
-    echo '  systemctl start ngircd' >> /usr/bin/$WATCHDOG_SCRIPT_NAME
195
-    echo '  echo -n $CURRENT_DATE >> $LOGFILE' >> /usr/bin/$WATCHDOG_SCRIPT_NAME
196
-    echo '  echo " IRC daemon restarted" >> $LOGFILE' >> /usr/bin/$WATCHDOG_SCRIPT_NAME
197
-    echo 'fi' >> /usr/bin/$WATCHDOG_SCRIPT_NAME
189
+	# keep the daemon running
190
+	echo '' >> /usr/bin/$WATCHDOG_SCRIPT_NAME
191
+	echo '# keep irc daemon running' >> /usr/bin/$WATCHDOG_SCRIPT_NAME
192
+	echo 'IRC_RUNNING=$(pgrep ngircd > /dev/null && echo Running)' >> /usr/bin/$WATCHDOG_SCRIPT_NAME
193
+	echo 'if [ ! $IRC_RUNNING ]; then' >> /usr/bin/$WATCHDOG_SCRIPT_NAME
194
+	echo '  systemctl start ngircd' >> /usr/bin/$WATCHDOG_SCRIPT_NAME
195
+	echo '  echo -n $CURRENT_DATE >> $LOGFILE' >> /usr/bin/$WATCHDOG_SCRIPT_NAME
196
+	echo '  echo " IRC daemon restarted" >> $LOGFILE' >> /usr/bin/$WATCHDOG_SCRIPT_NAME
197
+	echo 'fi' >> /usr/bin/$WATCHDOG_SCRIPT_NAME
198 198
 
199
-    if ! grep -q $"IRC Server" /home/$MY_USERNAME/README; then
200
-	echo '' >> /home/$MY_USERNAME/README
201
-	echo '' >> /home/$MY_USERNAME/README
202
-	echo $'IRC Server' >> /home/$MY_USERNAME/README
203
-	echo '==========' >> /home/$MY_USERNAME/README
204
-	echo $'To connect to your IRC server in irssi:' >> /home/$MY_USERNAME/README
205
-	echo '' >> /home/$MY_USERNAME/README
206
-	if [[ $ONION_ONLY != 'yes' ]]; then
207
-	    echo "  irssi" >> /home/$MY_USERNAME/README
208
-	    echo "  /server add -auto -ssl $DEFAULTDOMAIN $IRC_PORT" >> /home/$MY_USERNAME/README
209
-	    echo "  /connect $DEFAULT_DOMAIN_NAME" >> /home/$MY_USERNAME/README
210
-	else
211
-	    echo "  usetorwith irssi" >> /home/$MY_USERNAME/README
212
-	    echo "  /server add -auto $IRC_ONION_HOSTNAME $IRC_PORT" >> /home/$MY_USERNAME/README
213
-	    echo "  /connect $IRC_ONION_HOSTNAME" >> /home/$MY_USERNAME/README
199
+	if ! grep -q $"IRC Server" /home/$MY_USERNAME/README; then
200
+		echo '' >> /home/$MY_USERNAME/README
201
+		echo '' >> /home/$MY_USERNAME/README
202
+		echo $'IRC Server' >> /home/$MY_USERNAME/README
203
+		echo '==========' >> /home/$MY_USERNAME/README
204
+		echo $'To connect to your IRC server in irssi:' >> /home/$MY_USERNAME/README
205
+		echo '' >> /home/$MY_USERNAME/README
206
+		if [[ $ONION_ONLY != 'yes' ]]; then
207
+			echo "  irssi" >> /home/$MY_USERNAME/README
208
+			echo "  /server add -auto -ssl $DEFAULTDOMAIN $IRC_PORT" >> /home/$MY_USERNAME/README
209
+			echo "  /connect $DEFAULT_DOMAIN_NAME" >> /home/$MY_USERNAME/README
210
+		else
211
+			echo "  usetorwith irssi" >> /home/$MY_USERNAME/README
212
+			echo "  /server add -auto $IRC_ONION_HOSTNAME $IRC_PORT" >> /home/$MY_USERNAME/README
213
+			echo "  /connect $IRC_ONION_HOSTNAME" >> /home/$MY_USERNAME/README
214
+		fi
215
+		echo "  /join #${PROJECT_NAME}" >> /home/$MY_USERNAME/README
216
+		chown $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/README
217
+		chmod 600 /home/$MY_USERNAME/README
214 218
 	fi
215
-	echo "  /join #${PROJECT_NAME}" >> /home/$MY_USERNAME/README
216
-	chown $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/README
217
-	chmod 600 /home/$MY_USERNAME/README
218
-    fi
219 219
 
220
-    function_check configure_firewall_for_irc
221
-    configure_firewall_for_irc
222
-    echo 'install_irc_server' >> $COMPLETION_FILE
220
+	function_check configure_firewall_for_irc
221
+	configure_firewall_for_irc
222
+	echo 'install_irc_server' >> $COMPLETION_FILE
223 223
 }
224 224
 
225 225
 function install_irc_client {
226
-    if grep -Fxq "install_irc_client" $COMPLETION_FILE; then
227
-	return
228
-    fi
229
-    apt-get -y install irssi
226
+	if grep -Fxq "install_irc_client" $COMPLETION_FILE; then
227
+		return
228
+	fi
229
+	apt-get -y install irssi
230 230
 
231
-    if [ ! -d /home/$MY_USERNAME/.irssi ]; then
232
-	mkdir /home/$MY_USERNAME/.irssi
233
-    fi
231
+	if [ ! -d /home/$MY_USERNAME/.irssi ]; then
232
+		mkdir /home/$MY_USERNAME/.irssi
233
+	fi
234 234
 
235
-    echo 'servers = (' > /home/$MY_USERNAME/.irssi/config
236
-    echo '  {' >> /home/$MY_USERNAME/.irssi/config
237
-    echo '    address = "chat.freenode.net";' >> /home/$MY_USERNAME/.irssi/config
238
-    echo '    chatnet = "Freenode";' >> /home/$MY_USERNAME/.irssi/config
239
-    echo '    port = "6667";' >> /home/$MY_USERNAME/.irssi/config
240
-    echo '    autoconnect = "no";' >> /home/$MY_USERNAME/.irssi/config
241
-    echo '  },' >> /home/$MY_USERNAME/.irssi/config
242
-    echo '  {' >> /home/$MY_USERNAME/.irssi/config
243
-    echo '    address = "irc.oftc.net";' >> /home/$MY_USERNAME/.irssi/config
244
-    echo '    chatnet = "OFTC";' >> /home/$MY_USERNAME/.irssi/config
245
-    echo '    port = "6667";' >> /home/$MY_USERNAME/.irssi/config
246
-    echo '    autoconnect = "yes";' >> /home/$MY_USERNAME/.irssi/config
247
-    echo '  },' >> /home/$MY_USERNAME/.irssi/config
248
-    echo '  {' >> /home/$MY_USERNAME/.irssi/config
249
-    echo "    address = \"127.0.0.1\";" >> /home/$MY_USERNAME/.irssi/config
250
-    if [[ $ONION_ONLY == 'no' ]]; then
251
-	echo "    port = \"${IRC_PORT}\";" >> /home/$MY_USERNAME/.irssi/config
252
-	echo '    use_ssl = "yes";' >> /home/$MY_USERNAME/.irssi/config
253
-    else
254
-	IRC_ONION_HOSTNAME=$(cat $COMPLETION_FILE | grep "IRC onion domain" | awk -F ':' '{print $2}')
255
-	echo "    port = \"${IRC_ONION_PORT}\";" >> /home/$MY_USERNAME/.irssi/config
256
-	echo '    use_ssl = "no";' >> /home/$MY_USERNAME/.irssi/config
257
-    fi
258
-    echo '    chatnet = "Freedombone";' >> /home/$MY_USERNAME/.irssi/config
259
-    echo '    ssl_verify = "no";' >> /home/$MY_USERNAME/.irssi/config
260
-    echo '    autoconnect = "yes";' >> /home/$MY_USERNAME/.irssi/config
261
-    if [ $IRC_PASSWORD ]; then
262
-	echo "    password = \"${IRC_PASSWORD}\";" >> /home/$MY_USERNAME/.irssi/config
263
-    fi
264
-    echo '  }' >> /home/$MY_USERNAME/.irssi/config
265
-    echo ');' >> /home/$MY_USERNAME/.irssi/config
266
-    echo '' >> /home/$MY_USERNAME/.irssi/config
267
-    echo 'chatnets = {' >> /home/$MY_USERNAME/.irssi/config
268
-    echo '  Freedombone = {' >> /home/$MY_USERNAME/.irssi/config
269
-    echo '    type = "IRC";' >> /home/$MY_USERNAME/.irssi/config
270
-    echo '    max_kicks = "1";' >> /home/$MY_USERNAME/.irssi/config
271
-    echo '    max_msgs = "4";' >> /home/$MY_USERNAME/.irssi/config
272
-    echo '    max_whois = "1";' >> /home/$MY_USERNAME/.irssi/config
273
-    echo '  };' >> /home/$MY_USERNAME/.irssi/config
274
-    echo '  Freenode = {' >> /home/$MY_USERNAME/.irssi/config
275
-    echo '    type = "IRC";' >> /home/$MY_USERNAME/.irssi/config
276
-    echo '    max_kicks = "1";' >> /home/$MY_USERNAME/.irssi/config
277
-    echo '    max_msgs = "4";' >> /home/$MY_USERNAME/.irssi/config
278
-    echo '    max_whois = "1";' >> /home/$MY_USERNAME/.irssi/config
279
-    echo '  };' >> /home/$MY_USERNAME/.irssi/config
280
-    echo '  OFTC = {' >> /home/$MY_USERNAME/.irssi/config
281
-    echo '    type = "IRC";' >> /home/$MY_USERNAME/.irssi/config
282
-    echo '    max_kicks = "1";' >> /home/$MY_USERNAME/.irssi/config
283
-    echo '    max_msgs = "1";' >> /home/$MY_USERNAME/.irssi/config
284
-    echo '    max_whois = "1";' >> /home/$MY_USERNAME/.irssi/config
285
-    echo '  };' >> /home/$MY_USERNAME/.irssi/config
286
-    echo '};' >> /home/$MY_USERNAME/.irssi/config
287
-    echo '' >> /home/$MY_USERNAME/.irssi/config
288
-    echo 'channels = (' >> /home/$MY_USERNAME/.irssi/config
289
-    echo '  { name = "#freedombone"; chatnet = "Freedombone"; autojoin = "Yes"; },' >> /home/$MY_USERNAME/.irssi/config
290
-    echo ');' >> /home/$MY_USERNAME/.irssi/config
291
-    echo '' >> /home/$MY_USERNAME/.irssi/config
292
-    echo 'settings = {' >> /home/$MY_USERNAME/.irssi/config
293
-    echo "  core = { real_name = \"$MY_NAME\"; user_name = \"$MY_USERNAME\"; nick = \"$MY_USERNAME\"; };" >> /home/$MY_USERNAME/.irssi/config
294
-    echo '  "fe-text" = { actlist_sort = "refnum"; };' >> /home/$MY_USERNAME/.irssi/config
295
-    echo '};' >> /home/$MY_USERNAME/.irssi/config
296
-    echo 'ignores = ( { level = "CTCPS"; } );' >> /home/$MY_USERNAME/.irssi/config
235
+	echo 'servers = (' > /home/$MY_USERNAME/.irssi/config
236
+	echo '  {' >> /home/$MY_USERNAME/.irssi/config
237
+	echo '    address = "chat.freenode.net";' >> /home/$MY_USERNAME/.irssi/config
238
+	echo '    chatnet = "Freenode";' >> /home/$MY_USERNAME/.irssi/config
239
+	echo '    port = "6667";' >> /home/$MY_USERNAME/.irssi/config
240
+	echo '    autoconnect = "no";' >> /home/$MY_USERNAME/.irssi/config
241
+	echo '  },' >> /home/$MY_USERNAME/.irssi/config
242
+	echo '  {' >> /home/$MY_USERNAME/.irssi/config
243
+	echo '    address = "irc.oftc.net";' >> /home/$MY_USERNAME/.irssi/config
244
+	echo '    chatnet = "OFTC";' >> /home/$MY_USERNAME/.irssi/config
245
+	echo '    port = "6667";' >> /home/$MY_USERNAME/.irssi/config
246
+	echo '    autoconnect = "yes";' >> /home/$MY_USERNAME/.irssi/config
247
+	echo '  },' >> /home/$MY_USERNAME/.irssi/config
248
+	echo '  {' >> /home/$MY_USERNAME/.irssi/config
249
+	echo "    address = \"127.0.0.1\";" >> /home/$MY_USERNAME/.irssi/config
250
+	if [[ $ONION_ONLY == 'no' ]]; then
251
+		echo "    port = \"${IRC_PORT}\";" >> /home/$MY_USERNAME/.irssi/config
252
+		echo '    use_ssl = "yes";' >> /home/$MY_USERNAME/.irssi/config
253
+	else
254
+		IRC_ONION_HOSTNAME=$(cat $COMPLETION_FILE | grep "IRC onion domain" | awk -F ':' '{print $2}')
255
+		echo "    port = \"${IRC_ONION_PORT}\";" >> /home/$MY_USERNAME/.irssi/config
256
+		echo '    use_ssl = "no";' >> /home/$MY_USERNAME/.irssi/config
257
+	fi
258
+	echo '    chatnet = "Freedombone";' >> /home/$MY_USERNAME/.irssi/config
259
+	echo '    ssl_verify = "no";' >> /home/$MY_USERNAME/.irssi/config
260
+	echo '    autoconnect = "yes";' >> /home/$MY_USERNAME/.irssi/config
261
+	if [ $IRC_PASSWORD ]; then
262
+		echo "    password = \"${IRC_PASSWORD}\";" >> /home/$MY_USERNAME/.irssi/config
263
+	fi
264
+	echo '  }' >> /home/$MY_USERNAME/.irssi/config
265
+	echo ');' >> /home/$MY_USERNAME/.irssi/config
266
+	echo '' >> /home/$MY_USERNAME/.irssi/config
267
+	echo 'chatnets = {' >> /home/$MY_USERNAME/.irssi/config
268
+	echo '  Freedombone = {' >> /home/$MY_USERNAME/.irssi/config
269
+	echo '    type = "IRC";' >> /home/$MY_USERNAME/.irssi/config
270
+	echo '    max_kicks = "1";' >> /home/$MY_USERNAME/.irssi/config
271
+	echo '    max_msgs = "4";' >> /home/$MY_USERNAME/.irssi/config
272
+	echo '    max_whois = "1";' >> /home/$MY_USERNAME/.irssi/config
273
+	echo '  };' >> /home/$MY_USERNAME/.irssi/config
274
+	echo '  Freenode = {' >> /home/$MY_USERNAME/.irssi/config
275
+	echo '    type = "IRC";' >> /home/$MY_USERNAME/.irssi/config
276
+	echo '    max_kicks = "1";' >> /home/$MY_USERNAME/.irssi/config
277
+	echo '    max_msgs = "4";' >> /home/$MY_USERNAME/.irssi/config
278
+	echo '    max_whois = "1";' >> /home/$MY_USERNAME/.irssi/config
279
+	echo '  };' >> /home/$MY_USERNAME/.irssi/config
280
+	echo '  OFTC = {' >> /home/$MY_USERNAME/.irssi/config
281
+	echo '    type = "IRC";' >> /home/$MY_USERNAME/.irssi/config
282
+	echo '    max_kicks = "1";' >> /home/$MY_USERNAME/.irssi/config
283
+	echo '    max_msgs = "1";' >> /home/$MY_USERNAME/.irssi/config
284
+	echo '    max_whois = "1";' >> /home/$MY_USERNAME/.irssi/config
285
+	echo '  };' >> /home/$MY_USERNAME/.irssi/config
286
+	echo '};' >> /home/$MY_USERNAME/.irssi/config
287
+	echo '' >> /home/$MY_USERNAME/.irssi/config
288
+	echo 'channels = (' >> /home/$MY_USERNAME/.irssi/config
289
+	echo '  { name = "#freedombone"; chatnet = "Freedombone"; autojoin = "Yes"; },' >> /home/$MY_USERNAME/.irssi/config
290
+	echo ');' >> /home/$MY_USERNAME/.irssi/config
291
+	echo '' >> /home/$MY_USERNAME/.irssi/config
292
+	echo 'settings = {' >> /home/$MY_USERNAME/.irssi/config
293
+	echo "  core = { real_name = \"$MY_NAME\"; user_name = \"$MY_USERNAME\"; nick = \"$MY_USERNAME\"; };" >> /home/$MY_USERNAME/.irssi/config
294
+	echo '  "fe-text" = { actlist_sort = "refnum"; };' >> /home/$MY_USERNAME/.irssi/config
295
+	echo '};' >> /home/$MY_USERNAME/.irssi/config
296
+	echo 'ignores = ( { level = "CTCPS"; } );' >> /home/$MY_USERNAME/.irssi/config
297 297
 
298
-    chown -R $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/.irssi
298
+	chown -R $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/.irssi
299 299
 
300
-    echo 'install_irc_client' >> $COMPLETION_FILE
300
+	echo 'install_irc_client' >> $COMPLETION_FILE
301 301
 }
302 302
 
303 303
 function install_irc {
304
-    if grep -Fxq "install_irc" $COMPLETION_FILE; then
305
-	return
306
-    fi
307
-    install_irc_server
308
-    install_irc_client
309
-    echo 'install_irc' >> $COMPLETION_FILE
304
+	if grep -Fxq "install_irc" $COMPLETION_FILE; then
305
+		return
306
+	fi
307
+	install_irc_server
308
+	install_irc_client
309
+	echo 'install_irc' >> $COMPLETION_FILE
310 310
 }
311 311
 
312 312
 # NOTE: deliberately no exit 0

+ 293
- 293
src/freedombone-app-mediagoblin Parādīt failu

@@ -38,242 +38,311 @@ MEDIAGOBLIN_ADMIN_PASSWORD=
38 38
 MEDIAGOBLIN_ONION_PORT=8096
39 39
 
40 40
 function reconfigure_mediagoblin {
41
-    echo -n ''
41
+	echo -n ''
42 42
 }
43 43
 
44 44
 function upgrade_mediagoblin {
45
-    echo -n ''
45
+	echo -n ''
46 46
 }
47 47
 
48 48
 function backup_local_mediagoblin {
49
-    echo -n ''
49
+	echo -n ''
50 50
 }
51 51
 
52 52
 function restore_local_mediagoblin {
53
-    echo -n ''
53
+	echo -n ''
54 54
 }
55 55
 
56 56
 function backup_remote_mediagoblin {
57
-    if grep -q "Mediagoblin domain" $COMPLETION_FILE; then
58
-	MEDIAGOBLIN_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "Mediagoblin domain" | awk -F ':' '{print $2}')
59
-	function_check suspend_site
60
-	suspend_site ${MEDIAGOBLIN_DOMAIN_NAME}
57
+	if grep -q "Mediagoblin domain" $COMPLETION_FILE; then
58
+		MEDIAGOBLIN_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "Mediagoblin domain" | awk -F ':' '{print $2}')
59
+		function_check suspend_site
60
+		suspend_site ${MEDIAGOBLIN_DOMAIN_NAME}
61 61
 
62
-	echo $"Backing up Mediagoblin"
62
+		echo $"Backing up Mediagoblin"
63 63
 
64
-	backup_directory_to_friend /var/www/$MEDIAGOBLIN_DOMAIN_NAME/htdocs mediagoblin
64
+		backup_directory_to_friend /var/www/$MEDIAGOBLIN_DOMAIN_NAME/htdocs mediagoblin
65 65
 
66
-	function_check restart_site
67
-	restart_site
66
+		function_check restart_site
67
+		restart_site
68 68
 
69
-	echo $"Backup of Mediagoblin complete"
70
-    fi
69
+		echo $"Backup of Mediagoblin complete"
70
+	fi
71 71
 }
72 72
 
73 73
 function restore_remote_mediagoblin {
74
-    if grep -q "Mediagoblin domain" $COMPLETION_FILE; then
75
-	MEDIAGOBLIN_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "Mediagoblin domain" | awk -F ':' '{print $2}')
76
-	if [ -d $SERVER_DIRECTORY/backup/mediagoblin ]; then
77
-	    echo $"Restoring Mediagoblin installation"
78
-	    temp_restore_dir=/root/tempmediagoblin
79
-	    function_check restore_directory_from_friend
80
-	    restore_directory_from_friend $temp_restore_dir mediagoblin
81
-	    cp -r $temp_restore_dir/* /
82
-	    if [ ! "$?" = "0" ]; then
83
-		exit 5626
84
-	    fi
85
-	    rm -rf $temp_restore_dir
86
-	    echo $"Restore of Mediagoblin complete"
74
+	if grep -q "Mediagoblin domain" $COMPLETION_FILE; then
75
+		MEDIAGOBLIN_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "Mediagoblin domain" | awk -F ':' '{print $2}')
76
+		if [ -d $SERVER_DIRECTORY/backup/mediagoblin ]; then
77
+			echo $"Restoring Mediagoblin installation"
78
+			temp_restore_dir=/root/tempmediagoblin
79
+			function_check restore_directory_from_friend
80
+			restore_directory_from_friend $temp_restore_dir mediagoblin
81
+			cp -r $temp_restore_dir/* /
82
+			if [ ! "$?" = "0" ]; then
83
+				exit 5626
84
+			fi
85
+			rm -rf $temp_restore_dir
86
+			echo $"Restore of Mediagoblin complete"
87
+		fi
88
+		chown -hR mediagoblin:www-data /var/www/$MEDIAGOBLIN_DOMAIN_NAME/htdocs
87 89
 	fi
88
-	chown -hR mediagoblin:www-data /var/www/$MEDIAGOBLIN_DOMAIN_NAME/htdocs
89
-    fi
90 90
 }
91 91
 
92 92
 function remove_mediagoblin {
93
-    echo -n ''
93
+	echo -n ''
94 94
 }
95 95
 
96 96
 function install_mediagoblin {
97
-    if [ ! $MEDIAGOBLIN_DOMAIN_NAME ]; then
98
-	return
99
-    fi
97
+	if [ ! $MEDIAGOBLIN_DOMAIN_NAME ]; then
98
+		return
99
+	fi
100
+
101
+	MEDIAGOBLIN_WORKING_DIRECTORY=/var/www/$MEDIAGOBLIN_DOMAIN_NAME/htdocs
102
+
103
+	# update to a new commit if needed
104
+	function_check set_repo_commit
105
+	set_repo_commit $MEDIAGOBLIN_WORKING_DIRECTORY "Mediagoblin commit" "$MEDIAGOBLIN_COMMIT" $MEDIAGOBLIN_REPO
106
+	if [ -d $MEDIAGOBLIN_WORKING_DIRECTORY ]; then
107
+		chown -hR mediagoblin:www-data $MEDIAGOBLIN_WORKING_DIRECTORY
108
+	fi
109
+
110
+	if grep -Fxq "install_mediagoblin" $COMPLETION_FILE; then
111
+		return
112
+	fi
113
+
114
+	apt-get -y install git-core python python-dev python-lxml python-pil
115
+	apt-get -y install python-virtualenv npm nodejs-legacy automake
116
+	apt-get -y install fcgiwrap
117
+
118
+	#apt-get -y install postgresql postgresql-client python-psycopg2
119
+	#apt-get -y install python-gst-1.0 libjpeg62-turbo-dev gstreamer1.0-plugins-base python-gobject
120
+	#apt-get -y install gstreamer1.0-plugins-good gstreamer1.0-libav libav-tools gstreamer0.10-tools
121
+	#apt-get -y install python-numpy python-scipy libsndfile1-dev python-gst0.10-dev
122
+	#apt-get -y install gstreamer0.10-plugins-base gstreamer0.10-plugins-good gstreamer1.0-tools
123
+	#su -c "createuser -A -D mediagoblin" - postgres
124
+	#su -c "createdb -E UNICODE -O mediagoblin mediagoblin" - postgres
125
+
126
+	useradd -c "GNU MediaGoblin system account" -d /var/lib/mediagoblin -m -r -g www-data mediagoblin
127
+	groupadd mediagoblin
128
+	usermod --append -G mediagoblin mediagoblin
129
+
130
+	if [ ! -d $MEDIAGOBLIN_WORKING_DIRECTORY ]; then
131
+		mkdir -p $MEDIAGOBLIN_WORKING_DIRECTORY
132
+	fi
133
+
134
+	function_check git_clone
135
+	git_clone $MEDIAGOBLIN_REPO $MEDIAGOBLIN_WORKING_DIRECTORY
136
+	cd $MEDIAGOBLIN_WORKING_DIRECTORY
137
+	git checkout $MEDIAGOBLIN_COMMIT -b $MEDIAGOBLIN_COMMIT
138
+	git submodule init
139
+	git submodule update
140
+
141
+	if ! grep -q "Mediagoblin commit" $COMPLETION_FILE; then
142
+		echo "Mediagoblin commit:$MEDIAGOBLIN_COMMIT" >> $COMPLETION_FILE
143
+	else
144
+		sed -i "s/Mediagoblin commit.*/Mediagoblin commit:$MEDIAGOBLIN_COMMIT/g" $COMPLETION_FILE
145
+	fi
146
+
147
+	chown -hR mediagoblin:www-data $MEDIAGOBLIN_WORKING_DIRECTORY
148
+	su -c "cd $MEDIAGOBLIN_WORKING_DIRECTORY && ./bootstrap.sh" - mediagoblin
149
+	if [ ! "$?" = "0" ]; then
150
+		exit 278826
151
+	fi
152
+
153
+	su -c "cd $MEDIAGOBLIN_WORKING_DIRECTORY && ./configure" - mediagoblin
154
+	if [ ! "$?" = "0" ]; then
155
+		exit 462826
156
+	fi
100 157
 
101
-    MEDIAGOBLIN_WORKING_DIRECTORY=/var/www/$MEDIAGOBLIN_DOMAIN_NAME/htdocs
158
+	su -c "cd $MEDIAGOBLIN_WORKING_DIRECTORY && make" - mediagoblin
159
+	if [ ! "$?" = "0" ]; then
160
+		exit 738229
161
+	fi
162
+
163
+	if [ ! -d $MEDIAGOBLIN_WORKING_DIRECTORY/user_dev ]; then
164
+		mkdir $MEDIAGOBLIN_WORKING_DIRECTORY/user_dev
165
+	fi
166
+	chmod 750 $MEDIAGOBLIN_WORKING_DIRECTORY/user_dev
167
+	su -c "cd $MEDIAGOBLIN_WORKING_DIRECTORY && ./bin/easy_install flup==1.0.3.dev-20110405" - mediagoblin
168
+	su -c "cd $MEDIAGOBLIN_WORKING_DIRECTORY && ./bin/easy_install --upgrade billiard" - mediagoblin
169
+	su -c "cd $MEDIAGOBLIN_WORKING_DIRECTORY && ./bin/easy_install --upgrade Paste" - mediagoblin
170
+	su -c "cd $MEDIAGOBLIN_WORKING_DIRECTORY && ./bin/easy_install --upgrade amqp" - mediagoblin
171
+	su -c "cd $MEDIAGOBLIN_WORKING_DIRECTORY && ./bin/easy_install --upgrade anyjson" - mediagoblin
172
+	su -c "cd $MEDIAGOBLIN_WORKING_DIRECTORY && ./bin/easy_install --upgrade py-bcrypt" - mediagoblin
173
+	su -c "cd $MEDIAGOBLIN_WORKING_DIRECTORY && ./bin/easy_install --upgrade wtforms" - mediagoblin
174
+	su -c "cd $MEDIAGOBLIN_WORKING_DIRECTORY && ./bin/easy_install --upgrade python-dateutil" - mediagoblin
175
+	su -c "cd $MEDIAGOBLIN_WORKING_DIRECTORY && ./bin/easy_install --upgrade alembic" - mediagoblin
176
+	su -c "cd $MEDIAGOBLIN_WORKING_DIRECTORY && ./bin/easy_install --upgrade waitress" - mediagoblin
177
+	su -c "cd $MEDIAGOBLIN_WORKING_DIRECTORY && ./bin/easy_install --upgrade imagesize" - mediagoblin
178
+	su -c "cd $MEDIAGOBLIN_WORKING_DIRECTORY && ./bin/easy_install --upgrade alabaster" - mediagoblin
179
+	su -c "cd $MEDIAGOBLIN_WORKING_DIRECTORY && ./bin/easy_install --upgrade snowballstemmer" - mediagoblin
180
+	su -c "cd $MEDIAGOBLIN_WORKING_DIRECTORY && ./bin/easy_install --upgrade docutils" - mediagoblin
181
+	su -c "cd $MEDIAGOBLIN_WORKING_DIRECTORY && ./bin/easy_install --upgrade Pygments" - mediagoblin
182
+	su -c "cd $MEDIAGOBLIN_WORKING_DIRECTORY && ./bin/easy_install --upgrade beautifulsoup4" - mediagoblin
183
+	su -c "cd $MEDIAGOBLIN_WORKING_DIRECTORY && ./bin/easy_install --upgrade WebOb" - mediagoblin
184
+	su -c "cd $MEDIAGOBLIN_WORKING_DIRECTORY && ./bin/easy_install --upgrade py" - mediagoblin
185
+	su -c "cd $MEDIAGOBLIN_WORKING_DIRECTORY && ./bin/easy_install --upgrade execnet" - mediagoblin
186
+
187
+	# create some directories
188
+	mkdir /var/log/mediagoblin
189
+	chown -hR mediagoblin:www-data /var/log/mediagoblin
190
+	mkdir /var/run/mediagoblin
191
+	chown -hR mediagoblin:www-data /var/run/mediagoblin
192
+
193
+	if [ ! -f $MEDIAGOBLIN_WORKING_DIRECTORY/mediagoblin.ini ]; then
194
+		echo $'mediagoblin.ini not found'
195
+		exit 737529
196
+	fi
197
+	if [ ! -f $MEDIAGOBLIN_WORKING_DIRECTORY/paste.ini ]; then
198
+		echo $'paste.ini not found'
199
+		exit 52762
200
+	fi
201
+
202
+	cp -av mediagoblin.ini mediagoblin_local.ini
203
+	cp -av paste.ini paste_local.ini
102 204
 
103
-    # update to a new commit if needed
104
-    function_check set_repo_commit
105
-    set_repo_commit $MEDIAGOBLIN_WORKING_DIRECTORY "Mediagoblin commit" "$MEDIAGOBLIN_COMMIT" $MEDIAGOBLIN_REPO
106
-    if [ -d $MEDIAGOBLIN_WORKING_DIRECTORY ]; then
107 205
 	chown -hR mediagoblin:www-data $MEDIAGOBLIN_WORKING_DIRECTORY
108
-    fi
109
-
110
-    if grep -Fxq "install_mediagoblin" $COMPLETION_FILE; then
111
-	return
112
-    fi
113
-
114
-    apt-get -y install git-core python python-dev python-lxml python-pil
115
-    apt-get -y install python-virtualenv npm nodejs-legacy automake
116
-    apt-get -y install fcgiwrap
117
-
118
-    #apt-get -y install postgresql postgresql-client python-psycopg2
119
-    #apt-get -y install python-gst-1.0 libjpeg62-turbo-dev gstreamer1.0-plugins-base python-gobject
120
-    #apt-get -y install gstreamer1.0-plugins-good gstreamer1.0-libav libav-tools gstreamer0.10-tools
121
-    #apt-get -y install python-numpy python-scipy libsndfile1-dev python-gst0.10-dev
122
-    #apt-get -y install gstreamer0.10-plugins-base gstreamer0.10-plugins-good gstreamer1.0-tools
123
-    #su -c "createuser -A -D mediagoblin" - postgres
124
-    #su -c "createdb -E UNICODE -O mediagoblin mediagoblin" - postgres
125
-
126
-    useradd -c "GNU MediaGoblin system account" -d /var/lib/mediagoblin -m -r -g www-data mediagoblin
127
-    groupadd mediagoblin
128
-    usermod --append -G mediagoblin mediagoblin
129
-
130
-    if [ ! -d $MEDIAGOBLIN_WORKING_DIRECTORY ]; then
131
-	mkdir -p $MEDIAGOBLIN_WORKING_DIRECTORY
132
-    fi
133
-
134
-    function_check git_clone
135
-    git_clone $MEDIAGOBLIN_REPO $MEDIAGOBLIN_WORKING_DIRECTORY
136
-    cd $MEDIAGOBLIN_WORKING_DIRECTORY
137
-    git checkout $MEDIAGOBLIN_COMMIT -b $MEDIAGOBLIN_COMMIT
138
-    git submodule init
139
-    git submodule update
140
-
141
-    if ! grep -q "Mediagoblin commit" $COMPLETION_FILE; then
142
-	echo "Mediagoblin commit:$MEDIAGOBLIN_COMMIT" >> $COMPLETION_FILE
143
-    else
144
-	sed -i "s/Mediagoblin commit.*/Mediagoblin commit:$MEDIAGOBLIN_COMMIT/g" $COMPLETION_FILE
145
-    fi
146
-
147
-    chown -hR mediagoblin:www-data $MEDIAGOBLIN_WORKING_DIRECTORY
148
-    su -c "cd $MEDIAGOBLIN_WORKING_DIRECTORY && ./bootstrap.sh" - mediagoblin
149
-    if [ ! "$?" = "0" ]; then
150
-	exit 278826
151
-    fi
152
-
153
-    su -c "cd $MEDIAGOBLIN_WORKING_DIRECTORY && ./configure" - mediagoblin
154
-    if [ ! "$?" = "0" ]; then
155
-	exit 462826
156
-    fi
157
-
158
-    su -c "cd $MEDIAGOBLIN_WORKING_DIRECTORY && make" - mediagoblin
159
-    if [ ! "$?" = "0" ]; then
160
-	exit 738229
161
-    fi
162
-
163
-    if [ ! -d $MEDIAGOBLIN_WORKING_DIRECTORY/user_dev ]; then
164
-	mkdir $MEDIAGOBLIN_WORKING_DIRECTORY/user_dev
165
-    fi
166
-    chmod 750 $MEDIAGOBLIN_WORKING_DIRECTORY/user_dev
167
-    su -c "cd $MEDIAGOBLIN_WORKING_DIRECTORY && ./bin/easy_install flup==1.0.3.dev-20110405" - mediagoblin
168
-    su -c "cd $MEDIAGOBLIN_WORKING_DIRECTORY && ./bin/easy_install --upgrade billiard" - mediagoblin
169
-    su -c "cd $MEDIAGOBLIN_WORKING_DIRECTORY && ./bin/easy_install --upgrade Paste" - mediagoblin
170
-    su -c "cd $MEDIAGOBLIN_WORKING_DIRECTORY && ./bin/easy_install --upgrade amqp" - mediagoblin
171
-    su -c "cd $MEDIAGOBLIN_WORKING_DIRECTORY && ./bin/easy_install --upgrade anyjson" - mediagoblin
172
-    su -c "cd $MEDIAGOBLIN_WORKING_DIRECTORY && ./bin/easy_install --upgrade py-bcrypt" - mediagoblin
173
-    su -c "cd $MEDIAGOBLIN_WORKING_DIRECTORY && ./bin/easy_install --upgrade wtforms" - mediagoblin
174
-    su -c "cd $MEDIAGOBLIN_WORKING_DIRECTORY && ./bin/easy_install --upgrade python-dateutil" - mediagoblin
175
-    su -c "cd $MEDIAGOBLIN_WORKING_DIRECTORY && ./bin/easy_install --upgrade alembic" - mediagoblin
176
-    su -c "cd $MEDIAGOBLIN_WORKING_DIRECTORY && ./bin/easy_install --upgrade waitress" - mediagoblin
177
-    su -c "cd $MEDIAGOBLIN_WORKING_DIRECTORY && ./bin/easy_install --upgrade imagesize" - mediagoblin
178
-    su -c "cd $MEDIAGOBLIN_WORKING_DIRECTORY && ./bin/easy_install --upgrade alabaster" - mediagoblin
179
-    su -c "cd $MEDIAGOBLIN_WORKING_DIRECTORY && ./bin/easy_install --upgrade snowballstemmer" - mediagoblin
180
-    su -c "cd $MEDIAGOBLIN_WORKING_DIRECTORY && ./bin/easy_install --upgrade docutils" - mediagoblin
181
-    su -c "cd $MEDIAGOBLIN_WORKING_DIRECTORY && ./bin/easy_install --upgrade Pygments" - mediagoblin
182
-    su -c "cd $MEDIAGOBLIN_WORKING_DIRECTORY && ./bin/easy_install --upgrade beautifulsoup4" - mediagoblin
183
-    su -c "cd $MEDIAGOBLIN_WORKING_DIRECTORY && ./bin/easy_install --upgrade WebOb" - mediagoblin
184
-    su -c "cd $MEDIAGOBLIN_WORKING_DIRECTORY && ./bin/easy_install --upgrade py" - mediagoblin
185
-    su -c "cd $MEDIAGOBLIN_WORKING_DIRECTORY && ./bin/easy_install --upgrade execnet" - mediagoblin
186
-
187
-    # create some directories
188
-    mkdir /var/log/mediagoblin
189
-    chown -hR mediagoblin:www-data /var/log/mediagoblin
190
-    mkdir /var/run/mediagoblin
191
-    chown -hR mediagoblin:www-data /var/run/mediagoblin
192
-
193
-    if [ ! -f $MEDIAGOBLIN_WORKING_DIRECTORY/mediagoblin.ini ]; then
194
-	echo $'mediagoblin.ini not found'
195
-	exit 737529
196
-    fi
197
-    if [ ! -f $MEDIAGOBLIN_WORKING_DIRECTORY/paste.ini ]; then
198
-	echo $'paste.ini not found'
199
-	exit 52762
200
-    fi
201
-
202
-    cp -av mediagoblin.ini mediagoblin_local.ini
203
-    cp -av paste.ini paste_local.ini
204
-
205
-    chown -hR mediagoblin:www-data $MEDIAGOBLIN_WORKING_DIRECTORY
206
-
207
-    # init with systemd
208
-    echo '[Unit]' > /etc/systemd/system/mediagoblin-celeryd.service
209
-    echo 'Description=Mediagoblin Celeryd' >> /etc/systemd/system/mediagoblin-celeryd.service
210
-    echo 'After=syslog.target' >> /etc/systemd/system/mediagoblin-celeryd.service
211
-    echo 'After=network.target' >> /etc/systemd/system/mediagoblin-celeryd.service
212
-    echo '' >> /etc/systemd/system/mediagoblin-celeryd.service
213
-    echo '[Service]' >> /etc/systemd/system/mediagoblin-celeryd.service
214
-    echo 'User=mediagoblin' >> /etc/systemd/system/mediagoblin-celeryd.service
215
-    echo 'Group=mediagoblin' >> /etc/systemd/system/mediagoblin-celeryd.service
216
-    echo 'Type=simple' >> /etc/systemd/system/mediagoblin-celeryd.service
217
-    echo "WorkingDirectory=$MEDIAGOBLIN_WORKING_DIRECTORY" >> /etc/systemd/system/mediagoblin-celeryd.service
218
-    echo "Environment=MEDIAGOBLIN_CONFIG=$MEDIAGOBLIN_WORKING_DIRECTORY/mediagoblin_local.ini \\" >> /etc/systemd/system/mediagoblin-celeryd.service
219
-    echo '    CELERY_CONFIG_MODULE=mediagoblin.init.celery.from_celery' >> /etc/systemd/system/mediagoblin-celeryd.service
220
-    echo "ExecStart=$MEDIAGOBLIN_WORKING_DIRECTORY/bin/celery worker \\" >> /etc/systemd/system/mediagoblin-celeryd.service
221
-    echo '    --logfile=/var/log/mediagoblin/celery.log \' >> /etc/systemd/system/mediagoblin-celeryd.service
222
-    echo '    --loglevel=INFO' >> /etc/systemd/system/mediagoblin-celeryd.service
223
-    echo 'PIDFile=/var/run/mediagoblin/mediagoblin-celeryd.pid' >> /etc/systemd/system/mediagoblin-celeryd.service
224
-    echo '' >> /etc/systemd/system/mediagoblin-celeryd.service
225
-    echo '[Install]' >> /etc/systemd/system/mediagoblin-celeryd.service
226
-    echo 'WantedBy=multi-user.target' >> /etc/systemd/system/mediagoblin-celeryd.service
227
-
228
-    echo '[Unit]' > /etc/systemd/system/mediagoblin-paster.service
229
-    echo 'Description=Mediagoblin' >> /etc/systemd/system/mediagoblin-paster.service
230
-    echo 'After=syslog.target' >> /etc/systemd/system/mediagoblin-paster.service
231
-    echo 'After=network.target' >> /etc/systemd/system/mediagoblin-paster.service
232
-    echo '' >> /etc/systemd/system/mediagoblin-paster.service
233
-    echo '[Service]' >> /etc/systemd/system/mediagoblin-paster.service
234
-    echo 'Type=forking' >> /etc/systemd/system/mediagoblin-paster.service
235
-    echo 'User=mediagoblin' >> /etc/systemd/system/mediagoblin-paster.service
236
-    echo 'Group=mediagoblin' >> /etc/systemd/system/mediagoblin-paster.service
237
-    echo 'Environment=CELERY_ALWAYS_EAGER=false' >> /etc/systemd/system/mediagoblin-paster.service
238
-    echo "WorkingDirectory=$MEDIAGOBLIN_WORKING_DIRECTORY" >> /etc/systemd/system/mediagoblin-paster.service
239
-    echo "ExecStart=$MEDIAGOBLIN_WORKING_DIRECTORY/bin/paster serve \\" >> /etc/systemd/system/mediagoblin-paster.service
240
-    echo "    $MEDIAGOBLIN_WORKING_DIRECTORY/paste_local.ini \\" >> /etc/systemd/system/mediagoblin-paster.service
241
-    echo '    --pid-file=/var/run/mediagoblin/mediagoblin.pid \' >> /etc/systemd/system/mediagoblin-paster.service
242
-    echo '    --log-file=/var/log/mediagoblin/mediagoblin.log \' >> /etc/systemd/system/mediagoblin-paster.service
243
-    echo '    --daemon \' >> /etc/systemd/system/mediagoblin-paster.service
244
-    echo '    --server-name=fcgi fcgi_host=127.0.0.1 fcgi_port=26543' >> /etc/systemd/system/mediagoblin-paster.service
245
-    echo "ExecStop=$MEDIAGOBLIN_WORKING_DIRECTORY/bin/paster serve \\" >> /etc/systemd/system/mediagoblin-paster.service
246
-    echo '    --pid-file=/var/run/mediagoblin/mediagoblin.pid \' >> /etc/systemd/system/mediagoblin-paster.service
247
-    echo "    $MEDIAGOBLIN_WORKING_DIRECTORY/paste_local.ini stop" >> /etc/systemd/system/mediagoblin-paster.service
248
-    echo 'PIDFile=/var/run/mediagoblin/mediagoblin.pid' >> /etc/systemd/system/mediagoblin-paster.service
249
-    echo '' >> /etc/systemd/system/mediagoblin-paster.service
250
-    echo '[Install]' >> /etc/systemd/system/mediagoblin-paster.service
251
-    echo 'WantedBy=multi-user.target' >> /etc/systemd/system/mediagoblin-paster.service
252
-    systemctl daemon-reload
253
-    systemctl enable mediagoblin-celeryd
254
-    systemctl enable mediagoblin-paster
255
-    systemctl daemon-reload
256
-    systemctl start mediagoblin-celeryd
257
-    systemctl start mediagoblin-paster
258
-
259
-    MEDIAGOBLIN_ONION_HOSTNAME=$(add_onion_service mediagoblin 80 ${MEDIAGOBLIN_ONION_PORT})
260
-    if ! grep -q "Mediagoblin onion domain" $COMPLETION_FILE; then
261
-	echo "Mediagoblin onion domain:${MEDIAGOBLIN_ONION_HOSTNAME}" >> $COMPLETION_FILE
262
-    else
263
-	sed -i "s|Mediagoblin onion domain.*|Mediagoblin onion domain:${MEDIAGOBLIN_ONION_HOSTNAME}|g" $COMPLETION_FILE
264
-    fi
265
-    if [[ $MEDIAGOBLIN_ONION_HOSTNAME == *"not found"* ]]; then
266
-	echo $'Problem creating onion address for mediagoblin'
267
-	exit 672652
268
-    fi
269
-
270
-    # web config
271
-    MEDIAGOBLIN_VIRTUAL_HOST=/etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
272
-    function_check nginx_http_redirect
273
-    nginx_http_redirect $MEDIAGOBLIN_DOMAIN_NAME
274
-    if [[ $ONION_ONLY == 'no' ]]; then
206
+
207
+	# init with systemd
208
+	echo '[Unit]' > /etc/systemd/system/mediagoblin-celeryd.service
209
+	echo 'Description=Mediagoblin Celeryd' >> /etc/systemd/system/mediagoblin-celeryd.service
210
+	echo 'After=syslog.target' >> /etc/systemd/system/mediagoblin-celeryd.service
211
+	echo 'After=network.target' >> /etc/systemd/system/mediagoblin-celeryd.service
212
+	echo '' >> /etc/systemd/system/mediagoblin-celeryd.service
213
+	echo '[Service]' >> /etc/systemd/system/mediagoblin-celeryd.service
214
+	echo 'User=mediagoblin' >> /etc/systemd/system/mediagoblin-celeryd.service
215
+	echo 'Group=mediagoblin' >> /etc/systemd/system/mediagoblin-celeryd.service
216
+	echo 'Type=simple' >> /etc/systemd/system/mediagoblin-celeryd.service
217
+	echo "WorkingDirectory=$MEDIAGOBLIN_WORKING_DIRECTORY" >> /etc/systemd/system/mediagoblin-celeryd.service
218
+	echo "Environment=MEDIAGOBLIN_CONFIG=$MEDIAGOBLIN_WORKING_DIRECTORY/mediagoblin_local.ini \\" >> /etc/systemd/system/mediagoblin-celeryd.service
219
+	echo '    CELERY_CONFIG_MODULE=mediagoblin.init.celery.from_celery' >> /etc/systemd/system/mediagoblin-celeryd.service
220
+	echo "ExecStart=$MEDIAGOBLIN_WORKING_DIRECTORY/bin/celery worker \\" >> /etc/systemd/system/mediagoblin-celeryd.service
221
+	echo '    --logfile=/var/log/mediagoblin/celery.log \' >> /etc/systemd/system/mediagoblin-celeryd.service
222
+	echo '    --loglevel=INFO' >> /etc/systemd/system/mediagoblin-celeryd.service
223
+	echo 'PIDFile=/var/run/mediagoblin/mediagoblin-celeryd.pid' >> /etc/systemd/system/mediagoblin-celeryd.service
224
+	echo '' >> /etc/systemd/system/mediagoblin-celeryd.service
225
+	echo '[Install]' >> /etc/systemd/system/mediagoblin-celeryd.service
226
+	echo 'WantedBy=multi-user.target' >> /etc/systemd/system/mediagoblin-celeryd.service
227
+
228
+	echo '[Unit]' > /etc/systemd/system/mediagoblin-paster.service
229
+	echo 'Description=Mediagoblin' >> /etc/systemd/system/mediagoblin-paster.service
230
+	echo 'After=syslog.target' >> /etc/systemd/system/mediagoblin-paster.service
231
+	echo 'After=network.target' >> /etc/systemd/system/mediagoblin-paster.service
232
+	echo '' >> /etc/systemd/system/mediagoblin-paster.service
233
+	echo '[Service]' >> /etc/systemd/system/mediagoblin-paster.service
234
+	echo 'Type=forking' >> /etc/systemd/system/mediagoblin-paster.service
235
+	echo 'User=mediagoblin' >> /etc/systemd/system/mediagoblin-paster.service
236
+	echo 'Group=mediagoblin' >> /etc/systemd/system/mediagoblin-paster.service
237
+	echo 'Environment=CELERY_ALWAYS_EAGER=false' >> /etc/systemd/system/mediagoblin-paster.service
238
+	echo "WorkingDirectory=$MEDIAGOBLIN_WORKING_DIRECTORY" >> /etc/systemd/system/mediagoblin-paster.service
239
+	echo "ExecStart=$MEDIAGOBLIN_WORKING_DIRECTORY/bin/paster serve \\" >> /etc/systemd/system/mediagoblin-paster.service
240
+	echo "    $MEDIAGOBLIN_WORKING_DIRECTORY/paste_local.ini \\" >> /etc/systemd/system/mediagoblin-paster.service
241
+	echo '    --pid-file=/var/run/mediagoblin/mediagoblin.pid \' >> /etc/systemd/system/mediagoblin-paster.service
242
+	echo '    --log-file=/var/log/mediagoblin/mediagoblin.log \' >> /etc/systemd/system/mediagoblin-paster.service
243
+	echo '    --daemon \' >> /etc/systemd/system/mediagoblin-paster.service
244
+	echo '    --server-name=fcgi fcgi_host=127.0.0.1 fcgi_port=26543' >> /etc/systemd/system/mediagoblin-paster.service
245
+	echo "ExecStop=$MEDIAGOBLIN_WORKING_DIRECTORY/bin/paster serve \\" >> /etc/systemd/system/mediagoblin-paster.service
246
+	echo '    --pid-file=/var/run/mediagoblin/mediagoblin.pid \' >> /etc/systemd/system/mediagoblin-paster.service
247
+	echo "    $MEDIAGOBLIN_WORKING_DIRECTORY/paste_local.ini stop" >> /etc/systemd/system/mediagoblin-paster.service
248
+	echo 'PIDFile=/var/run/mediagoblin/mediagoblin.pid' >> /etc/systemd/system/mediagoblin-paster.service
249
+	echo '' >> /etc/systemd/system/mediagoblin-paster.service
250
+	echo '[Install]' >> /etc/systemd/system/mediagoblin-paster.service
251
+	echo 'WantedBy=multi-user.target' >> /etc/systemd/system/mediagoblin-paster.service
252
+	systemctl daemon-reload
253
+	systemctl enable mediagoblin-celeryd
254
+	systemctl enable mediagoblin-paster
255
+	systemctl daemon-reload
256
+	systemctl start mediagoblin-celeryd
257
+	systemctl start mediagoblin-paster
258
+
259
+	MEDIAGOBLIN_ONION_HOSTNAME=$(add_onion_service mediagoblin 80 ${MEDIAGOBLIN_ONION_PORT})
260
+	if ! grep -q "Mediagoblin onion domain" $COMPLETION_FILE; then
261
+		echo "Mediagoblin onion domain:${MEDIAGOBLIN_ONION_HOSTNAME}" >> $COMPLETION_FILE
262
+	else
263
+		sed -i "s|Mediagoblin onion domain.*|Mediagoblin onion domain:${MEDIAGOBLIN_ONION_HOSTNAME}|g" $COMPLETION_FILE
264
+	fi
265
+	if [[ $MEDIAGOBLIN_ONION_HOSTNAME == *"not found"* ]]; then
266
+		echo $'Problem creating onion address for mediagoblin'
267
+		exit 672652
268
+	fi
269
+
270
+	# web config
271
+	MEDIAGOBLIN_VIRTUAL_HOST=/etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
272
+	function_check nginx_http_redirect
273
+	nginx_http_redirect $MEDIAGOBLIN_DOMAIN_NAME
274
+	if [[ $ONION_ONLY == 'no' ]]; then
275
+		echo 'server {' >> $MEDIAGOBLIN_VIRTUAL_HOST
276
+		echo '  listen 443 ssl;' >> $MEDIAGOBLIN_VIRTUAL_HOST
277
+		echo '  #################################################' >> $MEDIAGOBLIN_VIRTUAL_HOST
278
+		echo '  # Stock useful config options, but ignore them :)' >> $MEDIAGOBLIN_VIRTUAL_HOST
279
+		echo '  #################################################' >> $MEDIAGOBLIN_VIRTUAL_HOST
280
+		echo '  include /etc/nginx/mime.types;' >> $MEDIAGOBLIN_VIRTUAL_HOST
281
+		echo '' >> $MEDIAGOBLIN_VIRTUAL_HOST
282
+		echo '  autoindex off;' >> $MEDIAGOBLIN_VIRTUAL_HOST
283
+		echo '  default_type  application/octet-stream;' >> $MEDIAGOBLIN_VIRTUAL_HOST
284
+		echo '  sendfile on;' >> $MEDIAGOBLIN_VIRTUAL_HOST
285
+		echo '' >> $MEDIAGOBLIN_VIRTUAL_HOST
286
+		function_check nginx_limits
287
+		nginx_limits $MEDIAGOBLIN_DOMAIN_NAME '20m'
288
+		function_check nginx_ssl
289
+		nginx_ssl $MEDIAGOBLIN_DOMAIN_NAME
290
+		function_check nginx_disable_sniffing
291
+		nginx_disable_sniffing $MEDIAGOBLIN_DOMAIN_NAME
292
+		echo '' >> $MEDIAGOBLIN_VIRTUAL_HOST
293
+		echo '  # Gzip' >> $MEDIAGOBLIN_VIRTUAL_HOST
294
+		echo '  gzip on;' >> $MEDIAGOBLIN_VIRTUAL_HOST
295
+		echo '  gzip_min_length 1024;' >> $MEDIAGOBLIN_VIRTUAL_HOST
296
+		echo '  gzip_buffers 4 32k;' >> $MEDIAGOBLIN_VIRTUAL_HOST
297
+		echo '  gzip_types text/plain application/x-javascript text/javascript text/xml text/css;' >> $MEDIAGOBLIN_VIRTUAL_HOST
298
+		echo '' >> $MEDIAGOBLIN_VIRTUAL_HOST
299
+		echo '  #####################################' >> $MEDIAGOBLIN_VIRTUAL_HOST
300
+		echo '  # Mounting MediaGoblin stuff' >> $MEDIAGOBLIN_VIRTUAL_HOST
301
+		echo '  # This is the section you should read' >> $MEDIAGOBLIN_VIRTUAL_HOST
302
+		echo '  #####################################' >> $MEDIAGOBLIN_VIRTUAL_HOST
303
+		echo '' >> $MEDIAGOBLIN_VIRTUAL_HOST
304
+		echo "  server_name $MEDIAGOBLIN_DOMAIN_NAME;" >> $MEDIAGOBLIN_VIRTUAL_HOST
305
+		echo '  access_log /var/log/nginx/mediagoblin.log;' >> $MEDIAGOBLIN_VIRTUAL_HOST
306
+		echo '  error_log /var/log/nginx/mediagoblin.error.log;' >> $MEDIAGOBLIN_VIRTUAL_HOST
307
+		echo '' >> $MEDIAGOBLIN_VIRTUAL_HOST
308
+		echo '  # MediaGoblins stock static files: CSS, JS, etc.' >> $MEDIAGOBLIN_VIRTUAL_HOST
309
+		echo '  location /mgoblin_static/ {' >> $MEDIAGOBLIN_VIRTUAL_HOST
310
+		echo "    alias $MEDIAGOBLIN_WORKING_DIRECTORY/mediagoblin/static/;" >> $MEDIAGOBLIN_VIRTUAL_HOST
311
+		echo '  }' >> $MEDIAGOBLIN_VIRTUAL_HOST
312
+		echo '' >> $MEDIAGOBLIN_VIRTUAL_HOST
313
+		echo '  # Instance specific media:' >> $MEDIAGOBLIN_VIRTUAL_HOST
314
+		echo '  location /mgoblin_media/ {' >> $MEDIAGOBLIN_VIRTUAL_HOST
315
+		echo "    alias $MEDIAGOBLIN_WORKING_DIRECTORY/user_dev/media/public/;" >> $MEDIAGOBLIN_VIRTUAL_HOST
316
+		echo '  }' >> $MEDIAGOBLIN_VIRTUAL_HOST
317
+		echo '' >> $MEDIAGOBLIN_VIRTUAL_HOST
318
+		echo '  # Theme static files (usually symlinked in)' >> $MEDIAGOBLIN_VIRTUAL_HOST
319
+		echo '  location /theme_static/ {' >> $MEDIAGOBLIN_VIRTUAL_HOST
320
+		echo "    alias $MEDIAGOBLIN_WORKING_DIRECTORY/user_dev/theme_static/;" >> $MEDIAGOBLIN_VIRTUAL_HOST
321
+		echo '  }' >> $MEDIAGOBLIN_VIRTUAL_HOST
322
+		echo '' >> $MEDIAGOBLIN_VIRTUAL_HOST
323
+		echo '  # Plugin static files (usually symlinked in)' >> $MEDIAGOBLIN_VIRTUAL_HOST
324
+		echo '  location /plugin_static/ {' >> $MEDIAGOBLIN_VIRTUAL_HOST
325
+		echo "    alias $MEDIAGOBLIN_WORKING_DIRECTORY/user_dev/plugin_static/;" >> $MEDIAGOBLIN_VIRTUAL_HOST
326
+		echo '  }' >> $MEDIAGOBLIN_VIRTUAL_HOST
327
+		echo '' >> $MEDIAGOBLIN_VIRTUAL_HOST
328
+		echo '  # Mounting MediaGoblin itself via FastCGI.' >> $MEDIAGOBLIN_VIRTUAL_HOST
329
+		echo '  location / {' >> $MEDIAGOBLIN_VIRTUAL_HOST
330
+		echo '    fastcgi_pass 127.0.0.1:26543;' >> $MEDIAGOBLIN_VIRTUAL_HOST
331
+		echo '    include /etc/nginx/fastcgi_params;' >> $MEDIAGOBLIN_VIRTUAL_HOST
332
+		echo '' >> $MEDIAGOBLIN_VIRTUAL_HOST
333
+		echo '    # our understanding vs nginxs handling of script_name vs' >> $MEDIAGOBLIN_VIRTUAL_HOST
334
+		echo '      # path_info dont match :)' >> $MEDIAGOBLIN_VIRTUAL_HOST
335
+		echo '    fastcgi_param PATH_INFO $fastcgi_script_name;' >> $MEDIAGOBLIN_VIRTUAL_HOST
336
+		echo '    fastcgi_param SCRIPT_NAME "";' >> $MEDIAGOBLIN_VIRTUAL_HOST
337
+		echo '  }' >> $MEDIAGOBLIN_VIRTUAL_HOST
338
+		echo '}' >> $MEDIAGOBLIN_VIRTUAL_HOST
339
+		echo '' >> $MEDIAGOBLIN_VIRTUAL_HOST
340
+	else
341
+		echo -n '' > $MEDIAGOBLIN_VIRTUAL_HOST
342
+	fi
343
+
275 344
 	echo 'server {' >> $MEDIAGOBLIN_VIRTUAL_HOST
276
-	echo '  listen 443 ssl;' >> $MEDIAGOBLIN_VIRTUAL_HOST
345
+	echo "  listen 127.0.0.1:${MEDIAGOBLIN_ONION_PORT} default_server;" >> $MEDIAGOBLIN_VIRTUAL_HOST
277 346
 	echo '  #################################################' >> $MEDIAGOBLIN_VIRTUAL_HOST
278 347
 	echo '  # Stock useful config options, but ignore them :)' >> $MEDIAGOBLIN_VIRTUAL_HOST
279 348
 	echo '  #################################################' >> $MEDIAGOBLIN_VIRTUAL_HOST
@@ -285,8 +354,6 @@ function install_mediagoblin {
285 354
 	echo '' >> $MEDIAGOBLIN_VIRTUAL_HOST
286 355
 	function_check nginx_limits
287 356
 	nginx_limits $MEDIAGOBLIN_DOMAIN_NAME '20m'
288
-	function_check nginx_ssl
289
-	nginx_ssl $MEDIAGOBLIN_DOMAIN_NAME
290 357
 	function_check nginx_disable_sniffing
291 358
 	nginx_disable_sniffing $MEDIAGOBLIN_DOMAIN_NAME
292 359
 	echo '' >> $MEDIAGOBLIN_VIRTUAL_HOST
@@ -301,7 +368,7 @@ function install_mediagoblin {
301 368
 	echo '  # This is the section you should read' >> $MEDIAGOBLIN_VIRTUAL_HOST
302 369
 	echo '  #####################################' >> $MEDIAGOBLIN_VIRTUAL_HOST
303 370
 	echo '' >> $MEDIAGOBLIN_VIRTUAL_HOST
304
-	echo "  server_name $MEDIAGOBLIN_DOMAIN_NAME;" >> $MEDIAGOBLIN_VIRTUAL_HOST
371
+	echo "  server_name $MEDIAGOBLIN_ONION_HOSTNAME;" >> $MEDIAGOBLIN_VIRTUAL_HOST
305 372
 	echo '  access_log /var/log/nginx/mediagoblin.log;' >> $MEDIAGOBLIN_VIRTUAL_HOST
306 373
 	echo '  error_log /var/log/nginx/mediagoblin.error.log;' >> $MEDIAGOBLIN_VIRTUAL_HOST
307 374
 	echo '' >> $MEDIAGOBLIN_VIRTUAL_HOST
@@ -336,90 +403,23 @@ function install_mediagoblin {
336 403
 	echo '    fastcgi_param SCRIPT_NAME "";' >> $MEDIAGOBLIN_VIRTUAL_HOST
337 404
 	echo '  }' >> $MEDIAGOBLIN_VIRTUAL_HOST
338 405
 	echo '}' >> $MEDIAGOBLIN_VIRTUAL_HOST
339
-	echo '' >> $MEDIAGOBLIN_VIRTUAL_HOST
340
-    else
341
-	echo -n '' > $MEDIAGOBLIN_VIRTUAL_HOST
342
-    fi
343
-
344
-    echo 'server {' >> $MEDIAGOBLIN_VIRTUAL_HOST
345
-    echo "  listen 127.0.0.1:${MEDIAGOBLIN_ONION_PORT} default_server;" >> $MEDIAGOBLIN_VIRTUAL_HOST
346
-    echo '  #################################################' >> $MEDIAGOBLIN_VIRTUAL_HOST
347
-    echo '  # Stock useful config options, but ignore them :)' >> $MEDIAGOBLIN_VIRTUAL_HOST
348
-    echo '  #################################################' >> $MEDIAGOBLIN_VIRTUAL_HOST
349
-    echo '  include /etc/nginx/mime.types;' >> $MEDIAGOBLIN_VIRTUAL_HOST
350
-    echo '' >> $MEDIAGOBLIN_VIRTUAL_HOST
351
-    echo '  autoindex off;' >> $MEDIAGOBLIN_VIRTUAL_HOST
352
-    echo '  default_type  application/octet-stream;' >> $MEDIAGOBLIN_VIRTUAL_HOST
353
-    echo '  sendfile on;' >> $MEDIAGOBLIN_VIRTUAL_HOST
354
-    echo '' >> $MEDIAGOBLIN_VIRTUAL_HOST
355
-    function_check nginx_limits
356
-    nginx_limits $MEDIAGOBLIN_DOMAIN_NAME '20m'
357
-    function_check nginx_disable_sniffing
358
-    nginx_disable_sniffing $MEDIAGOBLIN_DOMAIN_NAME
359
-    echo '' >> $MEDIAGOBLIN_VIRTUAL_HOST
360
-    echo '  # Gzip' >> $MEDIAGOBLIN_VIRTUAL_HOST
361
-    echo '  gzip on;' >> $MEDIAGOBLIN_VIRTUAL_HOST
362
-    echo '  gzip_min_length 1024;' >> $MEDIAGOBLIN_VIRTUAL_HOST
363
-    echo '  gzip_buffers 4 32k;' >> $MEDIAGOBLIN_VIRTUAL_HOST
364
-    echo '  gzip_types text/plain application/x-javascript text/javascript text/xml text/css;' >> $MEDIAGOBLIN_VIRTUAL_HOST
365
-    echo '' >> $MEDIAGOBLIN_VIRTUAL_HOST
366
-    echo '  #####################################' >> $MEDIAGOBLIN_VIRTUAL_HOST
367
-    echo '  # Mounting MediaGoblin stuff' >> $MEDIAGOBLIN_VIRTUAL_HOST
368
-    echo '  # This is the section you should read' >> $MEDIAGOBLIN_VIRTUAL_HOST
369
-    echo '  #####################################' >> $MEDIAGOBLIN_VIRTUAL_HOST
370
-    echo '' >> $MEDIAGOBLIN_VIRTUAL_HOST
371
-    echo "  server_name $MEDIAGOBLIN_ONION_HOSTNAME;" >> $MEDIAGOBLIN_VIRTUAL_HOST
372
-    echo '  access_log /var/log/nginx/mediagoblin.log;' >> $MEDIAGOBLIN_VIRTUAL_HOST
373
-    echo '  error_log /var/log/nginx/mediagoblin.error.log;' >> $MEDIAGOBLIN_VIRTUAL_HOST
374
-    echo '' >> $MEDIAGOBLIN_VIRTUAL_HOST
375
-    echo '  # MediaGoblins stock static files: CSS, JS, etc.' >> $MEDIAGOBLIN_VIRTUAL_HOST
376
-    echo '  location /mgoblin_static/ {' >> $MEDIAGOBLIN_VIRTUAL_HOST
377
-    echo "    alias $MEDIAGOBLIN_WORKING_DIRECTORY/mediagoblin/static/;" >> $MEDIAGOBLIN_VIRTUAL_HOST
378
-    echo '  }' >> $MEDIAGOBLIN_VIRTUAL_HOST
379
-    echo '' >> $MEDIAGOBLIN_VIRTUAL_HOST
380
-    echo '  # Instance specific media:' >> $MEDIAGOBLIN_VIRTUAL_HOST
381
-    echo '  location /mgoblin_media/ {' >> $MEDIAGOBLIN_VIRTUAL_HOST
382
-    echo "    alias $MEDIAGOBLIN_WORKING_DIRECTORY/user_dev/media/public/;" >> $MEDIAGOBLIN_VIRTUAL_HOST
383
-    echo '  }' >> $MEDIAGOBLIN_VIRTUAL_HOST
384
-    echo '' >> $MEDIAGOBLIN_VIRTUAL_HOST
385
-    echo '  # Theme static files (usually symlinked in)' >> $MEDIAGOBLIN_VIRTUAL_HOST
386
-    echo '  location /theme_static/ {' >> $MEDIAGOBLIN_VIRTUAL_HOST
387
-    echo "    alias $MEDIAGOBLIN_WORKING_DIRECTORY/user_dev/theme_static/;" >> $MEDIAGOBLIN_VIRTUAL_HOST
388
-    echo '  }' >> $MEDIAGOBLIN_VIRTUAL_HOST
389
-    echo '' >> $MEDIAGOBLIN_VIRTUAL_HOST
390
-    echo '  # Plugin static files (usually symlinked in)' >> $MEDIAGOBLIN_VIRTUAL_HOST
391
-    echo '  location /plugin_static/ {' >> $MEDIAGOBLIN_VIRTUAL_HOST
392
-    echo "    alias $MEDIAGOBLIN_WORKING_DIRECTORY/user_dev/plugin_static/;" >> $MEDIAGOBLIN_VIRTUAL_HOST
393
-    echo '  }' >> $MEDIAGOBLIN_VIRTUAL_HOST
394
-    echo '' >> $MEDIAGOBLIN_VIRTUAL_HOST
395
-    echo '  # Mounting MediaGoblin itself via FastCGI.' >> $MEDIAGOBLIN_VIRTUAL_HOST
396
-    echo '  location / {' >> $MEDIAGOBLIN_VIRTUAL_HOST
397
-    echo '    fastcgi_pass 127.0.0.1:26543;' >> $MEDIAGOBLIN_VIRTUAL_HOST
398
-    echo '    include /etc/nginx/fastcgi_params;' >> $MEDIAGOBLIN_VIRTUAL_HOST
399
-    echo '' >> $MEDIAGOBLIN_VIRTUAL_HOST
400
-    echo '    # our understanding vs nginxs handling of script_name vs' >> $MEDIAGOBLIN_VIRTUAL_HOST
401
-    echo '      # path_info dont match :)' >> $MEDIAGOBLIN_VIRTUAL_HOST
402
-    echo '    fastcgi_param PATH_INFO $fastcgi_script_name;' >> $MEDIAGOBLIN_VIRTUAL_HOST
403
-    echo '    fastcgi_param SCRIPT_NAME "";' >> $MEDIAGOBLIN_VIRTUAL_HOST
404
-    echo '  }' >> $MEDIAGOBLIN_VIRTUAL_HOST
405
-    echo '}' >> $MEDIAGOBLIN_VIRTUAL_HOST
406
-
407
-    function_check create_site_certificate
408
-    create_site_certificate $MEDIAGOBLIN_DOMAIN_NAME
409
-
410
-    nginx_ensite $MEDIAGOBLIN_DOMAIN_NAME
411
-    systemctl restart php5-fpm
412
-    systemctl restart nginx
413
-
414
-    add_ddns_domain $MEDIAGOBLIN_DOMAIN_NAME
415
-
416
-    if ! grep -q "Mediagoblin domain" $COMPLETION_FILE; then
417
-	echo "Mediagoblin domain:$MEDIAGOBLIN_DOMAIN_NAME" >> $COMPLETION_FILE
418
-    else
419
-	sed -i "s/Mediagoblin domain.*/Mediagoblin domain:$MEDIAGOBLIN_DOMAIN_NAME/g" $COMPLETION_FILE
420
-    fi
421
-
422
-    echo 'install_mediagoblin' >> $COMPLETION_FILE
406
+
407
+	function_check create_site_certificate
408
+	create_site_certificate $MEDIAGOBLIN_DOMAIN_NAME
409
+
410
+	nginx_ensite $MEDIAGOBLIN_DOMAIN_NAME
411
+	systemctl restart php5-fpm
412
+	systemctl restart nginx
413
+
414
+	add_ddns_domain $MEDIAGOBLIN_DOMAIN_NAME
415
+
416
+	if ! grep -q "Mediagoblin domain" $COMPLETION_FILE; then
417
+		echo "Mediagoblin domain:$MEDIAGOBLIN_DOMAIN_NAME" >> $COMPLETION_FILE
418
+	else
419
+		sed -i "s/Mediagoblin domain.*/Mediagoblin domain:$MEDIAGOBLIN_DOMAIN_NAME/g" $COMPLETION_FILE
420
+	fi
421
+
422
+	echo 'install_mediagoblin' >> $COMPLETION_FILE
423 423
 }
424 424
 
425 425
 # NOTE: deliberately no exit 0

+ 203
- 203
src/freedombone-app-mumble Parādīt failu

@@ -40,256 +40,256 @@ VOIP_DATABASE="mumble-server.sqlite"
40 40
 VOIP_CONFIG_FILE="mumble-server.ini"
41 41
 
42 42
 function reconfigure_mumble {
43
-    echo -n ''
43
+	echo -n ''
44 44
 }
45 45
 
46 46
 function upgrade_mumble {
47
-    echo -n ''
47
+	echo -n ''
48 48
 }
49 49
 
50 50
 function backup_local_mumble {
51
-    if [ -f /etc/mumble-server.ini ]; then
52
-	echo $"Backing up Mumble settings"
53
-	temp_backup_dir=/root/tempvoipbackup
54
-	if [ ! -d $temp_backup_dir ]; then
55
-	    mkdir -p $temp_backup_dir
51
+	if [ -f /etc/mumble-server.ini ]; then
52
+		echo $"Backing up Mumble settings"
53
+		temp_backup_dir=/root/tempvoipbackup
54
+		if [ ! -d $temp_backup_dir ]; then
55
+			mkdir -p $temp_backup_dir
56
+		fi
57
+		cp -f /etc/mumble-server.ini $temp_backup_dir
58
+		cp -f /var/lib/mumble-server/mumble-server.sqlite $temp_backup_dir
59
+		backup_directory_to_usb $temp_backup_dir voip
60
+		echo $"Mumble settings backup complete"
56 61
 	fi
57
-	cp -f /etc/mumble-server.ini $temp_backup_dir
58
-	cp -f /var/lib/mumble-server/mumble-server.sqlite $temp_backup_dir
59
-	backup_directory_to_usb $temp_backup_dir voip
60
-	echo $"Mumble settings backup complete"
61
-    fi
62 62
 }
63 63
 
64 64
 function restore_local_mumble {
65
-    if [ -d $USB_MOUNT/backup/voip ]; then
66
-	echo $"Restoring VoIP settings"
67
-	temp_restore_dir=/root/tempvoip
68
-	function_check restore_directory_from_usb
69
-	restore_directory_from_usb $temp_restore_dir voip
70
-	cp -f $temp_restore_dir/home/$ADMIN_USERNAME/tempbackup/mumble-server.ini /etc/
71
-	if [ ! "$?" = "0" ]; then
72
-	    rm -rf $temp_restore_dir
73
-	    function_check set_user_permissions
74
-	    set_user_permissions
75
-	    function_check backup_unmount_drive
76
-	    backup_unmount_drive
77
-	    exit 3679
78
-	fi
79
-	cp -f $temp_restore_dir/home/$ADMIN_USERNAME/tempbackup/mumble-server.sqlite /var/lib/mumble-server/
80
-	if [ ! "$?" = "0" ]; then
81
-	    rm -rf $temp_restore_dir
82
-	    function_check set_user_permissions
83
-	    set_user_permissions
84
-	    function_check backup_unmount_drive
85
-	    backup_unmount_drive
86
-	    exit 276
65
+	if [ -d $USB_MOUNT/backup/voip ]; then
66
+		echo $"Restoring VoIP settings"
67
+		temp_restore_dir=/root/tempvoip
68
+		function_check restore_directory_from_usb
69
+		restore_directory_from_usb $temp_restore_dir voip
70
+		cp -f $temp_restore_dir/home/$ADMIN_USERNAME/tempbackup/mumble-server.ini /etc/
71
+		if [ ! "$?" = "0" ]; then
72
+			rm -rf $temp_restore_dir
73
+			function_check set_user_permissions
74
+			set_user_permissions
75
+			function_check backup_unmount_drive
76
+			backup_unmount_drive
77
+			exit 3679
78
+		fi
79
+		cp -f $temp_restore_dir/home/$ADMIN_USERNAME/tempbackup/mumble-server.sqlite /var/lib/mumble-server/
80
+		if [ ! "$?" = "0" ]; then
81
+			rm -rf $temp_restore_dir
82
+			function_check set_user_permissions
83
+			set_user_permissions
84
+			function_check backup_unmount_drive
85
+			backup_unmount_drive
86
+			exit 276
87
+		fi
88
+		rm -rf $temp_restore_dir
89
+		cp /etc/ssl/certs/mumble* /var/lib/mumble-server
90
+		cp /etc/ssl/private/mumble* /var/lib/mumble-server
91
+		chown -R mumble-server:mumble-server /var/lib/mumble-server
92
+		service mumble-server restart
87 93
 	fi
88
-	rm -rf $temp_restore_dir
89
-	cp /etc/ssl/certs/mumble* /var/lib/mumble-server
90
-	cp /etc/ssl/private/mumble* /var/lib/mumble-server
91
-	chown -R mumble-server:mumble-server /var/lib/mumble-server
92
-	service mumble-server restart
93
-    fi
94 94
 }
95 95
 
96 96
 function backup_remote_mumble {
97
-    if [ -f /etc/mumble-server.ini ]; then
98
-	echo $"Backing up VoIP settings"
99
-	if [ ! -d /root/tempvoipbackup ]; then
100
-	    mkdir -p /root/tempvoipbackup
97
+	if [ -f /etc/mumble-server.ini ]; then
98
+		echo $"Backing up VoIP settings"
99
+		if [ ! -d /root/tempvoipbackup ]; then
100
+			mkdir -p /root/tempvoipbackup
101
+		fi
102
+		cp -f /etc/mumble-server.ini /root/tempvoipbackup
103
+		cp -f /var/lib/mumble-server/mumble-server.sqlite /root/tempvoipbackup
104
+		backup_directory_to_friend /root/tempvoipbackup voip
105
+		echo $"Backup of VoIP settings complete"
101 106
 	fi
102
-	cp -f /etc/mumble-server.ini /root/tempvoipbackup
103
-	cp -f /var/lib/mumble-server/mumble-server.sqlite /root/tempvoipbackup
104
-	backup_directory_to_friend /root/tempvoipbackup voip
105
-	echo $"Backup of VoIP settings complete"
106
-    fi
107 107
 }
108 108
 
109 109
 function restore_remote_mumble {
110
-    if [ -d $SERVER_DIRECTORY/backup/voip ]; then
111
-	echo $"Restoring Mumble settings"
112
-	temp_restore_dir=/root/tempvoip
113
-	function_check restore_directory_from_friend
114
-	restore_directory_from_friend $temp_restore_dir voip
115
-	cp -f $temp_restore_dir/home/$ADMIN_USERNAME/tempbackup/mumble-server.ini /etc/
116
-	if [ ! "$?" = "0" ]; then
117
-	    rm -rf $temp_restore_dir
118
-	    exit 7823
119
-	fi
120
-	cp -f $temp_restore_dir/home/$ADMIN_USERNAME/tempbackup/sipwitch.conf /etc/sipwitch.conf
121
-	if [ ! "$?" = "0" ]; then
122
-	    rm -rf $temp_restore_dir
123
-	    exit 7823
124
-	fi
125
-	cp -f $temp_restore_dir/home/$ADMIN_USERNAME/tempbackup/mumble-server.sqlite /var/lib/mumble-server/
126
-	if [ ! "$?" = "0" ]; then
127
-	    rm -rf $temp_restore_dir
128
-	    exit 276
110
+	if [ -d $SERVER_DIRECTORY/backup/voip ]; then
111
+		echo $"Restoring Mumble settings"
112
+		temp_restore_dir=/root/tempvoip
113
+		function_check restore_directory_from_friend
114
+		restore_directory_from_friend $temp_restore_dir voip
115
+		cp -f $temp_restore_dir/home/$ADMIN_USERNAME/tempbackup/mumble-server.ini /etc/
116
+		if [ ! "$?" = "0" ]; then
117
+			rm -rf $temp_restore_dir
118
+			exit 7823
119
+		fi
120
+		cp -f $temp_restore_dir/home/$ADMIN_USERNAME/tempbackup/sipwitch.conf /etc/sipwitch.conf
121
+		if [ ! "$?" = "0" ]; then
122
+			rm -rf $temp_restore_dir
123
+			exit 7823
124
+		fi
125
+		cp -f $temp_restore_dir/home/$ADMIN_USERNAME/tempbackup/mumble-server.sqlite /var/lib/mumble-server/
126
+		if [ ! "$?" = "0" ]; then
127
+			rm -rf $temp_restore_dir
128
+			exit 276
129
+		fi
130
+		rm -rf $temp_restore_dir
131
+		cp /etc/ssl/certs/mumble* /var/lib/mumble-server
132
+		cp /etc/ssl/private/mumble* /var/lib/mumble-server
133
+		chown -R mumble-server:mumble-server /var/lib/mumble-server
134
+		service mumble-server restart
135
+		echo $"Restore of Mumble complete"
129 136
 	fi
130
-	rm -rf $temp_restore_dir
131
-	cp /etc/ssl/certs/mumble* /var/lib/mumble-server
132
-	cp /etc/ssl/private/mumble* /var/lib/mumble-server
133
-	chown -R mumble-server:mumble-server /var/lib/mumble-server
134
-	service mumble-server restart
135
-	echo $"Restore of Mumble complete"
136
-    fi
137 137
 }
138 138
 
139 139
 function remove_mumble {
140
-    if !grep -Fxq "install_mumble" $COMPLETION_FILE; then
141
-	if ! grep -Fxq "install_voip" $COMPLETION_FILE; then
142
-	    return
140
+	if !grep -Fxq "install_mumble" $COMPLETION_FILE; then
141
+		if ! grep -Fxq "install_voip" $COMPLETION_FILE; then
142
+			return
143
+		fi
143 144
 	fi
144
-    fi
145
-    apt-get -y remove --purge mumble-server
146
-    if [[ $ONION_ONLY == "no" ]]; then
147
-	iptables -D INPUT -p udp --dport $VOIP_PORT -j ACCEPT
148
-	iptables -D INPUT -p tcp --dport $VOIP_PORT -j ACCEPT
149
-	function_check save_firewall_settings
150
-	save_firewall_settings
151
-    fi
152
-    if [ -f /etc/mumble-server.ini ]; then
153
-	rm /etc/mumble-server.ini
154
-    fi
155
-    function_check remove_onion_service
156
-    remove_onion_service voip ${VOIP_PORT}
157
-    sed -i '/install_mumble/d' $COMPLETION_FILE
158
-    sed -i '/install_voip/d' $COMPLETION_FILE
159
-    sed -i '/configure_firewall_for_voip/d' $COMPLETION_FILE
160
-    sed -i '/VoIP /d' $COMPLETION_FILE
145
+	apt-get -y remove --purge mumble-server
146
+	if [[ $ONION_ONLY == "no" ]]; then
147
+		iptables -D INPUT -p udp --dport $VOIP_PORT -j ACCEPT
148
+		iptables -D INPUT -p tcp --dport $VOIP_PORT -j ACCEPT
149
+		function_check save_firewall_settings
150
+		save_firewall_settings
151
+	fi
152
+	if [ -f /etc/mumble-server.ini ]; then
153
+		rm /etc/mumble-server.ini
154
+	fi
155
+	function_check remove_onion_service
156
+	remove_onion_service voip ${VOIP_PORT}
157
+	sed -i '/install_mumble/d' $COMPLETION_FILE
158
+	sed -i '/install_voip/d' $COMPLETION_FILE
159
+	sed -i '/configure_firewall_for_voip/d' $COMPLETION_FILE
160
+	sed -i '/VoIP /d' $COMPLETION_FILE
161 161
 }
162 162
 
163 163
 function get_voip_server_password {
164
-    if [ -f /home/$MY_USERNAME/README ]; then
165
-	if grep -q "VoIP server password" /home/$MY_USERNAME/README; then
166
-	    if [ ! $VOIP_SERVER_PASSWORD ]; then
167
-		VOIP_SERVER_PASSWORD=$(cat /home/$MY_USERNAME/README | grep "VoIP server password" | awk -F ':' '{print $2}' | sed 's/^ *//')
168
-	    fi
169
-	else
170
-	    if grep -q "Mumble server password" /home/$MY_USERNAME/README; then
171
-		if [ ! $VOIP_SERVER_PASSWORD ]; then
172
-		    VOIP_SERVER_PASSWORD=$(cat /home/$MY_USERNAME/README | grep "Mumble server password" | awk -F ':' '{print $2}' | sed 's/^ *//')
164
+	if [ -f /home/$MY_USERNAME/README ]; then
165
+		if grep -q "VoIP server password" /home/$MY_USERNAME/README; then
166
+			if [ ! $VOIP_SERVER_PASSWORD ]; then
167
+				VOIP_SERVER_PASSWORD=$(cat /home/$MY_USERNAME/README | grep "VoIP server password" | awk -F ':' '{print $2}' | sed 's/^ *//')
168
+			fi
169
+		else
170
+			if grep -q "Mumble server password" /home/$MY_USERNAME/README; then
171
+				if [ ! $VOIP_SERVER_PASSWORD ]; then
172
+					VOIP_SERVER_PASSWORD=$(cat /home/$MY_USERNAME/README | grep "Mumble server password" | awk -F ':' '{print $2}' | sed 's/^ *//')
173
+				fi
174
+			fi
173 175
 		fi
174
-	    fi
175 176
 	fi
176
-    fi
177 177
 }
178 178
 
179 179
 function configure_firewall_for_voip {
180
-    if grep -Fxq "configure_firewall_for_voip" $COMPLETION_FILE; then
181
-	return
182
-    fi
183
-    if [[ $ONION_ONLY != "no" ]]; then
184
-	return
185
-    fi
186
-    iptables -A INPUT -p udp --dport $VOIP_PORT -j ACCEPT
187
-    iptables -A INPUT -p tcp --dport $VOIP_PORT -j ACCEPT
188
-    function_check save_firewall_settings
189
-    save_firewall_settings
180
+	if grep -Fxq "configure_firewall_for_voip" $COMPLETION_FILE; then
181
+		return
182
+	fi
183
+	if [[ $ONION_ONLY != "no" ]]; then
184
+		return
185
+	fi
186
+	iptables -A INPUT -p udp --dport $VOIP_PORT -j ACCEPT
187
+	iptables -A INPUT -p tcp --dport $VOIP_PORT -j ACCEPT
188
+	function_check save_firewall_settings
189
+	save_firewall_settings
190 190
 
191
-    OPEN_PORTS+=("Mumble   $VOIP_PORT")
192
-    echo 'configure_firewall_for_voip' >> $COMPLETION_FILE
191
+	OPEN_PORTS+=("Mumble   $VOIP_PORT")
192
+	echo 'configure_firewall_for_voip' >> $COMPLETION_FILE
193 193
 }
194 194
 
195 195
 function install_mumble {
196
-    if grep -Fxq "install_mumble" $COMPLETION_FILE; then
197
-	return
198
-    fi
199
-    if grep -Fxq "install_voip" $COMPLETION_FILE; then
200
-	return
201
-    fi
202
-    apt-get -y install mumble-server
196
+	if grep -Fxq "install_mumble" $COMPLETION_FILE; then
197
+		return
198
+	fi
199
+	if grep -Fxq "install_voip" $COMPLETION_FILE; then
200
+		return
201
+	fi
202
+	apt-get -y install mumble-server
203 203
 
204
-    function_check get_voip_server_password
205
-    get_voip_server_password
206
-    if [ ! $VOIP_SERVER_PASSWORD ]; then
207
-	if [ -f $IMAGE_PASSWORD_FILE ]; then
208
-	    VOIP_SERVER_PASSWORD="$(printf `cat $IMAGE_PASSWORD_FILE`)"
209
-	else
210
-	    VOIP_SERVER_PASSWORD="$(create_password ${MINIMUM_PASSWORD_LENGTH})"
211
-	    if [ ${#VOIP_SERVER_PASSWORD} -lt $MINIMUM_PASSWORD_LENGTH ]; then
212
-		VOIP_SERVER_PASSWORD="$(create_password ${MINIMUM_PASSWORD_LENGTH})"
213
-	    fi
204
+	function_check get_voip_server_password
205
+	get_voip_server_password
206
+	if [ ! $VOIP_SERVER_PASSWORD ]; then
207
+		if [ -f $IMAGE_PASSWORD_FILE ]; then
208
+			VOIP_SERVER_PASSWORD="$(printf `cat $IMAGE_PASSWORD_FILE`)"
209
+		else
210
+			VOIP_SERVER_PASSWORD="$(create_password ${MINIMUM_PASSWORD_LENGTH})"
211
+			if [ ${#VOIP_SERVER_PASSWORD} -lt $MINIMUM_PASSWORD_LENGTH ]; then
212
+				VOIP_SERVER_PASSWORD="$(create_password ${MINIMUM_PASSWORD_LENGTH})"
213
+			fi
214
+		fi
214 215
 	fi
215
-    fi
216 216
 
217
-    # Make an ssl cert for the server
218
-    if [ ! -f /etc/ssl/certs/mumble.dhparam ]; then
219
-	${PROJECT_NAME}-addcert -h mumble --dhkey $DH_KEYLENGTH
220
-	function_check check_certificates
221
-	check_certificates mumble
222
-    fi
217
+	# Make an ssl cert for the server
218
+	if [ ! -f /etc/ssl/certs/mumble.dhparam ]; then
219
+		${PROJECT_NAME}-addcert -h mumble --dhkey $DH_KEYLENGTH
220
+		function_check check_certificates
221
+		check_certificates mumble
222
+	fi
223 223
 
224
-    # Check that the cert was created
225
-    if [ ! -f /etc/ssl/certs/mumble.crt ]; then
226
-	echo $'VoIP server certificate not created'
227
-	exit 57892
228
-    fi
229
-    if [ ! -f /etc/ssl/private/mumble.key ]; then
230
-	echo $'VoIP server key not created'
231
-	exit 57893
232
-    fi
233
-    if [ ! -d /var/lib/mumble-server ]; then
234
-	mkdir /var/lib/mumble-server
235
-    fi
236
-    cp /etc/ssl/certs/mumble.* /var/lib/mumble-server
237
-    cp /etc/ssl/private/mumble.key /var/lib/mumble-server
238
-    chown -R mumble-server:mumble-server /var/lib/mumble-server
224
+	# Check that the cert was created
225
+	if [ ! -f /etc/ssl/certs/mumble.crt ]; then
226
+		echo $'VoIP server certificate not created'
227
+		exit 57892
228
+	fi
229
+	if [ ! -f /etc/ssl/private/mumble.key ]; then
230
+		echo $'VoIP server key not created'
231
+		exit 57893
232
+	fi
233
+	if [ ! -d /var/lib/mumble-server ]; then
234
+		mkdir /var/lib/mumble-server
235
+	fi
236
+	cp /etc/ssl/certs/mumble.* /var/lib/mumble-server
237
+	cp /etc/ssl/private/mumble.key /var/lib/mumble-server
238
+	chown -R mumble-server:mumble-server /var/lib/mumble-server
239 239
 
240
-    sed -i "s|welcometext=.*|welcometext=\"<br />Welcome to $DEFAULT_DOMAIN_NAME <b>VoIP</b>.<br />Chat freely!<br />\"|g" /etc/mumble-server.ini
240
+	sed -i "s|welcometext=.*|welcometext=\"<br />Welcome to $DEFAULT_DOMAIN_NAME <b>VoIP</b>.<br />Chat freely!<br />\"|g" /etc/mumble-server.ini
241 241
 
242
-    if [[ $VOIP_SERVER_PASSWORD && $SYSTEM_TYPE != "$VARIANT_MESH" ]]; then
243
-	sed -i "s|serverpassword=.*|serverpassword=$VOIP_SERVER_PASSWORD|g" /etc/mumble-server.ini
244
-    fi
242
+	if [[ $VOIP_SERVER_PASSWORD && $SYSTEM_TYPE != "$VARIANT_MESH" ]]; then
243
+		sed -i "s|serverpassword=.*|serverpassword=$VOIP_SERVER_PASSWORD|g" /etc/mumble-server.ini
244
+	fi
245 245
 
246
-    sed -i 's|#autobanAttempts.*|autobanAttempts = 10|g' /etc/mumble-server.ini
247
-    sed -i 's|#autobanTimeframe.*|autobanTimeframe = 120|g' /etc/mumble-server.ini
248
-    sed -i 's|#autobanTime.*|autobanTime = 300|g' /etc/mumble-server.ini
249
-    sed -i 's|#sendversion=.*|sendversion=False|g' /etc/mumble-server.ini
250
-    sed -i 's|sendversion=.*|sendversion=False|g' /etc/mumble-server.ini
251
-    if ! grep -q "allowping" /etc/mumble-server.ini; then
252
-	echo 'allowping=False' >> /etc/mumble-server.ini
253
-    fi
254
-    sed -i 's|allowping=.*|allowping=False|g' /etc/mumble-server.ini
255
-    sed -i 's|#sslCert=.*|sslCert=/var/lib/mumble-server/mumble.crt|g' /etc/mumble-server.ini
256
-    sed -i 's|#sslKey=.*|sslKey=/var/lib/mumble-server/mumble.key|g' /etc/mumble-server.ini
257
-    sed -i 's|#certrequired=.*|certrequired=True|g' /etc/mumble-server.ini
258
-    sed -i 's|users=100|users=10|g' /etc/mumble-server.ini
259
-    sed -i 's|#channelnestinglimit=10|channelnestinglimit=10|g' /etc/mumble-server.ini
260
-    sed -i 's|#textmessagelength=.*|textmessagelength=1000|g' /etc/mumble-server.ini
261
-    sed -i 's|textmessagelength=.*|textmessagelength=1000|g' /etc/mumble-server.ini
262
-    sed -i 's|#imagemessagelength=.*|imagemessagelength=131072|g' /etc/mumble-server.ini
263
-    sed -i 's|#allowhtml=.*|allowhtml=False|g' /etc/mumble-server.ini
264
-    sed -i 's|allowhtml=.*|allowhtml=False|g' /etc/mumble-server.ini
265
-    sed -i "s|port=.*|port=${VOIP_PORT}|g" /etc/mumble-server.ini
246
+	sed -i 's|#autobanAttempts.*|autobanAttempts = 10|g' /etc/mumble-server.ini
247
+	sed -i 's|#autobanTimeframe.*|autobanTimeframe = 120|g' /etc/mumble-server.ini
248
+	sed -i 's|#autobanTime.*|autobanTime = 300|g' /etc/mumble-server.ini
249
+	sed -i 's|#sendversion=.*|sendversion=False|g' /etc/mumble-server.ini
250
+	sed -i 's|sendversion=.*|sendversion=False|g' /etc/mumble-server.ini
251
+	if ! grep -q "allowping" /etc/mumble-server.ini; then
252
+		echo 'allowping=False' >> /etc/mumble-server.ini
253
+	fi
254
+	sed -i 's|allowping=.*|allowping=False|g' /etc/mumble-server.ini
255
+	sed -i 's|#sslCert=.*|sslCert=/var/lib/mumble-server/mumble.crt|g' /etc/mumble-server.ini
256
+	sed -i 's|#sslKey=.*|sslKey=/var/lib/mumble-server/mumble.key|g' /etc/mumble-server.ini
257
+	sed -i 's|#certrequired=.*|certrequired=True|g' /etc/mumble-server.ini
258
+	sed -i 's|users=100|users=10|g' /etc/mumble-server.ini
259
+	sed -i 's|#channelnestinglimit=10|channelnestinglimit=10|g' /etc/mumble-server.ini
260
+	sed -i 's|#textmessagelength=.*|textmessagelength=1000|g' /etc/mumble-server.ini
261
+	sed -i 's|textmessagelength=.*|textmessagelength=1000|g' /etc/mumble-server.ini
262
+	sed -i 's|#imagemessagelength=.*|imagemessagelength=131072|g' /etc/mumble-server.ini
263
+	sed -i 's|#allowhtml=.*|allowhtml=False|g' /etc/mumble-server.ini
264
+	sed -i 's|allowhtml=.*|allowhtml=False|g' /etc/mumble-server.ini
265
+	sed -i "s|port=.*|port=${VOIP_PORT}|g" /etc/mumble-server.ini
266 266
 
267
-    VOIP_ONION_HOSTNAME=$(add_onion_service voip ${VOIP_PORT} ${VOIP_PORT})
268
-    if ! grep -q $"VoIP onion domain" $COMPLETION_FILE; then
269
-	echo "VoIP onion domain:$VOIP_ONION_HOSTNAME" >> $COMPLETION_FILE
270
-    fi
267
+	VOIP_ONION_HOSTNAME=$(add_onion_service voip ${VOIP_PORT} ${VOIP_PORT})
268
+	if ! grep -q $"VoIP onion domain" $COMPLETION_FILE; then
269
+		echo "VoIP onion domain:$VOIP_ONION_HOSTNAME" >> $COMPLETION_FILE
270
+	fi
271 271
 
272
-    systemctl restart mumble-server
272
+	systemctl restart mumble-server
273 273
 
274
-    if ! grep -q $"Mumble Server" /home/$MY_USERNAME/README; then
275
-	echo '' >> /home/$MY_USERNAME/README
276
-	echo '' >> /home/$MY_USERNAME/README
277
-	echo $'Mumble Server' >> /home/$MY_USERNAME/README
278
-	echo '=============' >> /home/$MY_USERNAME/README
279
-	echo $"Mumble onion domain:$VOIP_ONION_HOSTNAME" >> /home/$MY_USERNAME/README
280
-	echo $'Mumble server username: mumble-server' >> /home/$MY_USERNAME/README
281
-	if [[ $SYSTEM_TYPE != "VARIANT_MESH" ]]; then
282
-	    echo $"Mumble server password: $VOIP_SERVER_PASSWORD" >> /home/$MY_USERNAME/README
274
+	if ! grep -q $"Mumble Server" /home/$MY_USERNAME/README; then
275
+		echo '' >> /home/$MY_USERNAME/README
276
+		echo '' >> /home/$MY_USERNAME/README
277
+		echo $'Mumble Server' >> /home/$MY_USERNAME/README
278
+		echo '=============' >> /home/$MY_USERNAME/README
279
+		echo $"Mumble onion domain:$VOIP_ONION_HOSTNAME" >> /home/$MY_USERNAME/README
280
+		echo $'Mumble server username: mumble-server' >> /home/$MY_USERNAME/README
281
+		if [[ $SYSTEM_TYPE != "VARIANT_MESH" ]]; then
282
+			echo $"Mumble server password: $VOIP_SERVER_PASSWORD" >> /home/$MY_USERNAME/README
283
+		fi
284
+		echo '' >> /home/$MY_USERNAME/README
285
+		echo $'To connect to the Mumble server use your username and the server password shown above.' >> /home/$MY_USERNAME/README
286
+		chown $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/README
287
+		chmod 600 /home/$MY_USERNAME/README
283 288
 	fi
284
-	echo '' >> /home/$MY_USERNAME/README
285
-	echo $'To connect to the Mumble server use your username and the server password shown above.' >> /home/$MY_USERNAME/README
286
-	chown $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/README
287
-	chmod 600 /home/$MY_USERNAME/README
288
-    fi
289 289
 
290
-    function_check configure_firewall_for_voip
291
-    configure_firewall_for_voip
292
-    echo 'install_mumble' >> $COMPLETION_FILE
290
+	function_check configure_firewall_for_voip
291
+	configure_firewall_for_voip
292
+	echo 'install_mumble' >> $COMPLETION_FILE
293 293
 }
294 294
 
295 295
 # NOTE: deliberately no exit 0

+ 229
- 229
src/freedombone-app-searx Parādīt failu

@@ -39,258 +39,258 @@ SEARX_LOGIN_TEXT=$"Search engine login"
39 39
 SEARX_PASSWORD=
40 40
 
41 41
 function reconfigure_searx {
42
-    echo -n ''
42
+	echo -n ''
43 43
 }
44 44
 
45 45
 function upgrade_searx {
46
-    if ! grep -Fxq "install_searx" $COMPLETION_FILE; then
47
-	return
48
-    fi
49
-
50
-    set_repo_commit $SEARX_PATH/searx "Search engine commit" "$SEARX_COMMIT" $SEARX_REPO
51
-    if grep "Search engine key" $COMPLETION_FILE; then
52
-	if [ -f ${SEARX_PATH}/searx/searx/settings.yml ]; then
53
-	    # note: this might change to a --tor option in a later version
54
-	    if ! grep 'socks5://127.0.0.1:9050' ${SEARX_PATH}/searx/searx/settings.yml; then
55
-		echo 'outgoing: # communication with search engines' >> ${SEARX_PATH}/searx/searx/settings.yml
56
-		echo '    proxies:' >> ${SEARX_PATH}/searx/searx/settings.yml
57
-		echo '        http : socks5://127.0.0.1:9050' >> ${SEARX_PATH}/searx/searx/settings.yml
58
-		echo '        https: socks5://127.0.0.1:9050' >> ${SEARX_PATH}/searx/searx/settings.yml
59
-	    fi
60
-	    SEARX_SECRET_KEY=$(cat $COMPLETION_FILE | grep "Search engine key" | awk -F ':' '{print $2}')
61
-	    sed -i "s|secret_key.*|secret_key : \"${SEARX_SECRET_KEY}\"|g" ${SEARX_PATH}/searx/searx/settings.yml
62
-	    if [ -f /var/lib/tor/hidden_service_searx/hostname ]; then
63
-		SEARX_ONION_HOSTNAME=$(echo /var/lib/tor/hidden_service_searx/hostname)
64
-		sed -i '0,/RE/s/base_url.*/base_url : \"http://${SEARX_ONION_HOSTNAME}\/' ${SEARX_PATH}/searx/searx/settings.yml
65
-	    fi
46
+	if ! grep -Fxq "install_searx" $COMPLETION_FILE; then
47
+		return
48
+	fi
49
+
50
+	set_repo_commit $SEARX_PATH/searx "Search engine commit" "$SEARX_COMMIT" $SEARX_REPO
51
+	if grep "Search engine key" $COMPLETION_FILE; then
52
+		if [ -f ${SEARX_PATH}/searx/searx/settings.yml ]; then
53
+			# note: this might change to a --tor option in a later version
54
+			if ! grep 'socks5://127.0.0.1:9050' ${SEARX_PATH}/searx/searx/settings.yml; then
55
+				echo 'outgoing: # communication with search engines' >> ${SEARX_PATH}/searx/searx/settings.yml
56
+				echo '    proxies:' >> ${SEARX_PATH}/searx/searx/settings.yml
57
+				echo '        http : socks5://127.0.0.1:9050' >> ${SEARX_PATH}/searx/searx/settings.yml
58
+				echo '        https: socks5://127.0.0.1:9050' >> ${SEARX_PATH}/searx/searx/settings.yml
59
+			fi
60
+			SEARX_SECRET_KEY=$(cat $COMPLETION_FILE | grep "Search engine key" | awk -F ':' '{print $2}')
61
+			sed -i "s|secret_key.*|secret_key : \"${SEARX_SECRET_KEY}\"|g" ${SEARX_PATH}/searx/searx/settings.yml
62
+			if [ -f /var/lib/tor/hidden_service_searx/hostname ]; then
63
+				SEARX_ONION_HOSTNAME=$(echo /var/lib/tor/hidden_service_searx/hostname)
64
+				sed -i '0,/RE/s/base_url.*/base_url : \"http://${SEARX_ONION_HOSTNAME}\/' ${SEARX_PATH}/searx/searx/settings.yml
65
+			fi
66
+		fi
66 67
 	fi
67
-    fi
68 68
 }
69 69
 
70 70
 function backup_local_searx {
71
-    echo -n ''
71
+	echo -n ''
72 72
 }
73 73
 
74 74
 function restore_local_searx {
75
-    echo -n ''
75
+	echo -n ''
76 76
 }
77 77
 
78 78
 function backup_remote_searx {
79
-    echo -n ''
79
+	echo -n ''
80 80
 }
81 81
 
82 82
 function restore_remote_searx {
83
-    echo -n ''
83
+	echo -n ''
84 84
 }
85 85
 
86 86
 function remove_searx {
87
-    if ! grep -Fxq "install_searx" $COMPLETION_FILE; then
88
-	return
89
-    fi
90
-    systemctl stop searx
91
-    systemctl disable searx
92
-    rm /etc/systemd/system/searx.service
93
-    function_check remove_onion_service
94
-    remove_onion_service searx ${SEARX_ONION_PORT}
95
-    userdel -r searx
96
-    nginx_dissite searx
97
-    if [ -f /etc/nginx/sites-available/searx ]; then
98
-	rm /etc/nginx/sites-available/searx
99
-    fi
100
-    if [ -d ${SEARX_PATH}/searx ]; then
101
-	rm -rf ${SEARX_PATH}/searx
102
-    fi
103
-    sed -i '/install_searx/d' $COMPLETION_FILE
104
-    sed -i '/Search engine /d' $COMPLETION_FILE
87
+	if ! grep -Fxq "install_searx" $COMPLETION_FILE; then
88
+		return
89
+	fi
90
+	systemctl stop searx
91
+	systemctl disable searx
92
+	rm /etc/systemd/system/searx.service
93
+	function_check remove_onion_service
94
+	remove_onion_service searx ${SEARX_ONION_PORT}
95
+	userdel -r searx
96
+	nginx_dissite searx
97
+	if [ -f /etc/nginx/sites-available/searx ]; then
98
+		rm /etc/nginx/sites-available/searx
99
+	fi
100
+	if [ -d ${SEARX_PATH}/searx ]; then
101
+		rm -rf ${SEARX_PATH}/searx
102
+	fi
103
+	sed -i '/install_searx/d' $COMPLETION_FILE
104
+	sed -i '/Search engine /d' $COMPLETION_FILE
105 105
 }
106 106
 
107 107
 function install_searx {
108
-    # Note: currently socks5 outgoing proxies to other search engines does not work
109
-    if [[ $SYSTEM_TYPE == "$VARIANT_MESH" ]]; then
110
-	return
111
-    fi
112
-    if [ ! -d /etc/nginx ]; then
113
-	echo $'Webserver is not installed'
114
-	exit 62429
115
-    fi
116
-
117
-    if grep -Fxq "install_searx" $COMPLETION_FILE; then
118
-	return
119
-    fi
120
-
121
-    apt-get -y install python-pip libyaml-dev python-werkzeug python-babel python-lxml apache2-utils
122
-    apt-get -y install git build-essential libxslt-dev python-dev python-virtualenv python-pybabel zlib1g-dev uwsgi uwsgi-plugin-python libapache2-mod-uwsgi
123
-
124
-    pip install --upgrade pip
125
-
126
-    pip install certifi
127
-    if [ ! "$?" = "0" ]; then
128
-	echo $'Failed to install certifi'
129
-	exit 737692
130
-    fi
131
-
132
-    pip install pyyaml
133
-    if [ ! "$?" = "0" ]; then
134
-	echo $'Failed to install pyyaml'
135
-	exit 469242
136
-    fi
137
-
138
-    pip install flask --upgrade
139
-    if [ ! "$?" = "0" ]; then
140
-	echo $'Failed to install flask'
141
-	exit 888575
142
-    fi
143
-
144
-    pip install flask_restless --upgrade
145
-    if [ ! "$?" = "0" ]; then
146
-	echo $'Failed to install flask_restless'
147
-	exit 54835
148
-    fi
149
-
150
-    pip install flask_babel --upgrade
151
-    if [ ! "$?" = "0" ]; then
152
-	echo $'Failed to install flask_babel'
153
-	exit 63738
154
-    fi
155
-
156
-    if [ ! -d $SEARX_PATH ]; then
157
-	mkdir -p $SEARX_PATH
158
-    fi
159
-
160
-    # clone the repo
161
-    cd $SEARX_PATH
162
-    function_check git_clone
163
-    git_clone $SEARX_REPO searx
164
-    git checkout $SEARX_COMMIT -b $SEARX_COMMIT
165
-    if ! grep -q "Search engine commit" $COMPLETION_FILE; then
166
-	echo "Search engine commit:$SEARX_COMMIT" >> $COMPLETION_FILE
167
-    else
168
-	sed -i "s/Search engine commit.*/Search engine commit:$SEARX_COMMIT/g" $COMPLETION_FILE
169
-    fi
170
-
171
-    # create an onion service
172
-    SEARX_ONION_HOSTNAME=$(add_onion_service searx 80 ${SEARX_ONION_PORT})
173
-    if ! grep "Search engine onion domain" $COMPLETION_FILE; then
174
-	echo "Search engine onion domain:${SEARX_ONION_HOSTNAME}" >> $COMPLETION_FILE
175
-    else
176
-	sed -i "s|Search engine onion domain.*|Search engine onion domain:${SEARX_ONION_HOSTNAME}|g" $COMPLETION_FILE
177
-    fi
178
-
179
-    # an unprivileged user to run as
180
-    useradd -d ${SEARX_PATH}/searx/ -s /bin/false searx
181
-    adduser searx debian-tor
182
-
183
-    # daemon
184
-    echo '[Unit]' > /etc/systemd/system/searx.service
185
-    echo 'Description=Searx (search engine)' >> /etc/systemd/system/searx.service
186
-    echo 'After=syslog.target' >> /etc/systemd/system/searx.service
187
-    echo 'After=network.target' >> /etc/systemd/system/searx.service
188
-    echo '' >> /etc/systemd/system/searx.service
189
-    echo '[Service]' >> /etc/systemd/system/searx.service
190
-    echo 'Type=simple' >> /etc/systemd/system/searx.service
191
-    echo 'User=searx' >> /etc/systemd/system/searx.service
192
-    echo 'Group=searx' >> /etc/systemd/system/searx.service
193
-    echo "WorkingDirectory=${SEARX_PATH}/searx" >> /etc/systemd/system/searx.service
194
-    echo "ExecStart=/usr/bin/python ${SEARX_PATH}/searx/searx/webapp.py" >> /etc/systemd/system/searx.service
195
-    echo 'Restart=always' >> /etc/systemd/system/searx.service
196
-    echo 'Environment="USER=searx"' >> /etc/systemd/system/searx.service
197
-    echo '' >> /etc/systemd/system/searx.service
198
-    echo '[Install]' >> /etc/systemd/system/searx.service
199
-    echo 'WantedBy=multi-user.target' >> /etc/systemd/system/searx.service
200
-
201
-    # create a webserver file
202
-    echo 'server {' > /etc/nginx/sites-available/searx
203
-    echo "    listen 127.0.0.1:${SEARX_ONION_PORT} default_server;" >> /etc/nginx/sites-available/searx
204
-    echo "    root ${SEARX_PATH}/searx;" >> /etc/nginx/sites-available/searx
205
-    echo "    server_name ${SEARX_ONION_HOSTNAME};" >> /etc/nginx/sites-available/searx
206
-    echo '    access_log off;' >> /etc/nginx/sites-available/searx
207
-    echo "    error_log /var/log/searx_error.log $WEBSERVER_LOG_LEVEL;" >> /etc/nginx/sites-available/searx
208
-    echo '' >> /etc/nginx/sites-available/searx
209
-    function_check nginx_limits
210
-    nginx_limits searx '1M'
211
-    function_check nginx_disable_sniffing
212
-    nginx_disable_sniffing searx
213
-    echo '    add_header Strict-Transport-Security max-age=0;' >> /etc/nginx/sites-available/searx
214
-    echo '' >> /etc/nginx/sites-available/searx
215
-    echo '    location / {' >> /etc/nginx/sites-available/searx
216
-    echo '        proxy_pass http://localhost:8888;' >> /etc/nginx/sites-available/searx
217
-    echo '        proxy_set_header Host $host;' >> /etc/nginx/sites-available/searx
218
-    echo '        proxy_set_header X-Real-IP $remote_addr;' >> /etc/nginx/sites-available/searx
219
-    echo '        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;' >> /etc/nginx/sites-available/searx
220
-    echo '        proxy_set_header X-Remote-Port $remote_port;' >> /etc/nginx/sites-available/searx
221
-    echo '        proxy_set_header X-Forwarded-Proto $scheme;' >> /etc/nginx/sites-available/searx
222
-    echo '        proxy_redirect off;' >> /etc/nginx/sites-available/searx
223
-
224
-    echo "        auth_basic \"${SEARX_LOGIN_TEXT}\";" >> /etc/nginx/sites-available/searx
225
-    echo '        auth_basic_user_file /etc/nginx/.htpasswd;' >> /etc/nginx/sites-available/searx
226
-    echo '    }' >> /etc/nginx/sites-available/searx
227
-    echo '' >> /etc/nginx/sites-available/searx
228
-    echo '    fastcgi_buffers 64 4K;' >> /etc/nginx/sites-available/searx
229
-    echo '' >> /etc/nginx/sites-available/searx
230
-    echo '    error_page 403 /core/templates/403.php;' >> /etc/nginx/sites-available/searx
231
-    echo '    error_page 404 /core/templates/404.php;' >> /etc/nginx/sites-available/searx
232
-    echo '' >> /etc/nginx/sites-available/searx
233
-    echo '    location = /robots.txt {' >> /etc/nginx/sites-available/searx
234
-    echo '        allow all;' >> /etc/nginx/sites-available/searx
235
-    echo '        log_not_found off;' >> /etc/nginx/sites-available/searx
236
-    echo '        access_log off;' >> /etc/nginx/sites-available/searx
237
-    echo '    }' >> /etc/nginx/sites-available/searx
238
-    echo '}' >> /etc/nginx/sites-available/searx
239
-
240
-    # replace the secret key
241
-    if ! grep "Search engine key" $COMPLETION_FILE; then
242
-	SEARX_SECRET_KEY="$(create_password 30)"
243
-	echo "Search engine key:${SEARX_SECRET_KEY}" >> $COMPLETION_FILE
244
-    else
245
-	SEARX_SECRET_KEY=$(cat $COMPLETION_FILE | grep "Search engine key" | awk -F ':' '{print $2}')
246
-    fi
247
-    sed -i "s|secret_key.*|secret_key : \"${SEARX_SECRET_KEY}\"|g" ${SEARX_PATH}/searx/searx/settings.yml
248
-    sed -i "s|secret_key.*|secret_key : \"${SEARX_SECRET_KEY}\"|g" ${SEARX_PATH}/searx/searx/settings_robot.yml
249
-    sed -i '0,/RE/s/base_url.*/base_url : \"http://${SEARX_ONION_HOSTNAME}\/' ${SEARX_PATH}/searx/searx/settings.yml
250
-    sed -i '0,/RE/s/base_url.*/base_url : \"http://${SEARX_ONION_HOSTNAME}\/' ${SEARX_PATH}/searx/searx/settings_robot.yml
251
-
252
-    # note: this might change to a --tor option in a later version
253
-    if ! grep 'socks5://127.0.0.1:9050' ${SEARX_PATH}/searx/searx/settings.yml; then
254
-	echo 'outgoing: # communication with search engines' >> ${SEARX_PATH}/searx/searx/settings.yml
255
-	echo '    proxies:' >> ${SEARX_PATH}/searx/searx/settings.yml
256
-	echo '        http : socks5://127.0.0.1:9050' >> ${SEARX_PATH}/searx/searx/settings.yml
257
-	echo '        https: socks5://127.0.0.1:9050' >> ${SEARX_PATH}/searx/searx/settings.yml
258
-    fi
259
-
260
-    chown -R searx:searx ${SEARX_PATH}/searx
261
-
262
-    # enable the site
263
-    nginx_ensite searx
264
-
265
-    # restart the web server
266
-    systemctl restart php5-fpm
267
-    systemctl restart nginx
268
-
269
-    # start the daemon
270
-    systemctl enable searx.service
271
-    systemctl daemon-reload
272
-    systemctl start searx.service
273
-
274
-    if ! grep -q "Your search engine password is" /home/$MY_USERNAME/README; then
275
-	if [ ${#SEARX_PASSWORD} -lt 8 ]; then
276
-	    if [ -f $IMAGE_PASSWORD_FILE ]; then
277
-		SEARX_PASSWORD="$(printf `cat $IMAGE_PASSWORD_FILE`)"
278
-	    else
279
-		SEARX_PASSWORD="$(create_password ${MINIMUM_PASSWORD_LENGTH})"
280
-	    fi
108
+	# Note: currently socks5 outgoing proxies to other search engines does not work
109
+	if [[ $SYSTEM_TYPE == "$VARIANT_MESH" ]]; then
110
+		return
281 111
 	fi
282
-	echo "$SEARX_PASSWORD" | htpasswd -i -s -c /etc/nginx/.htpasswd $MY_USERNAME
283
-	echo '' >> /home/$MY_USERNAME/README
284
-	echo '' >> /home/$MY_USERNAME/README
285
-	echo $'Search Engine' >> /home/$MY_USERNAME/README
286
-	echo '=============' >> /home/$MY_USERNAME/README
287
-	echo $"Search engine onion domain: ${SEARX_ONION_HOSTNAME}" >> /home/$MY_USERNAME/README
288
-	echo $"Your search engine password is: $SEARX_PASSWORD" >> /home/$MY_USERNAME/README
289
-	chown $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/README
290
-	chmod 600 /home/$MY_USERNAME/README
291
-    fi
292
-
293
-    echo 'install_searx' >> $COMPLETION_FILE
112
+	if [ ! -d /etc/nginx ]; then
113
+		echo $'Webserver is not installed'
114
+		exit 62429
115
+	fi
116
+
117
+	if grep -Fxq "install_searx" $COMPLETION_FILE; then
118
+		return
119
+	fi
120
+
121
+	apt-get -y install python-pip libyaml-dev python-werkzeug python-babel python-lxml apache2-utils
122
+	apt-get -y install git build-essential libxslt-dev python-dev python-virtualenv python-pybabel zlib1g-dev uwsgi uwsgi-plugin-python libapache2-mod-uwsgi
123
+
124
+	pip install --upgrade pip
125
+
126
+	pip install certifi
127
+	if [ ! "$?" = "0" ]; then
128
+		echo $'Failed to install certifi'
129
+		exit 737692
130
+	fi
131
+
132
+	pip install pyyaml
133
+	if [ ! "$?" = "0" ]; then
134
+		echo $'Failed to install pyyaml'
135
+		exit 469242
136
+	fi
137
+
138
+	pip install flask --upgrade
139
+	if [ ! "$?" = "0" ]; then
140
+		echo $'Failed to install flask'
141
+		exit 888575
142
+	fi
143
+
144
+	pip install flask_restless --upgrade
145
+	if [ ! "$?" = "0" ]; then
146
+		echo $'Failed to install flask_restless'
147
+		exit 54835
148
+	fi
149
+
150
+	pip install flask_babel --upgrade
151
+	if [ ! "$?" = "0" ]; then
152
+		echo $'Failed to install flask_babel'
153
+		exit 63738
154
+	fi
155
+
156
+	if [ ! -d $SEARX_PATH ]; then
157
+		mkdir -p $SEARX_PATH
158
+	fi
159
+
160
+	# clone the repo
161
+	cd $SEARX_PATH
162
+	function_check git_clone
163
+	git_clone $SEARX_REPO searx
164
+	git checkout $SEARX_COMMIT -b $SEARX_COMMIT
165
+	if ! grep -q "Search engine commit" $COMPLETION_FILE; then
166
+		echo "Search engine commit:$SEARX_COMMIT" >> $COMPLETION_FILE
167
+	else
168
+		sed -i "s/Search engine commit.*/Search engine commit:$SEARX_COMMIT/g" $COMPLETION_FILE
169
+	fi
170
+
171
+	# create an onion service
172
+	SEARX_ONION_HOSTNAME=$(add_onion_service searx 80 ${SEARX_ONION_PORT})
173
+	if ! grep "Search engine onion domain" $COMPLETION_FILE; then
174
+		echo "Search engine onion domain:${SEARX_ONION_HOSTNAME}" >> $COMPLETION_FILE
175
+	else
176
+		sed -i "s|Search engine onion domain.*|Search engine onion domain:${SEARX_ONION_HOSTNAME}|g" $COMPLETION_FILE
177
+	fi
178
+
179
+	# an unprivileged user to run as
180
+	useradd -d ${SEARX_PATH}/searx/ -s /bin/false searx
181
+	adduser searx debian-tor
182
+
183
+	# daemon
184
+	echo '[Unit]' > /etc/systemd/system/searx.service
185
+	echo 'Description=Searx (search engine)' >> /etc/systemd/system/searx.service
186
+	echo 'After=syslog.target' >> /etc/systemd/system/searx.service
187
+	echo 'After=network.target' >> /etc/systemd/system/searx.service
188
+	echo '' >> /etc/systemd/system/searx.service
189
+	echo '[Service]' >> /etc/systemd/system/searx.service
190
+	echo 'Type=simple' >> /etc/systemd/system/searx.service
191
+	echo 'User=searx' >> /etc/systemd/system/searx.service
192
+	echo 'Group=searx' >> /etc/systemd/system/searx.service
193
+	echo "WorkingDirectory=${SEARX_PATH}/searx" >> /etc/systemd/system/searx.service
194
+	echo "ExecStart=/usr/bin/python ${SEARX_PATH}/searx/searx/webapp.py" >> /etc/systemd/system/searx.service
195
+	echo 'Restart=always' >> /etc/systemd/system/searx.service
196
+	echo 'Environment="USER=searx"' >> /etc/systemd/system/searx.service
197
+	echo '' >> /etc/systemd/system/searx.service
198
+	echo '[Install]' >> /etc/systemd/system/searx.service
199
+	echo 'WantedBy=multi-user.target' >> /etc/systemd/system/searx.service
200
+
201
+	# create a webserver file
202
+	echo 'server {' > /etc/nginx/sites-available/searx
203
+	echo "    listen 127.0.0.1:${SEARX_ONION_PORT} default_server;" >> /etc/nginx/sites-available/searx
204
+	echo "    root ${SEARX_PATH}/searx;" >> /etc/nginx/sites-available/searx
205
+	echo "    server_name ${SEARX_ONION_HOSTNAME};" >> /etc/nginx/sites-available/searx
206
+	echo '    access_log off;' >> /etc/nginx/sites-available/searx
207
+	echo "    error_log /var/log/searx_error.log $WEBSERVER_LOG_LEVEL;" >> /etc/nginx/sites-available/searx
208
+	echo '' >> /etc/nginx/sites-available/searx
209
+	function_check nginx_limits
210
+	nginx_limits searx '1M'
211
+	function_check nginx_disable_sniffing
212
+	nginx_disable_sniffing searx
213
+	echo '    add_header Strict-Transport-Security max-age=0;' >> /etc/nginx/sites-available/searx
214
+	echo '' >> /etc/nginx/sites-available/searx
215
+	echo '    location / {' >> /etc/nginx/sites-available/searx
216
+	echo '        proxy_pass http://localhost:8888;' >> /etc/nginx/sites-available/searx
217
+	echo '        proxy_set_header Host $host;' >> /etc/nginx/sites-available/searx
218
+	echo '        proxy_set_header X-Real-IP $remote_addr;' >> /etc/nginx/sites-available/searx
219
+	echo '        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;' >> /etc/nginx/sites-available/searx
220
+	echo '        proxy_set_header X-Remote-Port $remote_port;' >> /etc/nginx/sites-available/searx
221
+	echo '        proxy_set_header X-Forwarded-Proto $scheme;' >> /etc/nginx/sites-available/searx
222
+	echo '        proxy_redirect off;' >> /etc/nginx/sites-available/searx
223
+
224
+	echo "        auth_basic \"${SEARX_LOGIN_TEXT}\";" >> /etc/nginx/sites-available/searx
225
+	echo '        auth_basic_user_file /etc/nginx/.htpasswd;' >> /etc/nginx/sites-available/searx
226
+	echo '    }' >> /etc/nginx/sites-available/searx
227
+	echo '' >> /etc/nginx/sites-available/searx
228
+	echo '    fastcgi_buffers 64 4K;' >> /etc/nginx/sites-available/searx
229
+	echo '' >> /etc/nginx/sites-available/searx
230
+	echo '    error_page 403 /core/templates/403.php;' >> /etc/nginx/sites-available/searx
231
+	echo '    error_page 404 /core/templates/404.php;' >> /etc/nginx/sites-available/searx
232
+	echo '' >> /etc/nginx/sites-available/searx
233
+	echo '    location = /robots.txt {' >> /etc/nginx/sites-available/searx
234
+	echo '        allow all;' >> /etc/nginx/sites-available/searx
235
+	echo '        log_not_found off;' >> /etc/nginx/sites-available/searx
236
+	echo '        access_log off;' >> /etc/nginx/sites-available/searx
237
+	echo '    }' >> /etc/nginx/sites-available/searx
238
+	echo '}' >> /etc/nginx/sites-available/searx
239
+
240
+	# replace the secret key
241
+	if ! grep "Search engine key" $COMPLETION_FILE; then
242
+		SEARX_SECRET_KEY="$(create_password 30)"
243
+		echo "Search engine key:${SEARX_SECRET_KEY}" >> $COMPLETION_FILE
244
+	else
245
+		SEARX_SECRET_KEY=$(cat $COMPLETION_FILE | grep "Search engine key" | awk -F ':' '{print $2}')
246
+	fi
247
+	sed -i "s|secret_key.*|secret_key : \"${SEARX_SECRET_KEY}\"|g" ${SEARX_PATH}/searx/searx/settings.yml
248
+	sed -i "s|secret_key.*|secret_key : \"${SEARX_SECRET_KEY}\"|g" ${SEARX_PATH}/searx/searx/settings_robot.yml
249
+	sed -i '0,/RE/s/base_url.*/base_url : \"http://${SEARX_ONION_HOSTNAME}\/' ${SEARX_PATH}/searx/searx/settings.yml
250
+	sed -i '0,/RE/s/base_url.*/base_url : \"http://${SEARX_ONION_HOSTNAME}\/' ${SEARX_PATH}/searx/searx/settings_robot.yml
251
+
252
+	# note: this might change to a --tor option in a later version
253
+	if ! grep 'socks5://127.0.0.1:9050' ${SEARX_PATH}/searx/searx/settings.yml; then
254
+		echo 'outgoing: # communication with search engines' >> ${SEARX_PATH}/searx/searx/settings.yml
255
+		echo '    proxies:' >> ${SEARX_PATH}/searx/searx/settings.yml
256
+		echo '        http : socks5://127.0.0.1:9050' >> ${SEARX_PATH}/searx/searx/settings.yml
257
+		echo '        https: socks5://127.0.0.1:9050' >> ${SEARX_PATH}/searx/searx/settings.yml
258
+	fi
259
+
260
+	chown -R searx:searx ${SEARX_PATH}/searx
261
+
262
+	# enable the site
263
+	nginx_ensite searx
264
+
265
+	# restart the web server
266
+	systemctl restart php5-fpm
267
+	systemctl restart nginx
268
+
269
+	# start the daemon
270
+	systemctl enable searx.service
271
+	systemctl daemon-reload
272
+	systemctl start searx.service
273
+
274
+	if ! grep -q "Your search engine password is" /home/$MY_USERNAME/README; then
275
+		if [ ${#SEARX_PASSWORD} -lt 8 ]; then
276
+			if [ -f $IMAGE_PASSWORD_FILE ]; then
277
+				SEARX_PASSWORD="$(printf `cat $IMAGE_PASSWORD_FILE`)"
278
+			else
279
+				SEARX_PASSWORD="$(create_password ${MINIMUM_PASSWORD_LENGTH})"
280
+			fi
281
+		fi
282
+		echo "$SEARX_PASSWORD" | htpasswd -i -s -c /etc/nginx/.htpasswd $MY_USERNAME
283
+		echo '' >> /home/$MY_USERNAME/README
284
+		echo '' >> /home/$MY_USERNAME/README
285
+		echo $'Search Engine' >> /home/$MY_USERNAME/README
286
+		echo '=============' >> /home/$MY_USERNAME/README
287
+		echo $"Search engine onion domain: ${SEARX_ONION_HOSTNAME}" >> /home/$MY_USERNAME/README
288
+		echo $"Your search engine password is: $SEARX_PASSWORD" >> /home/$MY_USERNAME/README
289
+		chown $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/README
290
+		chmod 600 /home/$MY_USERNAME/README
291
+	fi
292
+
293
+	echo 'install_searx' >> $COMPLETION_FILE
294 294
 }
295 295
 
296 296
 # NOTE: deliberately no exit 0

+ 361
- 361
src/freedombone-app-sip Parādīt failu

@@ -38,415 +38,415 @@ VOIP_TURN_TLS_PORT=5349
38 38
 VOIP_TURN_NONCE=
39 39
 
40 40
 function reconfigure_sip {
41
-    echo -n ''
41
+	echo -n ''
42 42
 }
43 43
 
44 44
 function upgrade_sip {
45
-    # remove the original sipwitch daemon if it exists
46
-    if [ -f /etc/init.d/sipwitch ]; then
47
-	rm -f /etc/init.d/sipwitch
48
-    fi
45
+	# remove the original sipwitch daemon if it exists
46
+	if [ -f /etc/init.d/sipwitch ]; then
47
+		rm -f /etc/init.d/sipwitch
48
+	fi
49 49
 }
50 50
 
51 51
 function backup_local_sip {
52
-    if [ -f /etc/sipwitch.conf ]; then
53
-	echo $"Backing up SIP settings"
54
-	temp_backup_dir=/root/tempsipbackup
55
-	if [ ! -d $temp_backup_dir ]; then
56
-	    mkdir -p $temp_backup_dir
52
+	if [ -f /etc/sipwitch.conf ]; then
53
+		echo $"Backing up SIP settings"
54
+		temp_backup_dir=/root/tempsipbackup
55
+		if [ ! -d $temp_backup_dir ]; then
56
+			mkdir -p $temp_backup_dir
57
+		fi
58
+		cp -f /etc/sipwitch.conf $temp_backup_dir
59
+		backup_directory_to_usb $temp_backup_dir sip
60
+		echo $"SIP settings backup complete"
57 61
 	fi
58
-	cp -f /etc/sipwitch.conf $temp_backup_dir
59
-	backup_directory_to_usb $temp_backup_dir sip
60
-	echo $"SIP settings backup complete"
61
-    fi
62 62
 }
63 63
 
64 64
 function restore_local_sip {
65
-    if [ -d $USB_MOUNT/backup/sip ]; then
66
-	echo $"Restoring SIP settings"
67
-	temp_restore_dir=/root/tempsip
68
-	function_check restore_directory_from_usb
69
-	restore_directory_from_usb $temp_restore_dir sip
70
-	cp -f $temp_restore_dir/home/$ADMIN_USERNAME/tempbackup/sipwitch.conf /etc/sipwitch.conf
71
-	if [ ! "$?" = "0" ]; then
72
-	    rm -rf $temp_restore_dir
73
-	    function_check set_user_permissions
74
-	    set_user_permissions
75
-	    backup_unmount_drive
76
-	    exit 3679
65
+	if [ -d $USB_MOUNT/backup/sip ]; then
66
+		echo $"Restoring SIP settings"
67
+		temp_restore_dir=/root/tempsip
68
+		function_check restore_directory_from_usb
69
+		restore_directory_from_usb $temp_restore_dir sip
70
+		cp -f $temp_restore_dir/home/$ADMIN_USERNAME/tempbackup/sipwitch.conf /etc/sipwitch.conf
71
+		if [ ! "$?" = "0" ]; then
72
+			rm -rf $temp_restore_dir
73
+			function_check set_user_permissions
74
+			set_user_permissions
75
+			backup_unmount_drive
76
+			exit 3679
77
+		fi
78
+		rm -rf $temp_restore_dir
79
+		service sipwitch restart
80
+		echo $"Restore of SIP settings complete"
77 81
 	fi
78
-	rm -rf $temp_restore_dir
79
-	service sipwitch restart
80
-	echo $"Restore of SIP settings complete"
81
-    fi
82 82
 }
83 83
 
84 84
 function backup_remote_sip {
85
-    if [ -f /etc/sipwitch.conf ]; then
86
-	echo $"Backing up SIP settings"
87
-	temp_backup_dir=/root/tempsipbackup
88
-	if [ ! -d $temp_backup_dir ]; then
89
-	    mkdir -p $temp_backup_dir
85
+	if [ -f /etc/sipwitch.conf ]; then
86
+		echo $"Backing up SIP settings"
87
+		temp_backup_dir=/root/tempsipbackup
88
+		if [ ! -d $temp_backup_dir ]; then
89
+			mkdir -p $temp_backup_dir
90
+		fi
91
+		cp -f /etc/sipwitch.conf $temp_backup_dir
92
+		backup_directory_to_friend $temp_backup_dir sip
93
+		echo $"Backup SIP settings complete"
90 94
 	fi
91
-	cp -f /etc/sipwitch.conf $temp_backup_dir
92
-	backup_directory_to_friend $temp_backup_dir sip
93
-	echo $"Backup SIP settings complete"
94
-    fi
95 95
 }
96 96
 
97 97
 function restore_remote_sip {
98
-    echo -n ''
98
+	echo -n ''
99 99
 }
100 100
 
101 101
 function remove_sip {
102
-    if ! grep -Fxq "install_sip" $COMPLETION_FILE; then
103
-	return
104
-    fi
105
-    iptables -D INPUT -p udp --dport $VOIP_TURN_PORT -j ACCEPT
106
-    iptables -D INPUT -p tcp --dport $VOIP_TURN_PORT -j ACCEPT
107
-    iptables -D INPUT -p tcp --dport $VOIP_TURN_TLS_PORT -j ACCEPT
108
-    iptables -D INPUT -p udp --dport $SIP_PORT -j ACCEPT
109
-    iptables -D INPUT -p tcp --dport $SIP_PORT -j ACCEPT
110
-    iptables -D INPUT -p udp --dport $SIP_TLS_PORT -j ACCEPT
111
-    iptables -D INPUT -p tcp --dport $SIP_TLS_PORT -j ACCEPT
112
-    function_check save_firewall_settings
113
-    save_firewall_settings
114
-
115
-    function_check remove_onion_service
116
-    remove_onion_service sip ${SIP_PORT}
117
-
118
-    apt-get -y remove --purge sipwitch
119
-    apt-get -y remove --purge turnserver
120
-    if [ -f /etc/sipwitch.conf ]; then
121
-	rm /etc/sipwitch.conf
122
-    fi
123
-    if [ -d /etc/turnserver ]; then
124
-	rm -rf /etc/turnserver
125
-    fi
126
-    sed -i '/install_sip/d' $COMPLETION_FILE
127
-    sed -i '/configure_firewall_for_voip_turn/d' $COMPLETION_FILE
128
-    sed -i '/configure_firewall_for_sip4/d' $COMPLETION_FILE
102
+	if ! grep -Fxq "install_sip" $COMPLETION_FILE; then
103
+		return
104
+	fi
105
+	iptables -D INPUT -p udp --dport $VOIP_TURN_PORT -j ACCEPT
106
+	iptables -D INPUT -p tcp --dport $VOIP_TURN_PORT -j ACCEPT
107
+	iptables -D INPUT -p tcp --dport $VOIP_TURN_TLS_PORT -j ACCEPT
108
+	iptables -D INPUT -p udp --dport $SIP_PORT -j ACCEPT
109
+	iptables -D INPUT -p tcp --dport $SIP_PORT -j ACCEPT
110
+	iptables -D INPUT -p udp --dport $SIP_TLS_PORT -j ACCEPT
111
+	iptables -D INPUT -p tcp --dport $SIP_TLS_PORT -j ACCEPT
112
+	function_check save_firewall_settings
113
+	save_firewall_settings
114
+
115
+	function_check remove_onion_service
116
+	remove_onion_service sip ${SIP_PORT}
117
+
118
+	apt-get -y remove --purge sipwitch
119
+	apt-get -y remove --purge turnserver
120
+	if [ -f /etc/sipwitch.conf ]; then
121
+		rm /etc/sipwitch.conf
122
+	fi
123
+	if [ -d /etc/turnserver ]; then
124
+		rm -rf /etc/turnserver
125
+	fi
126
+	sed -i '/install_sip/d' $COMPLETION_FILE
127
+	sed -i '/configure_firewall_for_voip_turn/d' $COMPLETION_FILE
128
+	sed -i '/configure_firewall_for_sip4/d' $COMPLETION_FILE
129 129
 }
130 130
 
131 131
 function configure_firewall_for_voip_turn {
132
-    if grep -Fxq "configure_firewall_for_voip_turn" $COMPLETION_FILE; then
133
-	return
134
-    fi
135
-    if [[ $ONION_ONLY != "no" ]]; then
136
-	return
137
-    fi
138
-    iptables -A INPUT -p udp --dport $VOIP_TURN_PORT -j ACCEPT
139
-    iptables -A INPUT -p tcp --dport $VOIP_TURN_PORT -j ACCEPT
140
-    iptables -A INPUT -p tcp --dport $VOIP_TURN_TLS_PORT -j ACCEPT
141
-    function_check save_firewall_settings
142
-    save_firewall_settings
143
-
144
-    OPEN_PORTS+=("TURN     $VOIP_TURN_PORT")
145
-    OPEN_PORTS+=("TURN TLS $VOIP_TURN_TLS_PORT")
146
-    echo 'configure_firewall_for_voip_turn' >> $COMPLETION_FILE
132
+	if grep -Fxq "configure_firewall_for_voip_turn" $COMPLETION_FILE; then
133
+		return
134
+	fi
135
+	if [[ $ONION_ONLY != "no" ]]; then
136
+		return
137
+	fi
138
+	iptables -A INPUT -p udp --dport $VOIP_TURN_PORT -j ACCEPT
139
+	iptables -A INPUT -p tcp --dport $VOIP_TURN_PORT -j ACCEPT
140
+	iptables -A INPUT -p tcp --dport $VOIP_TURN_TLS_PORT -j ACCEPT
141
+	function_check save_firewall_settings
142
+	save_firewall_settings
143
+
144
+	OPEN_PORTS+=("TURN     $VOIP_TURN_PORT")
145
+	OPEN_PORTS+=("TURN TLS $VOIP_TURN_TLS_PORT")
146
+	echo 'configure_firewall_for_voip_turn' >> $COMPLETION_FILE
147 147
 }
148 148
 
149 149
 
150 150
 function configure_firewall_for_sip4 {
151
-    if grep -Fxq "configure_firewall_for_sip4" $COMPLETION_FILE; then
152
-	return
153
-    fi
154
-    if [[ $ONION_ONLY != "no" ]]; then
155
-	return
156
-    fi
157
-    iptables -A INPUT -p udp --dport $SIP_PORT -j ACCEPT
158
-    iptables -A INPUT -p tcp --dport $SIP_PORT -j ACCEPT
159
-    iptables -A INPUT -p udp --dport $SIP_TLS_PORT -j ACCEPT
160
-    iptables -A INPUT -p tcp --dport $SIP_TLS_PORT -j ACCEPT
161
-    function_check save_firewall_settings
162
-    save_firewall_settings
163
-
164
-    OPEN_PORTS+=("SIP      $SIP_PORT")
165
-    OPEN_PORTS+=("SIP TLS  $SIP_TLS_PORT")
166
-    echo 'configure_firewall_for_sip4' >> $COMPLETION_FILE
151
+	if grep -Fxq "configure_firewall_for_sip4" $COMPLETION_FILE; then
152
+		return
153
+	fi
154
+	if [[ $ONION_ONLY != "no" ]]; then
155
+		return
156
+	fi
157
+	iptables -A INPUT -p udp --dport $SIP_PORT -j ACCEPT
158
+	iptables -A INPUT -p tcp --dport $SIP_PORT -j ACCEPT
159
+	iptables -A INPUT -p udp --dport $SIP_TLS_PORT -j ACCEPT
160
+	iptables -A INPUT -p tcp --dport $SIP_TLS_PORT -j ACCEPT
161
+	function_check save_firewall_settings
162
+	save_firewall_settings
163
+
164
+	OPEN_PORTS+=("SIP      $SIP_PORT")
165
+	OPEN_PORTS+=("SIP TLS  $SIP_TLS_PORT")
166
+	echo 'configure_firewall_for_sip4' >> $COMPLETION_FILE
167 167
 }
168 168
 
169 169
 function get_sip_server_password {
170
-    if [ -f /home/$MY_USERNAME/README ]; then
171
-	if grep -q "SIP server password" /home/$MY_USERNAME/README; then
172
-	    if [ ! $SIP_SERVER_PASSWORD ]; then
173
-		SIP_SERVER_PASSWORD=$(cat /home/$MY_USERNAME/README | grep "SIP server password" | awk -F ':' '{print $2}' | sed 's/^ *//')
174
-	    fi
170
+	if [ -f /home/$MY_USERNAME/README ]; then
171
+		if grep -q "SIP server password" /home/$MY_USERNAME/README; then
172
+			if [ ! $SIP_SERVER_PASSWORD ]; then
173
+				SIP_SERVER_PASSWORD=$(cat /home/$MY_USERNAME/README | grep "SIP server password" | awk -F ':' '{print $2}' | sed 's/^ *//')
174
+			fi
175
+		fi
175 176
 	fi
176
-    fi
177 177
 }
178 178
 
179 179
 function update_sipwitch_daemon {
180
-    if [ ! -f /etc/init.d/sipwitch ]; then
181
-	return
182
-    fi
183
-    service sipwitch stop
184
-
185
-    # remove the original sipwitch daemon if it exists
186
-    if [ -f /etc/init.d/sipwitch ]; then
187
-	rm -f /etc/init.d/sipwitch
188
-    fi
189
-
190
-    # daemon
191
-    echo '[Unit]' > /etc/systemd/system/sipwitch.service
192
-    echo 'Description=GNU SIP Witch, a SIP telephony service daemon.' >> /etc/systemd/system/sipwitch.service
193
-    echo 'After=network.target' >> /etc/systemd/system/sipwitch.service
194
-    echo '' >> /etc/systemd/system/sipwitch.service
195
-    echo '[Service]' >> /etc/systemd/system/sipwitch.service
196
-    echo 'Type=simple' >> /etc/systemd/system/sipwitch.service
197
-    echo 'Group=sipwitch' >> /etc/systemd/system/sipwitch.service
198
-    echo 'PIDFile=/var/run/sipwitch/pidfile' >> /etc/systemd/system/sipwitch.service
199
-    echo 'EnvironmentFile=-/etc/conf.d/sipwitch' >> /etc/systemd/system/sipwitch.service
200
-    echo 'EnvironmentFile=-/etc/sipwitch.conf' >> /etc/systemd/system/sipwitch.service
201
-    echo 'EnvironmentFile=-/etc/default/sipwitch' >> /etc/systemd/system/sipwitch.service
202
-    echo 'ExecStartPre=-/bin/rm -f /var/run/sipwitch/control' >> /etc/systemd/system/sipwitch.service
203
-    echo "ExecStart=/usr/sbin/sipw -f \$OPTIONS -P$SIP_PORT" >> /etc/systemd/system/sipwitch.service
204
-    echo 'Restart=always' >> /etc/systemd/system/sipwitch.service
205
-    echo 'NotifyAccess=main' >> /etc/systemd/system/sipwitch.service
206
-    echo '' >> /etc/systemd/system/sipwitch.service
207
-    echo '[Install]' >> /etc/systemd/system/sipwitch.service
208
-    echo 'WantedBy=multi-user.target' >> /etc/systemd/system/sipwitch.service
209
-
210
-    systemctl enable sipwitch
211
-    systemctl daemon-reload
212
-    systemctl start sipwitch
180
+	if [ ! -f /etc/init.d/sipwitch ]; then
181
+		return
182
+	fi
183
+	service sipwitch stop
184
+
185
+	# remove the original sipwitch daemon if it exists
186
+	if [ -f /etc/init.d/sipwitch ]; then
187
+		rm -f /etc/init.d/sipwitch
188
+	fi
189
+
190
+	# daemon
191
+	echo '[Unit]' > /etc/systemd/system/sipwitch.service
192
+	echo 'Description=GNU SIP Witch, a SIP telephony service daemon.' >> /etc/systemd/system/sipwitch.service
193
+	echo 'After=network.target' >> /etc/systemd/system/sipwitch.service
194
+	echo '' >> /etc/systemd/system/sipwitch.service
195
+	echo '[Service]' >> /etc/systemd/system/sipwitch.service
196
+	echo 'Type=simple' >> /etc/systemd/system/sipwitch.service
197
+	echo 'Group=sipwitch' >> /etc/systemd/system/sipwitch.service
198
+	echo 'PIDFile=/var/run/sipwitch/pidfile' >> /etc/systemd/system/sipwitch.service
199
+	echo 'EnvironmentFile=-/etc/conf.d/sipwitch' >> /etc/systemd/system/sipwitch.service
200
+	echo 'EnvironmentFile=-/etc/sipwitch.conf' >> /etc/systemd/system/sipwitch.service
201
+	echo 'EnvironmentFile=-/etc/default/sipwitch' >> /etc/systemd/system/sipwitch.service
202
+	echo 'ExecStartPre=-/bin/rm -f /var/run/sipwitch/control' >> /etc/systemd/system/sipwitch.service
203
+	echo "ExecStart=/usr/sbin/sipw -f \$OPTIONS -P$SIP_PORT" >> /etc/systemd/system/sipwitch.service
204
+	echo 'Restart=always' >> /etc/systemd/system/sipwitch.service
205
+	echo 'NotifyAccess=main' >> /etc/systemd/system/sipwitch.service
206
+	echo '' >> /etc/systemd/system/sipwitch.service
207
+	echo '[Install]' >> /etc/systemd/system/sipwitch.service
208
+	echo 'WantedBy=multi-user.target' >> /etc/systemd/system/sipwitch.service
209
+
210
+	systemctl enable sipwitch
211
+	systemctl daemon-reload
212
+	systemctl start sipwitch
213 213
 }
214 214
 
215 215
 function install_sip_main {
216
-    if grep -Fxq "install_sip_main" $COMPLETION_FILE; then
217
-	return
218
-    fi
216
+	if grep -Fxq "install_sip_main" $COMPLETION_FILE; then
217
+		return
218
+	fi
219 219
 
220
-    apt-get -y install sipwitch
220
+	apt-get -y install sipwitch
221 221
 
222
-    function_check get_sip_server_password
223
-    get_sip_server_password
224
-    if [ ! $SIP_SERVER_PASSWORD ]; then
225
-	if [ -f $IMAGE_PASSWORD_FILE ]; then
226
-	    SIP_SERVER_PASSWORD="$(printf `cat $IMAGE_PASSWORD_FILE`)"
227
-	else
228
-	    SIP_SERVER_PASSWORD="$(create_password ${MINIMUM_PASSWORD_LENGTH})"
222
+	function_check get_sip_server_password
223
+	get_sip_server_password
224
+	if [ ! $SIP_SERVER_PASSWORD ]; then
225
+		if [ -f $IMAGE_PASSWORD_FILE ]; then
226
+			SIP_SERVER_PASSWORD="$(printf `cat $IMAGE_PASSWORD_FILE`)"
227
+		else
228
+			SIP_SERVER_PASSWORD="$(create_password ${MINIMUM_PASSWORD_LENGTH})"
229
+		fi
230
+	fi
231
+
232
+	echo '<?xml version="1.0"?>' > /etc/sipwitch.conf
233
+	echo '<sipwitch>' >> /etc/sipwitch.conf
234
+	echo '<provision>' >> /etc/sipwitch.conf
235
+
236
+	echo "<user id=\"$MY_USERNAME\">" >> /etc/sipwitch.conf
237
+	echo '<extension>201</extension>' >> /etc/sipwitch.conf
238
+	echo "<secret>$SIP_SERVER_PASSWORD</secret>" >> /etc/sipwitch.conf
239
+	echo "<display>$MY_USERNAME 201</display>" >> /etc/sipwitch.conf
240
+	echo '</user>' >> /etc/sipwitch.conf
241
+
242
+	echo '</provision>' >> /etc/sipwitch.conf
243
+	echo '<access>' >> /etc/sipwitch.conf
244
+	echo '</access>' >> /etc/sipwitch.conf
245
+	echo '<stack>' >> /etc/sipwitch.conf
246
+	echo "  <localnames>$DEFAULT_DOMAIN_NAME</localnames>" >> /etc/sipwitch.conf
247
+	echo '  <mapped>200</mapped>' >> /etc/sipwitch.conf
248
+	echo '  <threading>2</threading>' >> /etc/sipwitch.conf
249
+	echo '  <interface>*</interface>' >> /etc/sipwitch.conf
250
+	echo '  <dumping>false</dumping>' >> /etc/sipwitch.conf
251
+	echo '  <system>system</system>' >> /etc/sipwitch.conf
252
+	echo '  <anon>anonymous</anon>' >> /etc/sipwitch.conf
253
+	echo '</stack>' >> /etc/sipwitch.conf
254
+	echo '<timers>' >> /etc/sipwitch.conf
255
+	echo '  <!-- ring every 4 seconds -->' >> /etc/sipwitch.conf
256
+	echo '  <ring>4</ring>' >> /etc/sipwitch.conf
257
+	echo '  <!-- call forward no answer after x rings -->' >> /etc/sipwitch.conf
258
+	echo '  <cfna>4</cfna>' >> /etc/sipwitch.conf
259
+	echo '  <!-- call reset to clear cid in stack, 6 seconds -->' >> /etc/sipwitch.conf
260
+	echo '  <reset>6</reset>' >> /etc/sipwitch.conf
261
+	echo '</timers>' >> /etc/sipwitch.conf
262
+	echo '<!-- we have 2xx numbers plus space for external users -->' >> /etc/sipwitch.conf
263
+	echo '<registry>' >> /etc/sipwitch.conf
264
+	echo '  <prefix>200</prefix>' >> /etc/sipwitch.conf
265
+	echo '  <range>100</range>' >> /etc/sipwitch.conf
266
+	echo '  <keysize>77</keysize>' >> /etc/sipwitch.conf
267
+	echo '  <mapped>200</mapped>' >> /etc/sipwitch.conf
268
+	echo '  <!-- <realm>GNU Telephony</realm> -->' >> /etc/sipwitch.conf
269
+	echo '</registry>' >> /etc/sipwitch.conf
270
+	echo '<routing>' >> /etc/sipwitch.conf
271
+	echo '</routing>' >> /etc/sipwitch.conf
272
+	echo '</sipwitch>' >> /etc/sipwitch.conf
273
+
274
+	sed -i 's|#PLUGINS=|PLUGINS=|g' /etc/default/sipwitch
275
+	sed -i 's|PLUGINS=.*|PLUGINS="zeroconf subscriber forward"|g' /etc/default/sipwitch
276
+	groupadd sipwitch
277
+	usermod -aG sipwitch $MY_USERNAME
278
+
279
+	SIP_ONION_HOSTNAME=$(add_onion_service sip ${SIP_PORT} ${SIP_PORT})
280
+	if ! grep -q $"SIP onion domain" $COMPLETION_FILE; then
281
+		echo "SIP onion domain:$SIP_ONION_HOSTNAME" >> $COMPLETION_FILE
229 282
 	fi
230
-    fi
231
-
232
-    echo '<?xml version="1.0"?>' > /etc/sipwitch.conf
233
-    echo '<sipwitch>' >> /etc/sipwitch.conf
234
-    echo '<provision>' >> /etc/sipwitch.conf
235
-
236
-    echo "<user id=\"$MY_USERNAME\">" >> /etc/sipwitch.conf
237
-    echo '<extension>201</extension>' >> /etc/sipwitch.conf
238
-    echo "<secret>$SIP_SERVER_PASSWORD</secret>" >> /etc/sipwitch.conf
239
-    echo "<display>$MY_USERNAME 201</display>" >> /etc/sipwitch.conf
240
-    echo '</user>' >> /etc/sipwitch.conf
241
-
242
-    echo '</provision>' >> /etc/sipwitch.conf
243
-    echo '<access>' >> /etc/sipwitch.conf
244
-    echo '</access>' >> /etc/sipwitch.conf
245
-    echo '<stack>' >> /etc/sipwitch.conf
246
-    echo "  <localnames>$DEFAULT_DOMAIN_NAME</localnames>" >> /etc/sipwitch.conf
247
-    echo '  <mapped>200</mapped>' >> /etc/sipwitch.conf
248
-    echo '  <threading>2</threading>' >> /etc/sipwitch.conf
249
-    echo '  <interface>*</interface>' >> /etc/sipwitch.conf
250
-    echo '  <dumping>false</dumping>' >> /etc/sipwitch.conf
251
-    echo '  <system>system</system>' >> /etc/sipwitch.conf
252
-    echo '  <anon>anonymous</anon>' >> /etc/sipwitch.conf
253
-    echo '</stack>' >> /etc/sipwitch.conf
254
-    echo '<timers>' >> /etc/sipwitch.conf
255
-    echo '  <!-- ring every 4 seconds -->' >> /etc/sipwitch.conf
256
-    echo '  <ring>4</ring>' >> /etc/sipwitch.conf
257
-    echo '  <!-- call forward no answer after x rings -->' >> /etc/sipwitch.conf
258
-    echo '  <cfna>4</cfna>' >> /etc/sipwitch.conf
259
-    echo '  <!-- call reset to clear cid in stack, 6 seconds -->' >> /etc/sipwitch.conf
260
-    echo '  <reset>6</reset>' >> /etc/sipwitch.conf
261
-    echo '</timers>' >> /etc/sipwitch.conf
262
-    echo '<!-- we have 2xx numbers plus space for external users -->' >> /etc/sipwitch.conf
263
-    echo '<registry>' >> /etc/sipwitch.conf
264
-    echo '  <prefix>200</prefix>' >> /etc/sipwitch.conf
265
-    echo '  <range>100</range>' >> /etc/sipwitch.conf
266
-    echo '  <keysize>77</keysize>' >> /etc/sipwitch.conf
267
-    echo '  <mapped>200</mapped>' >> /etc/sipwitch.conf
268
-    echo '  <!-- <realm>GNU Telephony</realm> -->' >> /etc/sipwitch.conf
269
-    echo '</registry>' >> /etc/sipwitch.conf
270
-    echo '<routing>' >> /etc/sipwitch.conf
271
-    echo '</routing>' >> /etc/sipwitch.conf
272
-    echo '</sipwitch>' >> /etc/sipwitch.conf
273
-
274
-    sed -i 's|#PLUGINS=|PLUGINS=|g' /etc/default/sipwitch
275
-    sed -i 's|PLUGINS=.*|PLUGINS="zeroconf subscriber forward"|g' /etc/default/sipwitch
276
-    groupadd sipwitch
277
-    usermod -aG sipwitch $MY_USERNAME
278
-
279
-    SIP_ONION_HOSTNAME=$(add_onion_service sip ${SIP_PORT} ${SIP_PORT})
280
-    if ! grep -q $"SIP onion domain" $COMPLETION_FILE; then
281
-	echo "SIP onion domain:$SIP_ONION_HOSTNAME" >> $COMPLETION_FILE
282
-    fi
283
-
284
-    if ! grep -q $"SIP Server" /home/$MY_USERNAME/README; then
285
-	echo '' >> /home/$MY_USERNAME/README
286
-	echo '' >> /home/$MY_USERNAME/README
287
-	echo $'SIP Server' >> /home/$MY_USERNAME/README
288
-	echo '==========' >> /home/$MY_USERNAME/README
289
-	echo $"SIP onion_domain: $SIP_ONION_HOSTNAME" >> /home/$MY_USERNAME/README
290
-	echo $"SIP server username: $MY_USERNAME" >> /home/$MY_USERNAME/README
291
-	echo $"SIP server extension: 201" >> /home/$MY_USERNAME/README
292
-	echo $"SIP server password: $SIP_SERVER_PASSWORD" >> /home/$MY_USERNAME/README
293
-	chown $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/README
294
-	chmod 600 /home/$MY_USERNAME/README
295
-    fi
296
-
297
-    function_check configure_firewall_for_sip4
298
-    configure_firewall_for_sip4
299
-    echo 'install_sip_main' >> $COMPLETION_FILE
283
+
284
+	if ! grep -q $"SIP Server" /home/$MY_USERNAME/README; then
285
+		echo '' >> /home/$MY_USERNAME/README
286
+		echo '' >> /home/$MY_USERNAME/README
287
+		echo $'SIP Server' >> /home/$MY_USERNAME/README
288
+		echo '==========' >> /home/$MY_USERNAME/README
289
+		echo $"SIP onion_domain: $SIP_ONION_HOSTNAME" >> /home/$MY_USERNAME/README
290
+		echo $"SIP server username: $MY_USERNAME" >> /home/$MY_USERNAME/README
291
+		echo $"SIP server extension: 201" >> /home/$MY_USERNAME/README
292
+		echo $"SIP server password: $SIP_SERVER_PASSWORD" >> /home/$MY_USERNAME/README
293
+		chown $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/README
294
+		chmod 600 /home/$MY_USERNAME/README
295
+	fi
296
+
297
+	function_check configure_firewall_for_sip4
298
+	configure_firewall_for_sip4
299
+	echo 'install_sip_main' >> $COMPLETION_FILE
300 300
 }
301 301
 
302 302
 function install_sip_turn {
303
-    if grep -Fxq "install_sip_turn" $COMPLETION_FILE; then
304
-	return
305
-    fi
306
-
307
-    apt-get -y install turnserver
308
-
309
-    # create a nonce if needed
310
-    if [ ! $VOIP_TURN_NONCE ]; then
311
-	VOIP_TURN_NONCE="$(create_password 30)"
312
-    fi
313
-
314
-    function_check create_site_certificate
315
-    create_site_certificate $DEFAULT_DOMAIN_NAME
316
-
317
-    echo '##' > /etc/turnserver/turnserver.conf
318
-    echo '# TurnServer configuration file.' >> /etc/turnserver/turnserver.conf
319
-    echo '#' >> /etc/turnserver/turnserver.conf
320
-    echo '' >> /etc/turnserver/turnserver.conf
321
-    echo '## Public IPv4 address of any relayed address (if not set, no relay for IPv4).' >> /etc/turnserver/turnserver.conf
322
-    echo '## To have multiple address, separate addresses with a comma' >> /etc/turnserver/turnserver.conf
323
-    echo '## (i.e. listen_address = { "172.16.0.1", "172.17.0.1" }).' >> /etc/turnserver/turnserver.conf
324
-    echo "listen_address = { \"192.168.0.1\" }" >> /etc/turnserver/turnserver.conf
325
-    echo '' >> /etc/turnserver/turnserver.conf
326
-    echo '## Public IPv6 address of any relayed address (if not set, no relay for IPv6).' >> /etc/turnserver/turnserver.conf
327
-    echo '## To have multiple address, separate address with a comma' >> /etc/turnserver/turnserver.conf
328
-    echo '## (i.e. listen_addressv6 = { "2001:db8:1::1", "2001:db8:2::1" }).' >> /etc/turnserver/turnserver.conf
329
-    echo "#listen_addressv6 = { \"2001:db8::1\" }" >> /etc/turnserver/turnserver.conf
330
-    echo '' >> /etc/turnserver/turnserver.conf
331
-    echo '## UDP listening port.' >> /etc/turnserver/turnserver.conf
332
-    echo "udp_port = $VOIP_TURN_PORT" >> /etc/turnserver/turnserver.conf
333
-    echo '' >> /etc/turnserver/turnserver.conf
334
-    echo '## TCP listening port.' >> /etc/turnserver/turnserver.conf
335
-    echo "tcp_port = $VOIP_TURN_PORT" >> /etc/turnserver/turnserver.conf
336
-    echo '' >> /etc/turnserver/turnserver.conf
337
-    echo '## TLS listening port.' >> /etc/turnserver/turnserver.conf
338
-    echo "tls_port = $VOIP_TURN_TLS_PORT" >> /etc/turnserver/turnserver.conf
339
-    echo '' >> /etc/turnserver/turnserver.conf
340
-    echo '## TLS support.' >> /etc/turnserver/turnserver.conf
341
-    echo 'tls = true' >> /etc/turnserver/turnserver.conf
342
-    echo '' >> /etc/turnserver/turnserver.conf
343
-    echo '## DTLS support. It is an experimental feature and is not defined in TURN' >> /etc/turnserver/turnserver.conf
344
-    echo '## standard.' >> /etc/turnserver/turnserver.conf
345
-    echo 'dtls = false' >> /etc/turnserver/turnserver.conf
346
-    echo '' >> /etc/turnserver/turnserver.conf
347
-    echo '## Maximum allocation port number.' >> /etc/turnserver/turnserver.conf
348
-    echo 'max_port = 65535' >> /etc/turnserver/turnserver.conf
349
-    echo '' >> /etc/turnserver/turnserver.conf
350
-    echo '## Minimum allocation port number.' >> /etc/turnserver/turnserver.conf
351
-    echo '' >> /etc/turnserver/turnserver.conf
352
-    echo 'min_port = 49152' >> /etc/turnserver/turnserver.conf
353
-    echo '' >> /etc/turnserver/turnserver.conf
354
-    echo '## TURN-TCP support.' >> /etc/turnserver/turnserver.conf
355
-    echo '' >> /etc/turnserver/turnserver.conf
356
-    echo 'turn_tcp = true' >> /etc/turnserver/turnserver.conf
357
-    echo '' >> /etc/turnserver/turnserver.conf
358
-    echo '## TURN-TCP buffering mode:' >> /etc/turnserver/turnserver.conf
359
-    echo '## - true, use userspace buffering;' >> /etc/turnserver/turnserver.conf
360
-    echo '## - false, use kernel buffering.' >> /etc/turnserver/turnserver.conf
361
-    echo 'tcp_buffer_userspace = true' >> /etc/turnserver/turnserver.conf
362
-    echo '' >> /etc/turnserver/turnserver.conf
363
-    echo '## TURN-TCP maximum buffer size.' >> /etc/turnserver/turnserver.conf
364
-    echo 'tcp_buffer_size = 32768' >> /etc/turnserver/turnserver.conf
365
-    echo '' >> /etc/turnserver/turnserver.conf
366
-    echo '## Daemon mode.' >> /etc/turnserver/turnserver.conf
367
-    echo 'daemon = true' >> /etc/turnserver/turnserver.conf
368
-    echo '' >> /etc/turnserver/turnserver.conf
369
-    echo '## Unprivileged user.' >> /etc/turnserver/turnserver.conf
370
-    echo '## If you want to use this feature create a system user.' >> /etc/turnserver/turnserver.conf
371
-    echo '## On Linux: adduser --system --group turnserver' >> /etc/turnserver/turnserver.conf
372
-    echo 'unpriv_user = turnserver' >> /etc/turnserver/turnserver.conf
373
-    echo '' >> /etc/turnserver/turnserver.conf
374
-    echo '## Realm value.' >> /etc/turnserver/turnserver.conf
375
-    echo "realm = \"$DEFAULT_DOMAIN_NAME\"" >> /etc/turnserver/turnserver.conf
376
-    echo '' >> /etc/turnserver/turnserver.conf
377
-    echo '## Nonce key.' >> /etc/turnserver/turnserver.conf
378
-    echo "nonce_key = \"$VOIP_TURN_NONCE\"" >> /etc/turnserver/turnserver.conf
379
-    echo '' >> /etc/turnserver/turnserver.conf
380
-    echo '## Max relay per username.' >> /etc/turnserver/turnserver.conf
381
-    echo 'max_relay_per_username = 5' >> /etc/turnserver/turnserver.conf
382
-    echo '' >> /etc/turnserver/turnserver.conf
383
-    echo '## Allocation lifetime.' >> /etc/turnserver/turnserver.conf
384
-    echo 'allocation_lifetime = 1800' >> /etc/turnserver/turnserver.conf
385
-    echo '' >> /etc/turnserver/turnserver.conf
386
-    echo '## Allocation bandwidth limitation (in KBytes/s).' >> /etc/turnserver/turnserver.conf
387
-    echo '## 0 value means bandwidth quota disabled.' >> /etc/turnserver/turnserver.conf
388
-    echo 'bandwidth_per_allocation = 150' >> /etc/turnserver/turnserver.conf
389
-    echo '' >> /etc/turnserver/turnserver.conf
390
-    echo '## Restricted user bandwidth (in KBytes/s).' >> /etc/turnserver/turnserver.conf
391
-    echo '## 0 value means bandwidth limitation disabled.' >> /etc/turnserver/turnserver.conf
392
-    echo 'restricted_bandwidth = 10' >> /etc/turnserver/turnserver.conf
393
-    echo '' >> /etc/turnserver/turnserver.conf
394
-    echo '## Denied addresses.' >> /etc/turnserver/turnserver.conf
395
-    echo '' >> /etc/turnserver/turnserver.conf
396
-    echo '# disallow relaying to localhost' >> /etc/turnserver/turnserver.conf
397
-    echo 'denied_address {' >> /etc/turnserver/turnserver.conf
398
-    echo '  address = "127.0.0.1"' >> /etc/turnserver/turnserver.conf
399
-    echo '  mask = "8"' >> /etc/turnserver/turnserver.conf
400
-    echo '  port = 0' >> /etc/turnserver/turnserver.conf
401
-    echo '}' >> /etc/turnserver/turnserver.conf
402
-    echo '' >> /etc/turnserver/turnserver.conf
403
-    echo '# disallow relaying to ip6-localhost' >> /etc/turnserver/turnserver.conf
404
-    echo 'denied_address {' >> /etc/turnserver/turnserver.conf
405
-    echo '  address = "::1"' >> /etc/turnserver/turnserver.conf
406
-    echo '  mask = "128"' >> /etc/turnserver/turnserver.conf
407
-    echo '  port = 0' >> /etc/turnserver/turnserver.conf
408
-    echo '}' >> /etc/turnserver/turnserver.conf
409
-    echo '' >> /etc/turnserver/turnserver.conf
410
-    echo '## Certification Authority file.' >> /etc/turnserver/turnserver.conf
411
-    echo "ca_file = \"/etc/ssl/certs/ca-certificates.crt\"" >> /etc/turnserver/turnserver.conf
412
-    echo '' >> /etc/turnserver/turnserver.conf
413
-    echo '## Server certificate file.' >> /etc/turnserver/turnserver.conf
414
-    if [ -f /etc/ssl/certs/$DEFAULT_DOMAIN_NAME.pem ]; then
415
-	echo "cert_file = \"/etc/ssl/certs/$DEFAULT_DOMAIN_NAME.pem\"" >> /etc/turnserver/turnserver.conf
416
-    else
417
-	if [ -f /etc/ssl/certs/$DEFAULT_DOMAIN_NAME.crt ]; then
418
-	    echo "cert_file = \"/etc/ssl/certs/$DEFAULT_DOMAIN_NAME.crt\"" >> /etc/turnserver/turnserver.conf
303
+	if grep -Fxq "install_sip_turn" $COMPLETION_FILE; then
304
+		return
419 305
 	fi
420
-    fi
421
-    echo '' >> /etc/turnserver/turnserver.conf
422
-    echo '## Private key file.' >> /etc/turnserver/turnserver.conf
423
-    echo "private_key_file = \"/etc/ssl/certs/$DEFAULT_DOMAIN_NAME.key\"" >> /etc/turnserver/turnserver.conf
424
-    echo '' >> /etc/turnserver/turnserver.conf
425
-    echo '## Account method.' >> /etc/turnserver/turnserver.conf
426
-    echo "account_method = \"file\"" >> /etc/turnserver/turnserver.conf
427
-    echo '' >> /etc/turnserver/turnserver.conf
428
-    echo '## Account file (if account_method = file).' >> /etc/turnserver/turnserver.conf
429
-    echo "account_file = \"/etc/turnserver/turnusers.txt\"" >> /etc/turnserver/turnserver.conf
430
-    echo '' >> /etc/turnserver/turnserver.conf
431
-    echo '## mod_tmpuser.' >> /etc/turnserver/turnserver.conf
432
-    echo 'mod_tmpuser = false' >> /etc/turnserver/turnserver.conf
433
-
434
-    echo "${MY_USERNAME}:password:${DEFAULT_DOMAIN_NAME}:authorized" > /etc/turnserver/turnusers.txt
435
-
436
-    systemctl restart turnserver
437
-
438
-    function_check configure_firewall_for_voip_turn
439
-    configure_firewall_for_voip_turn
440
-    echo 'install_sip_turn' >> $COMPLETION_FILE
306
+
307
+	apt-get -y install turnserver
308
+
309
+	# create a nonce if needed
310
+	if [ ! $VOIP_TURN_NONCE ]; then
311
+		VOIP_TURN_NONCE="$(create_password 30)"
312
+	fi
313
+
314
+	function_check create_site_certificate
315
+	create_site_certificate $DEFAULT_DOMAIN_NAME
316
+
317
+	echo '##' > /etc/turnserver/turnserver.conf
318
+	echo '# TurnServer configuration file.' >> /etc/turnserver/turnserver.conf
319
+	echo '#' >> /etc/turnserver/turnserver.conf
320
+	echo '' >> /etc/turnserver/turnserver.conf
321
+	echo '## Public IPv4 address of any relayed address (if not set, no relay for IPv4).' >> /etc/turnserver/turnserver.conf
322
+	echo '## To have multiple address, separate addresses with a comma' >> /etc/turnserver/turnserver.conf
323
+	echo '## (i.e. listen_address = { "172.16.0.1", "172.17.0.1" }).' >> /etc/turnserver/turnserver.conf
324
+	echo "listen_address = { \"192.168.0.1\" }" >> /etc/turnserver/turnserver.conf
325
+	echo '' >> /etc/turnserver/turnserver.conf
326
+	echo '## Public IPv6 address of any relayed address (if not set, no relay for IPv6).' >> /etc/turnserver/turnserver.conf
327
+	echo '## To have multiple address, separate address with a comma' >> /etc/turnserver/turnserver.conf
328
+	echo '## (i.e. listen_addressv6 = { "2001:db8:1::1", "2001:db8:2::1" }).' >> /etc/turnserver/turnserver.conf
329
+	echo "#listen_addressv6 = { \"2001:db8::1\" }" >> /etc/turnserver/turnserver.conf
330
+	echo '' >> /etc/turnserver/turnserver.conf
331
+	echo '## UDP listening port.' >> /etc/turnserver/turnserver.conf
332
+	echo "udp_port = $VOIP_TURN_PORT" >> /etc/turnserver/turnserver.conf
333
+	echo '' >> /etc/turnserver/turnserver.conf
334
+	echo '## TCP listening port.' >> /etc/turnserver/turnserver.conf
335
+	echo "tcp_port = $VOIP_TURN_PORT" >> /etc/turnserver/turnserver.conf
336
+	echo '' >> /etc/turnserver/turnserver.conf
337
+	echo '## TLS listening port.' >> /etc/turnserver/turnserver.conf
338
+	echo "tls_port = $VOIP_TURN_TLS_PORT" >> /etc/turnserver/turnserver.conf
339
+	echo '' >> /etc/turnserver/turnserver.conf
340
+	echo '## TLS support.' >> /etc/turnserver/turnserver.conf
341
+	echo 'tls = true' >> /etc/turnserver/turnserver.conf
342
+	echo '' >> /etc/turnserver/turnserver.conf
343
+	echo '## DTLS support. It is an experimental feature and is not defined in TURN' >> /etc/turnserver/turnserver.conf
344
+	echo '## standard.' >> /etc/turnserver/turnserver.conf
345
+	echo 'dtls = false' >> /etc/turnserver/turnserver.conf
346
+	echo '' >> /etc/turnserver/turnserver.conf
347
+	echo '## Maximum allocation port number.' >> /etc/turnserver/turnserver.conf
348
+	echo 'max_port = 65535' >> /etc/turnserver/turnserver.conf
349
+	echo '' >> /etc/turnserver/turnserver.conf
350
+	echo '## Minimum allocation port number.' >> /etc/turnserver/turnserver.conf
351
+	echo '' >> /etc/turnserver/turnserver.conf
352
+	echo 'min_port = 49152' >> /etc/turnserver/turnserver.conf
353
+	echo '' >> /etc/turnserver/turnserver.conf
354
+	echo '## TURN-TCP support.' >> /etc/turnserver/turnserver.conf
355
+	echo '' >> /etc/turnserver/turnserver.conf
356
+	echo 'turn_tcp = true' >> /etc/turnserver/turnserver.conf
357
+	echo '' >> /etc/turnserver/turnserver.conf
358
+	echo '## TURN-TCP buffering mode:' >> /etc/turnserver/turnserver.conf
359
+	echo '## - true, use userspace buffering;' >> /etc/turnserver/turnserver.conf
360
+	echo '## - false, use kernel buffering.' >> /etc/turnserver/turnserver.conf
361
+	echo 'tcp_buffer_userspace = true' >> /etc/turnserver/turnserver.conf
362
+	echo '' >> /etc/turnserver/turnserver.conf
363
+	echo '## TURN-TCP maximum buffer size.' >> /etc/turnserver/turnserver.conf
364
+	echo 'tcp_buffer_size = 32768' >> /etc/turnserver/turnserver.conf
365
+	echo '' >> /etc/turnserver/turnserver.conf
366
+	echo '## Daemon mode.' >> /etc/turnserver/turnserver.conf
367
+	echo 'daemon = true' >> /etc/turnserver/turnserver.conf
368
+	echo '' >> /etc/turnserver/turnserver.conf
369
+	echo '## Unprivileged user.' >> /etc/turnserver/turnserver.conf
370
+	echo '## If you want to use this feature create a system user.' >> /etc/turnserver/turnserver.conf
371
+	echo '## On Linux: adduser --system --group turnserver' >> /etc/turnserver/turnserver.conf
372
+	echo 'unpriv_user = turnserver' >> /etc/turnserver/turnserver.conf
373
+	echo '' >> /etc/turnserver/turnserver.conf
374
+	echo '## Realm value.' >> /etc/turnserver/turnserver.conf
375
+	echo "realm = \"$DEFAULT_DOMAIN_NAME\"" >> /etc/turnserver/turnserver.conf
376
+	echo '' >> /etc/turnserver/turnserver.conf
377
+	echo '## Nonce key.' >> /etc/turnserver/turnserver.conf
378
+	echo "nonce_key = \"$VOIP_TURN_NONCE\"" >> /etc/turnserver/turnserver.conf
379
+	echo '' >> /etc/turnserver/turnserver.conf
380
+	echo '## Max relay per username.' >> /etc/turnserver/turnserver.conf
381
+	echo 'max_relay_per_username = 5' >> /etc/turnserver/turnserver.conf
382
+	echo '' >> /etc/turnserver/turnserver.conf
383
+	echo '## Allocation lifetime.' >> /etc/turnserver/turnserver.conf
384
+	echo 'allocation_lifetime = 1800' >> /etc/turnserver/turnserver.conf
385
+	echo '' >> /etc/turnserver/turnserver.conf
386
+	echo '## Allocation bandwidth limitation (in KBytes/s).' >> /etc/turnserver/turnserver.conf
387
+	echo '## 0 value means bandwidth quota disabled.' >> /etc/turnserver/turnserver.conf
388
+	echo 'bandwidth_per_allocation = 150' >> /etc/turnserver/turnserver.conf
389
+	echo '' >> /etc/turnserver/turnserver.conf
390
+	echo '## Restricted user bandwidth (in KBytes/s).' >> /etc/turnserver/turnserver.conf
391
+	echo '## 0 value means bandwidth limitation disabled.' >> /etc/turnserver/turnserver.conf
392
+	echo 'restricted_bandwidth = 10' >> /etc/turnserver/turnserver.conf
393
+	echo '' >> /etc/turnserver/turnserver.conf
394
+	echo '## Denied addresses.' >> /etc/turnserver/turnserver.conf
395
+	echo '' >> /etc/turnserver/turnserver.conf
396
+	echo '# disallow relaying to localhost' >> /etc/turnserver/turnserver.conf
397
+	echo 'denied_address {' >> /etc/turnserver/turnserver.conf
398
+	echo '  address = "127.0.0.1"' >> /etc/turnserver/turnserver.conf
399
+	echo '  mask = "8"' >> /etc/turnserver/turnserver.conf
400
+	echo '  port = 0' >> /etc/turnserver/turnserver.conf
401
+	echo '}' >> /etc/turnserver/turnserver.conf
402
+	echo '' >> /etc/turnserver/turnserver.conf
403
+	echo '# disallow relaying to ip6-localhost' >> /etc/turnserver/turnserver.conf
404
+	echo 'denied_address {' >> /etc/turnserver/turnserver.conf
405
+	echo '  address = "::1"' >> /etc/turnserver/turnserver.conf
406
+	echo '  mask = "128"' >> /etc/turnserver/turnserver.conf
407
+	echo '  port = 0' >> /etc/turnserver/turnserver.conf
408
+	echo '}' >> /etc/turnserver/turnserver.conf
409
+	echo '' >> /etc/turnserver/turnserver.conf
410
+	echo '## Certification Authority file.' >> /etc/turnserver/turnserver.conf
411
+	echo "ca_file = \"/etc/ssl/certs/ca-certificates.crt\"" >> /etc/turnserver/turnserver.conf
412
+	echo '' >> /etc/turnserver/turnserver.conf
413
+	echo '## Server certificate file.' >> /etc/turnserver/turnserver.conf
414
+	if [ -f /etc/ssl/certs/$DEFAULT_DOMAIN_NAME.pem ]; then
415
+		echo "cert_file = \"/etc/ssl/certs/$DEFAULT_DOMAIN_NAME.pem\"" >> /etc/turnserver/turnserver.conf
416
+	else
417
+		if [ -f /etc/ssl/certs/$DEFAULT_DOMAIN_NAME.crt ]; then
418
+			echo "cert_file = \"/etc/ssl/certs/$DEFAULT_DOMAIN_NAME.crt\"" >> /etc/turnserver/turnserver.conf
419
+		fi
420
+	fi
421
+	echo '' >> /etc/turnserver/turnserver.conf
422
+	echo '## Private key file.' >> /etc/turnserver/turnserver.conf
423
+	echo "private_key_file = \"/etc/ssl/certs/$DEFAULT_DOMAIN_NAME.key\"" >> /etc/turnserver/turnserver.conf
424
+	echo '' >> /etc/turnserver/turnserver.conf
425
+	echo '## Account method.' >> /etc/turnserver/turnserver.conf
426
+	echo "account_method = \"file\"" >> /etc/turnserver/turnserver.conf
427
+	echo '' >> /etc/turnserver/turnserver.conf
428
+	echo '## Account file (if account_method = file).' >> /etc/turnserver/turnserver.conf
429
+	echo "account_file = \"/etc/turnserver/turnusers.txt\"" >> /etc/turnserver/turnserver.conf
430
+	echo '' >> /etc/turnserver/turnserver.conf
431
+	echo '## mod_tmpuser.' >> /etc/turnserver/turnserver.conf
432
+	echo 'mod_tmpuser = false' >> /etc/turnserver/turnserver.conf
433
+
434
+	echo "${MY_USERNAME}:password:${DEFAULT_DOMAIN_NAME}:authorized" > /etc/turnserver/turnusers.txt
435
+
436
+	systemctl restart turnserver
437
+
438
+	function_check configure_firewall_for_voip_turn
439
+	configure_firewall_for_voip_turn
440
+	echo 'install_sip_turn' >> $COMPLETION_FILE
441 441
 }
442 442
 
443 443
 function install_sip {
444
-    if grep -Fxq "install_sip" $COMPLETION_FILE; then
445
-	return
446
-    fi
447
-    install_sip_main
448
-    update_sipwitch_daemon
449
-    echo 'install_sip' >> $COMPLETION_FILE
444
+	if grep -Fxq "install_sip" $COMPLETION_FILE; then
445
+		return
446
+	fi
447
+	install_sip_main
448
+	update_sipwitch_daemon
449
+	echo 'install_sip' >> $COMPLETION_FILE
450 450
 }
451 451
 
452 452
 # NOTE: deliberately no exit 0

+ 251
- 251
src/freedombone-app-syncthing Parādīt failu

@@ -40,300 +40,300 @@ SYNCTHING_SHARED_DATA=/var/lib/syncthing/SyncShared
40 40
 SYNCTHING_USER_IDS_FILE='.syncthingids'
41 41
 
42 42
 function reconfigure_syncthing {
43
-    echo -n ''
43
+	echo -n ''
44 44
 }
45 45
 
46 46
 function upgrade_syncthing {
47
-    echo -n ''
47
+	echo -n ''
48 48
 }
49 49
 
50 50
 function backup_local_syncthing {
51
-    if [ -d /var/lib/syncthing/SyncShared ]; then
52
-	echo $"Backing up syncthing"
51
+	if [ -d /var/lib/syncthing/SyncShared ]; then
52
+		echo $"Backing up syncthing"
53 53
 
54
-	function_check backup_directory_to_usb
55
-	backup_directory_to_usb /var/lib/syncthing/SyncShared syncthingshared
56
-	backup_directory_to_usb /root/.config/syncthing syncthingconfig
54
+		function_check backup_directory_to_usb
55
+		backup_directory_to_usb /var/lib/syncthing/SyncShared syncthingshared
56
+		backup_directory_to_usb /root/.config/syncthing syncthingconfig
57 57
 
58
-	echo $"Backup to syncthing complete"
59
-    fi
58
+		echo $"Backup to syncthing complete"
59
+	fi
60 60
 }
61 61
 
62 62
 function restore_local_syncthing {
63
-    if [ -f /etc/systemd/system/syncthing.service ]; then
64
-	systemctl stop syncthing
65
-	systemctl stop cron
66
-    fi
67
-
68
-    temp_restore_dir=/root/tempsyncthing
69
-    if [ -d $USB_MOUNT/backup/syncthingconfig ]; then
70
-	echo $"Restoring syncthing configuration"
71
-	function_check restore_directory_from_usb
72
-	restore_directory_from_usb ${temp_restore_dir}config syncthingconfig
73
-	cp -r ${temp_restore_dir}config/* /
74
-	if [ ! "$?" = "0" ]; then
75
-	    set_user_permissions
76
-	    backup_unmount_drive
77
-	    systemctl start syncthing
78
-	    systemctl start cron
79
-	    exit 6833
80
-	fi
81
-	rm -rf ${temp_restore_dir}config
82
-    fi
83
-
84
-    if [ -d $USB_MOUNT/backup/syncthingshared ]; then
85
-	echo $"Restoring syncthing shared files"
86
-	restore_directory_from_usb ${temp_restore_dir}shared syncthingshared
87
-	cp -r ${temp_restore_dir}shared/* /
88
-	if [ ! "$?" = "0" ]; then
89
-	    set_user_permissions
90
-	    backup_unmount_drive
91
-	    systemctl start syncthing
92
-	    systemctl start cron
93
-	    exit 37904
63
+	if [ -f /etc/systemd/system/syncthing.service ]; then
64
+		systemctl stop syncthing
65
+		systemctl stop cron
94 66
 	fi
95
-	rm -rf ${temp_restore_dir}shared
96
-    fi
97
-
98
-    if [ -d $USB_MOUNT/backup/syncthing ]; then
99
-	for d in $USB_MOUNT/backup/syncthing/*/ ; do
100
-	    USERNAME=$(echo "$d" | awk -F '/' '{print $6}')
101
-	    if [[ $USERNAME != "git" && $USERNAME != "mirrors" && $USERNAME != "sync" ]]; then
102
-		if [ ! -d /home/$USERNAME ]; then
103
-		    ${PROJECT_NAME}-adduser $USERNAME
104
-		fi
105
-		echo $"Restoring syncthing files for $USERNAME"
106
-		restore_directory_from_usb ${temp_restore_dir} syncthing/$USERNAME
107
-		cp -r ${temp_restore_dir}/home/$USERNAME/Sync /home/$USERNAME/
67
+
68
+	temp_restore_dir=/root/tempsyncthing
69
+	if [ -d $USB_MOUNT/backup/syncthingconfig ]; then
70
+		echo $"Restoring syncthing configuration"
71
+		function_check restore_directory_from_usb
72
+		restore_directory_from_usb ${temp_restore_dir}config syncthingconfig
73
+		cp -r ${temp_restore_dir}config/* /
108 74
 		if [ ! "$?" = "0" ]; then
109
-		    rm -rf ${temp_restore_dir}
110
-		    set_user_permissions
111
-		    backup_unmount_drive
112
-		    systemctl start syncthing
113
-		    systemctl start cron
114
-		    exit 68438
75
+			set_user_permissions
76
+			backup_unmount_drive
77
+			systemctl start syncthing
78
+			systemctl start cron
79
+			exit 6833
115 80
 		fi
116
-		rm -rf ${temp_restore_dir}
81
+		rm -rf ${temp_restore_dir}config
82
+	fi
117 83
 
118
-		# restore device IDs from config settings
119
-		if [ -f /home/$USERNAME/.config/syncthing/.syncthing-server-id ]; then
120
-		    cp /home/$USERNAME/.config/syncthing/.syncthing-server-id /home/$USERNAME/.syncthing-server-id
121
-		    chown $USERNAME:$USERNAME /home/$USERNAME/.syncthing-server-id
122
-		fi
123
-		if [ -f /home/$USERNAME/.config/syncthing/.syncthingids ]; then
124
-		    cp /home/$USERNAME/.config/syncthing/.syncthingids /home/$USERNAME/.syncthingids
125
-		    chown $USERNAME:$USERNAME /home/$USERNAME/.syncthingids
84
+	if [ -d $USB_MOUNT/backup/syncthingshared ]; then
85
+		echo $"Restoring syncthing shared files"
86
+		restore_directory_from_usb ${temp_restore_dir}shared syncthingshared
87
+		cp -r ${temp_restore_dir}shared/* /
88
+		if [ ! "$?" = "0" ]; then
89
+			set_user_permissions
90
+			backup_unmount_drive
91
+			systemctl start syncthing
92
+			systemctl start cron
93
+			exit 37904
126 94
 		fi
127
-	    fi
128
-	done
129
-    fi
95
+		rm -rf ${temp_restore_dir}shared
96
+	fi
130 97
 
131
-    if [ -f /etc/systemd/system/syncthing.service ]; then
132
-	systemctl start syncthing
133
-	systemctl start cron
134
-    fi
98
+	if [ -d $USB_MOUNT/backup/syncthing ]; then
99
+		for d in $USB_MOUNT/backup/syncthing/*/ ; do
100
+			USERNAME=$(echo "$d" | awk -F '/' '{print $6}')
101
+			if [[ $USERNAME != "git" && $USERNAME != "mirrors" && $USERNAME != "sync" ]]; then
102
+				if [ ! -d /home/$USERNAME ]; then
103
+					${PROJECT_NAME}-adduser $USERNAME
104
+				fi
105
+				echo $"Restoring syncthing files for $USERNAME"
106
+				restore_directory_from_usb ${temp_restore_dir} syncthing/$USERNAME
107
+				cp -r ${temp_restore_dir}/home/$USERNAME/Sync /home/$USERNAME/
108
+				if [ ! "$?" = "0" ]; then
109
+					rm -rf ${temp_restore_dir}
110
+					set_user_permissions
111
+					backup_unmount_drive
112
+					systemctl start syncthing
113
+					systemctl start cron
114
+					exit 68438
115
+				fi
116
+				rm -rf ${temp_restore_dir}
117
+
118
+				# restore device IDs from config settings
119
+				if [ -f /home/$USERNAME/.config/syncthing/.syncthing-server-id ]; then
120
+					cp /home/$USERNAME/.config/syncthing/.syncthing-server-id /home/$USERNAME/.syncthing-server-id
121
+					chown $USERNAME:$USERNAME /home/$USERNAME/.syncthing-server-id
122
+				fi
123
+				if [ -f /home/$USERNAME/.config/syncthing/.syncthingids ]; then
124
+					cp /home/$USERNAME/.config/syncthing/.syncthingids /home/$USERNAME/.syncthingids
125
+					chown $USERNAME:$USERNAME /home/$USERNAME/.syncthingids
126
+				fi
127
+			fi
128
+		done
129
+	fi
130
+
131
+	if [ -f /etc/systemd/system/syncthing.service ]; then
132
+		systemctl start syncthing
133
+		systemctl start cron
134
+	fi
135 135
 }
136 136
 
137 137
 function backup_remote_syncthing {
138
-    if [ -d /root/.config/syncthing ]; then
139
-	echo $"Backing up syncthing configuration"
140
-	function_check backup_directory_to_friend
141
-	backup_directory_to_friend /root/.config/syncthing syncthingconfig
142
-	echo $"Backup of syncthing configuration complete"
143
-    fi
144
-    if [ -d /var/lib/syncthing/SyncShared ]; then
145
-	echo $"Backing up syncthing shared files"
146
-	function_check backup_directory_to_friend
147
-	backup_directory_to_friend /var/lib/syncthing/SyncShared syncthingshared
148
-	echo $"Backup of syncthing shared files complete"
149
-    fi
138
+	if [ -d /root/.config/syncthing ]; then
139
+		echo $"Backing up syncthing configuration"
140
+		function_check backup_directory_to_friend
141
+		backup_directory_to_friend /root/.config/syncthing syncthingconfig
142
+		echo $"Backup of syncthing configuration complete"
143
+	fi
144
+	if [ -d /var/lib/syncthing/SyncShared ]; then
145
+		echo $"Backing up syncthing shared files"
146
+		function_check backup_directory_to_friend
147
+		backup_directory_to_friend /var/lib/syncthing/SyncShared syncthingshared
148
+		echo $"Backup of syncthing shared files complete"
149
+	fi
150 150
 }
151 151
 
152 152
 function restore_remote_syncthing {
153
-    if [ -f /etc/systemd/system/syncthing.service ]; then
154
-	systemctl stop syncthing
155
-	systemctl stop cron
156
-    fi
157
-
158
-    if [ -d $SERVER_DIRECTORY/backup/syncthingconfig ]; then
159
-	echo $"Restoring syncthing configuration"
160
-	temp_restore_dir=/root/tempsyncthingconfig
161
-	function_check restore_directory_from_friend
162
-	restore_directory_from_friend $temp_restore_dir syncthingconfig
163
-	cp -r $temp_restore_dir/* /
164
-	if [ ! "$?" = "0" ]; then
165
-	    systemctl start syncthing
166
-	    systemctl start cron
167
-	    exit 6833
168
-	fi
169
-	rm -rf $temp_restore_dir
170
-    fi
171
-
172
-    if [ -d $SERVER_DIRECTORY/backup/syncthingshared ]; then
173
-	echo $"Restoring syncthing shared files"
174
-	temp_restore_dir=/root/tempsyncthingshared
175
-	function_check restore_directory_from_friend
176
-	restore_directory_from_friend $temp_restore_dir syncthingshared
177
-	cp -r $temp_restore_dir/* /
178
-	if [ ! "$?" = "0" ]; then
179
-	    systemctl start syncthing
180
-	    systemctl start cron
181
-	    exit 37904
153
+	if [ -f /etc/systemd/system/syncthing.service ]; then
154
+		systemctl stop syncthing
155
+		systemctl stop cron
182 156
 	fi
183
-	rm -rf $temp_restore_dir
184
-    fi
185
-
186
-    if [ -d $SERVER_DIRECTORY/backup/syncthing ]; then
187
-	for d in $SERVER_DIRECTORY/backup/syncthing/*/ ; do
188
-	    USERNAME=$(echo "$d" | awk -F '/' '{print $6}')
189
-	    if [[ $USERNAME != "git" && $USERNAME != "mirrors" && $USERNAME != "sync" ]]; then
190
-		if [ ! -d /home/$USERNAME ]; then
191
-		    ${PROJECT_NAME}-adduser $USERNAME
192
-		fi
193
-		echo $"Restoring syncthing files for $USERNAME"
194
-		temp_restore_dir=/root/tempsyncthing
157
+
158
+	if [ -d $SERVER_DIRECTORY/backup/syncthingconfig ]; then
159
+		echo $"Restoring syncthing configuration"
160
+		temp_restore_dir=/root/tempsyncthingconfig
195 161
 		function_check restore_directory_from_friend
196
-		restore_directory_from_friend $temp_restore_dir syncthing/$USERNAME
197
-		cp -r $temp_restore_dir/home/$USERNAME/Sync /home/$USERNAME/
162
+		restore_directory_from_friend $temp_restore_dir syncthingconfig
163
+		cp -r $temp_restore_dir/* /
198 164
 		if [ ! "$?" = "0" ]; then
199
-		    rm -rf $temp_restore_dir
200
-		    systemctl start syncthing
201
-		    systemctl start cron
202
-		    exit 68438
165
+			systemctl start syncthing
166
+			systemctl start cron
167
+			exit 6833
203 168
 		fi
204 169
 		rm -rf $temp_restore_dir
170
+	fi
205 171
 
206
-		# restore device IDs from config settings
207
-		if [ -f /home/$USERNAME/.config/syncthing/.syncthing-server-id ]; then
208
-		    cp /home/$USERNAME/.config/syncthing/.syncthing-server-id /home/$USERNAME/.syncthing-server-id
209
-		    chown $USERNAME:$USERNAME /home/$USERNAME/.syncthing-server-id
210
-		fi
211
-		if [ -f /home/$USERNAME/.config/syncthing/.syncthingids ]; then
212
-		    cp /home/$USERNAME/.config/syncthing/.syncthingids /home/$USERNAME/.syncthingids
213
-		    chown $USERNAME:$USERNAME /home/$USERNAME/.syncthingids
172
+	if [ -d $SERVER_DIRECTORY/backup/syncthingshared ]; then
173
+		echo $"Restoring syncthing shared files"
174
+		temp_restore_dir=/root/tempsyncthingshared
175
+		function_check restore_directory_from_friend
176
+		restore_directory_from_friend $temp_restore_dir syncthingshared
177
+		cp -r $temp_restore_dir/* /
178
+		if [ ! "$?" = "0" ]; then
179
+			systemctl start syncthing
180
+			systemctl start cron
181
+			exit 37904
214 182
 		fi
215
-		echo $"Restore of syncthing files for $USERNAME complete"
216
-	    fi
217
-	done
218
-    fi
183
+		rm -rf $temp_restore_dir
184
+	fi
219 185
 
220
-    if [ -f /etc/systemd/system/syncthing.service ]; then
221
-	systemctl start syncthing
222
-	systemctl start cron
223
-    fi
186
+	if [ -d $SERVER_DIRECTORY/backup/syncthing ]; then
187
+		for d in $SERVER_DIRECTORY/backup/syncthing/*/ ; do
188
+			USERNAME=$(echo "$d" | awk -F '/' '{print $6}')
189
+			if [[ $USERNAME != "git" && $USERNAME != "mirrors" && $USERNAME != "sync" ]]; then
190
+				if [ ! -d /home/$USERNAME ]; then
191
+					${PROJECT_NAME}-adduser $USERNAME
192
+				fi
193
+				echo $"Restoring syncthing files for $USERNAME"
194
+				temp_restore_dir=/root/tempsyncthing
195
+				function_check restore_directory_from_friend
196
+				restore_directory_from_friend $temp_restore_dir syncthing/$USERNAME
197
+				cp -r $temp_restore_dir/home/$USERNAME/Sync /home/$USERNAME/
198
+				if [ ! "$?" = "0" ]; then
199
+					rm -rf $temp_restore_dir
200
+					systemctl start syncthing
201
+					systemctl start cron
202
+					exit 68438
203
+				fi
204
+				rm -rf $temp_restore_dir
205
+
206
+				# restore device IDs from config settings
207
+				if [ -f /home/$USERNAME/.config/syncthing/.syncthing-server-id ]; then
208
+					cp /home/$USERNAME/.config/syncthing/.syncthing-server-id /home/$USERNAME/.syncthing-server-id
209
+					chown $USERNAME:$USERNAME /home/$USERNAME/.syncthing-server-id
210
+				fi
211
+				if [ -f /home/$USERNAME/.config/syncthing/.syncthingids ]; then
212
+					cp /home/$USERNAME/.config/syncthing/.syncthingids /home/$USERNAME/.syncthingids
213
+					chown $USERNAME:$USERNAME /home/$USERNAME/.syncthingids
214
+				fi
215
+				echo $"Restore of syncthing files for $USERNAME complete"
216
+			fi
217
+		done
218
+	fi
219
+
220
+	if [ -f /etc/systemd/system/syncthing.service ]; then
221
+		systemctl start syncthing
222
+		systemctl start cron
223
+	fi
224 224
 }
225 225
 
226 226
 function remove_syncthing {
227
-    if ! grep -Fxq "install_syncthing" $COMPLETION_FILE; then
228
-	return
229
-    fi
230
-    iptables -D INPUT -p udp --dport $SYNCTHING_PORT -j ACCEPT
231
-    iptables -D INPUT -p tcp --dport $SYNCTHING_PORT -j ACCEPT
232
-    function_check save_firewall_settings
233
-    save_firewall_settings
234
-
235
-    systemctl stop syncthing
236
-    systemctl disable syncthing
237
-    apt-get -y remove --purge syncthing
238
-    rm /etc/systemd/system/syncthing.service
239
-    sed -i "/${PROJECT_NAME}-syncthing/d" /etc/crontab
240
-    sed -i '/install_syncthing/d' $COMPLETION_FILE
241
-    sed -i '/configure_firewall_for_syncthing/d' $COMPLETION_FILE
242
-    systemctl restart cron
227
+	if ! grep -Fxq "install_syncthing" $COMPLETION_FILE; then
228
+		return
229
+	fi
230
+	iptables -D INPUT -p udp --dport $SYNCTHING_PORT -j ACCEPT
231
+	iptables -D INPUT -p tcp --dport $SYNCTHING_PORT -j ACCEPT
232
+	function_check save_firewall_settings
233
+	save_firewall_settings
234
+
235
+	systemctl stop syncthing
236
+	systemctl disable syncthing
237
+	apt-get -y remove --purge syncthing
238
+	rm /etc/systemd/system/syncthing.service
239
+	sed -i "/${PROJECT_NAME}-syncthing/d" /etc/crontab
240
+	sed -i '/install_syncthing/d' $COMPLETION_FILE
241
+	sed -i '/configure_firewall_for_syncthing/d' $COMPLETION_FILE
242
+	systemctl restart cron
243 243
 }
244 244
 
245 245
 function configure_firewall_for_syncthing {
246
-    if grep -Fxq "configure_firewall_for_syncthing" $COMPLETION_FILE; then
247
-	return
248
-    fi
249
-    iptables -A INPUT -p udp --dport $SYNCTHING_PORT -j ACCEPT
250
-    iptables -A INPUT -p tcp --dport $SYNCTHING_PORT -j ACCEPT
251
-    function_check save_firewall_settings
252
-    save_firewall_settings
253
-
254
-    OPEN_PORTS+=("Syncthing $SYNCTHING_PORT")
255
-    echo 'configure_firewall_for_syncthing' >> $COMPLETION_FILE
246
+	if grep -Fxq "configure_firewall_for_syncthing" $COMPLETION_FILE; then
247
+		return
248
+	fi
249
+	iptables -A INPUT -p udp --dport $SYNCTHING_PORT -j ACCEPT
250
+	iptables -A INPUT -p tcp --dport $SYNCTHING_PORT -j ACCEPT
251
+	function_check save_firewall_settings
252
+	save_firewall_settings
253
+
254
+	OPEN_PORTS+=("Syncthing $SYNCTHING_PORT")
255
+	echo 'configure_firewall_for_syncthing' >> $COMPLETION_FILE
256 256
 }
257 257
 
258 258
 function mesh_install_syncthing {
259
-    chroot "$rootdir" wget -q https://syncthing.net/release-key.txt -O- | apt-key add -
260
-
261
-    echo "deb http://apt.syncthing.net/ syncthing release" | tee $rootdir/etc/apt/sources.list.d/syncthing.list
262
-    chroot "$rootdir" apt-get update
263
-    chroot "$rootdir" apt-get -y --force-yes install syncthing
264
-
265
-    # This probably does need to run as root so that it can access the Sync directories
266
-    # in each user's home directory
267
-    echo '[Unit]' > $rootdir/etc/systemd/system/syncthing.service
268
-    echo 'Description=Syncthing - Open Source Continuous File Synchronization' >> $rootdir/etc/systemd/system/syncthing.service
269
-    echo 'Documentation=man:syncthing(1)' >> $rootdir/etc/systemd/system/syncthing.service
270
-    echo 'After=network.target' >> $rootdir/etc/systemd/system/syncthing.service
271
-    echo 'Wants=syncthing-inotify@.service' >> $rootdir/etc/systemd/system/syncthing.service
272
-    echo '' >> $rootdir/etc/systemd/system/syncthing.service
273
-    echo '[Service]' >> $rootdir/etc/systemd/system/syncthing.service
274
-    echo 'User=root' >> $rootdir/etc/systemd/system/syncthing.service
275
-    echo "Environment='all_proxy=socks5://localhost:9050'" >> $rootdir/etc/systemd/system/syncthing.service
276
-    echo 'ExecStart=/usr/bin/syncthing -no-browser -no-restart -logflags=0' >> $rootdir/etc/systemd/system/syncthing.service
277
-    echo 'Restart=on-failure' >> $rootdir/etc/systemd/system/syncthing.service
278
-    echo 'SuccessExitStatus=3 4' >> $rootdir/etc/systemd/system/syncthing.service
279
-    echo 'RestartForceExitStatus=3 4' >> $rootdir/etc/systemd/system/syncthing.service
280
-    echo '' >> $rootdir/etc/systemd/system/syncthing.service
281
-    echo '[Install]' >> $rootdir/etc/systemd/system/syncthing.service
282
-    echo 'WantedBy=multi-user.target' >> $rootdir/etc/systemd/system/syncthing.service
283
-    chroot "$rootdir" systemctl enable syncthing
284
-
285
-    if ! grep -q "syncthing" $rootdir/etc/crontab; then
286
-	echo "*/1            * *   *   *   root /usr/local/bin/${PROJECT_NAME}-syncthing > /dev/null" >> $rootdir/etc/crontab
287
-    fi
288
-
289
-    echo 'mesh_install_syncthing'
259
+	chroot "$rootdir" wget -q https://syncthing.net/release-key.txt -O- | apt-key add -
260
+
261
+	echo "deb http://apt.syncthing.net/ syncthing release" | tee $rootdir/etc/apt/sources.list.d/syncthing.list
262
+	chroot "$rootdir" apt-get update
263
+	chroot "$rootdir" apt-get -y --force-yes install syncthing
264
+
265
+	# This probably does need to run as root so that it can access the Sync directories
266
+	# in each user's home directory
267
+	echo '[Unit]' > $rootdir/etc/systemd/system/syncthing.service
268
+	echo 'Description=Syncthing - Open Source Continuous File Synchronization' >> $rootdir/etc/systemd/system/syncthing.service
269
+	echo 'Documentation=man:syncthing(1)' >> $rootdir/etc/systemd/system/syncthing.service
270
+	echo 'After=network.target' >> $rootdir/etc/systemd/system/syncthing.service
271
+	echo 'Wants=syncthing-inotify@.service' >> $rootdir/etc/systemd/system/syncthing.service
272
+	echo '' >> $rootdir/etc/systemd/system/syncthing.service
273
+	echo '[Service]' >> $rootdir/etc/systemd/system/syncthing.service
274
+	echo 'User=root' >> $rootdir/etc/systemd/system/syncthing.service
275
+	echo "Environment='all_proxy=socks5://localhost:9050'" >> $rootdir/etc/systemd/system/syncthing.service
276
+	echo 'ExecStart=/usr/bin/syncthing -no-browser -no-restart -logflags=0' >> $rootdir/etc/systemd/system/syncthing.service
277
+	echo 'Restart=on-failure' >> $rootdir/etc/systemd/system/syncthing.service
278
+	echo 'SuccessExitStatus=3 4' >> $rootdir/etc/systemd/system/syncthing.service
279
+	echo 'RestartForceExitStatus=3 4' >> $rootdir/etc/systemd/system/syncthing.service
280
+	echo '' >> $rootdir/etc/systemd/system/syncthing.service
281
+	echo '[Install]' >> $rootdir/etc/systemd/system/syncthing.service
282
+	echo 'WantedBy=multi-user.target' >> $rootdir/etc/systemd/system/syncthing.service
283
+	chroot "$rootdir" systemctl enable syncthing
284
+
285
+	if ! grep -q "syncthing" $rootdir/etc/crontab; then
286
+		echo "*/1            * *   *   *   root /usr/local/bin/${PROJECT_NAME}-syncthing > /dev/null" >> $rootdir/etc/crontab
287
+	fi
288
+
289
+	echo 'mesh_install_syncthing'
290 290
 }
291 291
 
292 292
 function install_syncthing {
293
-    if [ $INSTALLING_MESH ]; then
294
-	mesh_install_syncthing
295
-	return
296
-    fi
297
-
298
-    if grep -Fxq "install_syncthing" $COMPLETION_FILE; then
299
-	return
300
-    fi
301
-
302
-    apt-get -y install curl
303
-
304
-    curl -s https://syncthing.net/release-key.txt | apt-key add -
305
-    echo "deb http://apt.syncthing.net/ syncthing release" | tee /etc/apt/sources.list.d/syncthing.list
306
-    apt-get update
307
-    apt-get -y install syncthing
308
-
309
-    # This probably does need to run as root so that it can access the Sync directories
310
-    # in each user's home directory
311
-    echo '[Unit]' > /etc/systemd/system/syncthing.service
312
-    echo 'Description=Syncthing - Open Source Continuous File Synchronization' >> /etc/systemd/system/syncthing.service
313
-    echo 'Documentation=man:syncthing(1)' >> /etc/systemd/system/syncthing.service
314
-    echo 'After=network.target' >> /etc/systemd/system/syncthing.service
315
-    echo 'Wants=syncthing-inotify@.service' >> /etc/systemd/system/syncthing.service
316
-    echo '' >> /etc/systemd/system/syncthing.service
317
-    echo '[Service]' >> /etc/systemd/system/syncthing.service
318
-    echo 'User=root' >> /etc/systemd/system/syncthing.service
319
-    echo "Environment='all_proxy=socks5://localhost:9050'" >> /etc/systemd/system/syncthing.service
320
-    echo 'ExecStart=/usr/bin/syncthing -no-browser -no-restart -logflags=0' >> /etc/systemd/system/syncthing.service
321
-    echo 'Restart=on-failure' >> /etc/systemd/system/syncthing.service
322
-    echo 'SuccessExitStatus=3 4' >> /etc/systemd/system/syncthing.service
323
-    echo 'RestartForceExitStatus=3 4' >> /etc/systemd/system/syncthing.service
324
-    echo '' >> /etc/systemd/system/syncthing.service
325
-    echo '[Install]' >> /etc/systemd/system/syncthing.service
326
-    echo 'WantedBy=multi-user.target' >> /etc/systemd/system/syncthing.service
327
-    systemctl enable syncthing
328
-    systemctl daemon-reload
329
-    systemctl start syncthing
330
-
331
-    function_check cron_add_mins
332
-    cron_add_mins 1 "/usr/local/bin/${PROJECT_NAME}-syncthing > /dev/null"
333
-
334
-    function_check configure_firewall_for_syncthing
335
-    configure_firewall_for_syncthing
336
-    echo 'install_syncthing' >> $COMPLETION_FILE
293
+	if [ $INSTALLING_MESH ]; then
294
+		mesh_install_syncthing
295
+		return
296
+	fi
297
+
298
+	if grep -Fxq "install_syncthing" $COMPLETION_FILE; then
299
+		return
300
+	fi
301
+
302
+	apt-get -y install curl
303
+
304
+	curl -s https://syncthing.net/release-key.txt | apt-key add -
305
+	echo "deb http://apt.syncthing.net/ syncthing release" | tee /etc/apt/sources.list.d/syncthing.list
306
+	apt-get update
307
+	apt-get -y install syncthing
308
+
309
+	# This probably does need to run as root so that it can access the Sync directories
310
+	# in each user's home directory
311
+	echo '[Unit]' > /etc/systemd/system/syncthing.service
312
+	echo 'Description=Syncthing - Open Source Continuous File Synchronization' >> /etc/systemd/system/syncthing.service
313
+	echo 'Documentation=man:syncthing(1)' >> /etc/systemd/system/syncthing.service
314
+	echo 'After=network.target' >> /etc/systemd/system/syncthing.service
315
+	echo 'Wants=syncthing-inotify@.service' >> /etc/systemd/system/syncthing.service
316
+	echo '' >> /etc/systemd/system/syncthing.service
317
+	echo '[Service]' >> /etc/systemd/system/syncthing.service
318
+	echo 'User=root' >> /etc/systemd/system/syncthing.service
319
+	echo "Environment='all_proxy=socks5://localhost:9050'" >> /etc/systemd/system/syncthing.service
320
+	echo 'ExecStart=/usr/bin/syncthing -no-browser -no-restart -logflags=0' >> /etc/systemd/system/syncthing.service
321
+	echo 'Restart=on-failure' >> /etc/systemd/system/syncthing.service
322
+	echo 'SuccessExitStatus=3 4' >> /etc/systemd/system/syncthing.service
323
+	echo 'RestartForceExitStatus=3 4' >> /etc/systemd/system/syncthing.service
324
+	echo '' >> /etc/systemd/system/syncthing.service
325
+	echo '[Install]' >> /etc/systemd/system/syncthing.service
326
+	echo 'WantedBy=multi-user.target' >> /etc/systemd/system/syncthing.service
327
+	systemctl enable syncthing
328
+	systemctl daemon-reload
329
+	systemctl start syncthing
330
+
331
+	function_check cron_add_mins
332
+	cron_add_mins 1 "/usr/local/bin/${PROJECT_NAME}-syncthing > /dev/null"
333
+
334
+	function_check configure_firewall_for_syncthing
335
+	configure_firewall_for_syncthing
336
+	echo 'install_syncthing' >> $COMPLETION_FILE
337 337
 }
338 338
 
339 339
 # NOTE: deliberately no exit 0

+ 455
- 455
src/freedombone-app-tox
Failā izmaiņas netiks attēlotas, jo tās ir par lielu
Parādīt failu


+ 23
- 23
src/freedombone-app-vpn Parādīt failu

@@ -31,52 +31,52 @@
31 31
 VARIANTS=''
32 32
 
33 33
 function reconfigure_vpn {
34
-    echo -n ''
34
+	echo -n ''
35 35
 }
36 36
 
37 37
 function upgrade_vpn {
38
-    echo -n ''
38
+	echo -n ''
39 39
 }
40 40
 
41 41
 function backup_local_vpn {
42
-    echo -n ''
42
+	echo -n ''
43 43
 }
44 44
 
45 45
 function restore_local_vpn {
46
-    echo -n ''
46
+	echo -n ''
47 47
 }
48 48
 
49 49
 function backup_remote_vpn {
50
-    echo -n ''
50
+	echo -n ''
51 51
 }
52 52
 
53 53
 function restore_remote_vpn {
54
-    echo -n ''
54
+	echo -n ''
55 55
 }
56 56
 
57 57
 function remove_vpn {
58
-    apt-get -y remove --purge fastd
59
-    sed -i '/install_vpn/d' $COMPLETION_FILE
58
+	apt-get -y remove --purge fastd
59
+	sed -i '/install_vpn/d' $COMPLETION_FILE
60 60
 }
61 61
 
62 62
 function install_vpn {
63
-    if grep -Fxq "install_vpn" $COMPLETION_FILE; then
64
-	return
65
-    fi
66
-    if ! grep -q "repo.universe-factory.net" /etc/apt/sources.list; then
67
-	echo 'deb http://repo.universe-factory.net/debian/ sid main' >> /etc/apt/sources.list
68
-	gpg --keyserver pgpkeys.mit.edu --recv-key 16EF3F64CB201D9C
69
-	if [ ! "$?" = "0" ]; then
70
-	    exit 76272
63
+	if grep -Fxq "install_vpn" $COMPLETION_FILE; then
64
+		return
71 65
 	fi
72
-	gpg -a --export 16EF3F64CB201D9C | sudo apt-key add -
73
-	apt-get update
74
-	apt-get -y install fastd
75
-	if [ ! "$?" = "0" ]; then
76
-	    exit 52026
66
+	if ! grep -q "repo.universe-factory.net" /etc/apt/sources.list; then
67
+		echo 'deb http://repo.universe-factory.net/debian/ sid main' >> /etc/apt/sources.list
68
+		gpg --keyserver pgpkeys.mit.edu --recv-key 16EF3F64CB201D9C
69
+		if [ ! "$?" = "0" ]; then
70
+			exit 76272
71
+		fi
72
+		gpg -a --export 16EF3F64CB201D9C | sudo apt-key add -
73
+		apt-get update
74
+		apt-get -y install fastd
75
+		if [ ! "$?" = "0" ]; then
76
+			exit 52026
77
+		fi
77 78
 	fi
78
-    fi
79
-    echo 'install_vpn' >> $COMPLETION_FILE
79
+	echo 'install_vpn' >> $COMPLETION_FILE
80 80
 }
81 81
 
82 82
 # NOTE: deliberately there is no "exit 0"

+ 389
- 389
src/freedombone-app-wiki Parādīt failu

@@ -37,302 +37,391 @@ WIKI_CODE=
37 37
 WIKI_ONION_PORT=8089
38 38
 
39 39
 function reconfigure_wiki {
40
-    echo -n ''
40
+	echo -n ''
41 41
 }
42 42
 
43 43
 function upgrade_wiki {
44
-    echo -n ''
44
+	echo -n ''
45 45
 }
46 46
 
47 47
 function backup_local_wiki {
48
-    source_directory=/var/lib/dokuwiki
49
-    if [ -d $source_directory ]; then
50
-	dest_directory=wiki
51
-	echo $"Backing up $source_directory to $dest_directory"
48
+	source_directory=/var/lib/dokuwiki
49
+	if [ -d $source_directory ]; then
50
+		dest_directory=wiki
51
+		echo $"Backing up $source_directory to $dest_directory"
52 52
 
53
-	function_check backup_directory_to_usb
54
-	backup_directory_to_usb $source_directory $dest_directory
55
-	backup_directory_to_usb /etc/dokuwiki wiki2
53
+		function_check backup_directory_to_usb
54
+		backup_directory_to_usb $source_directory $dest_directory
55
+		backup_directory_to_usb /etc/dokuwiki wiki2
56 56
 
57
-	echo $"Backup to $dest_directory complete"
58
-    fi
57
+		echo $"Backup to $dest_directory complete"
58
+	fi
59 59
 }
60 60
 
61 61
 function restore_local_wiki {
62
-    if [ -d /var/lib/dokuwiki ]; then
63
-	echo $"Restoring Wiki installation"
64
-	WIKI_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "Wiki domain" | awk -F ':' '{print $2}')
65
-	temp_restore_dir=/root/tempwiki
66
-	function_check restore_directory_from_usb
67
-	restore_directory_from_usb $temp_restore_dir wiki
68
-	cp -r $temp_restore_dir/var/lib/dokuwiki/* /var/lib/dokuwiki/
69
-	if [ ! "$?" = "0" ]; then
70
-	    function_check restore_directory_from_usb
71
-	    set_user_permissions
72
-	    function_check backup_unmount_drive
73
-	    backup_unmount_drive
74
-	    exit 868
75
-	fi
76
-	restore_directory_from_usb ${temp_restore_dir}2 wiki2
77
-	cp -r ${temp_restore_dir}2/etc/dokuwiki/* /etc/dokuwiki/
78
-	if [ ! "$?" = "0" ]; then
79
-	    function_check set_user_permissions
80
-	    set_user_permissions
81
-	    function_check backup_unmount_drive
82
-	    backup_unmount_drive
83
-	    exit 869
84
-	fi
85
-	rm -rf $temp_restore_dir
86
-	rm -rf ${temp_restore_dir}2
87
-	chown -R www-data:www-data /var/lib/dokuwiki/*
88
-	# Ensure that the bundled SSL cert is being used
89
-	if [ -f /etc/ssl/certs/${WIKI_DOMAIN_NAME}.bundle.crt ]; then
90
-	    sed -i "s|${WIKI_DOMAIN_NAME}.crt|${WIKI_DOMAIN_NAME}.bundle.crt|g" /etc/nginx/sites-available/${WIKI_DOMAIN_NAME}
91
-	fi
92
-	if [ -d /etc/letsencrypt/live/${WIKI_DOMAIN_NAME} ]; then
93
-	    ln -s /etc/letsencrypt/live/${WIKI_DOMAIN_NAME}/privkey.pem /etc/ssl/private/${WIKI_DOMAIN_NAME}.key
94
-	    ln -s /etc/letsencrypt/live/${WIKI_DOMAIN_NAME}/fullchain.pem /etc/ssl/certs/${WIKI_DOMAIN_NAME}.pem
62
+	if [ -d /var/lib/dokuwiki ]; then
63
+		echo $"Restoring Wiki installation"
64
+		WIKI_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "Wiki domain" | awk -F ':' '{print $2}')
65
+		temp_restore_dir=/root/tempwiki
66
+		function_check restore_directory_from_usb
67
+		restore_directory_from_usb $temp_restore_dir wiki
68
+		cp -r $temp_restore_dir/var/lib/dokuwiki/* /var/lib/dokuwiki/
69
+		if [ ! "$?" = "0" ]; then
70
+			function_check restore_directory_from_usb
71
+			set_user_permissions
72
+			function_check backup_unmount_drive
73
+			backup_unmount_drive
74
+			exit 868
75
+		fi
76
+		restore_directory_from_usb ${temp_restore_dir}2 wiki2
77
+		cp -r ${temp_restore_dir}2/etc/dokuwiki/* /etc/dokuwiki/
78
+		if [ ! "$?" = "0" ]; then
79
+			function_check set_user_permissions
80
+			set_user_permissions
81
+			function_check backup_unmount_drive
82
+			backup_unmount_drive
83
+			exit 869
84
+		fi
85
+		rm -rf $temp_restore_dir
86
+		rm -rf ${temp_restore_dir}2
87
+		chown -R www-data:www-data /var/lib/dokuwiki/*
88
+		# Ensure that the bundled SSL cert is being used
89
+		if [ -f /etc/ssl/certs/${WIKI_DOMAIN_NAME}.bundle.crt ]; then
90
+			sed -i "s|${WIKI_DOMAIN_NAME}.crt|${WIKI_DOMAIN_NAME}.bundle.crt|g" /etc/nginx/sites-available/${WIKI_DOMAIN_NAME}
91
+		fi
92
+		if [ -d /etc/letsencrypt/live/${WIKI_DOMAIN_NAME} ]; then
93
+			ln -s /etc/letsencrypt/live/${WIKI_DOMAIN_NAME}/privkey.pem /etc/ssl/private/${WIKI_DOMAIN_NAME}.key
94
+			ln -s /etc/letsencrypt/live/${WIKI_DOMAIN_NAME}/fullchain.pem /etc/ssl/certs/${WIKI_DOMAIN_NAME}.pem
95
+		fi
96
+		echo $"Restore of Wiki complete"
95 97
 	fi
96
-	echo $"Restore of Wiki complete"
97
-    fi
98 98
 }
99 99
 
100 100
 function backup_remote_wiki {
101
-    if [ -d /etc/dokuwiki ]; then
102
-	echo $"Backing up wiki"
103
-	backup_directory_to_friend /var/lib/dokuwiki wiki
104
-	backup_directory_to_friend /etc/dokuwiki wiki2
105
-    fi
101
+	if [ -d /etc/dokuwiki ]; then
102
+		echo $"Backing up wiki"
103
+		backup_directory_to_friend /var/lib/dokuwiki wiki
104
+		backup_directory_to_friend /etc/dokuwiki wiki2
105
+	fi
106 106
 }
107 107
 
108 108
 function restore_remote_wiki {
109
-    if [ -d $SERVER_DIRECTORY/backup/wiki ]; then
110
-	WIKI_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "Wiki domain" | awk -F ':' '{print $2}')
111
-	echo $"Restoring Wiki installation $WIKI_DOMAIN_NAME"
112
-	function_check restore_directory_from_friend
113
-	restore_directory_from_friend /root/tempwiki wiki
114
-	cp -r /root/tempwiki/var/lib/dokuwiki/* /var/lib/dokuwiki/
115
-	if [ ! "$?" = "0" ]; then
116
-	    exit 868
117
-	fi
118
-	restore_directory_from_friend /root/tempwiki2 wiki2
119
-	cp -r /root/tempwiki2/etc/dokuwiki/* /etc/dokuwiki/
120
-	if [ ! "$?" = "0" ]; then
121
-	    exit 869
122
-	fi
123
-	rm -rf /root/tempwiki
124
-	rm -rf /root/tempwiki2
125
-	chown -R www-data:www-data /var/lib/dokuwiki/*
126
-	# Ensure that the bundled SSL cert is being used
127
-	if [ -f /etc/ssl/certs/${WIKI_DOMAIN_NAME}.bundle.crt ]; then
128
-	    sed -i "s|${WIKI_DOMAIN_NAME}.crt|${WIKI_DOMAIN_NAME}.bundle.crt|g" /etc/nginx/sites-available/${WIKI_DOMAIN_NAME}
129
-	fi
130
-	if [ -d /etc/letsencrypt/live/${WIKI_DOMAIN_NAME} ]; then
131
-	    ln -s /etc/letsencrypt/live/${WIKI_DOMAIN_NAME}/privkey.pem /etc/ssl/private/${WIKI_DOMAIN_NAME}.key
132
-	    ln -s /etc/letsencrypt/live/${WIKI_DOMAIN_NAME}/fullchain.pem /etc/ssl/certs/${WIKI_DOMAIN_NAME}.pem
109
+	if [ -d $SERVER_DIRECTORY/backup/wiki ]; then
110
+		WIKI_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "Wiki domain" | awk -F ':' '{print $2}')
111
+		echo $"Restoring Wiki installation $WIKI_DOMAIN_NAME"
112
+		function_check restore_directory_from_friend
113
+		restore_directory_from_friend /root/tempwiki wiki
114
+		cp -r /root/tempwiki/var/lib/dokuwiki/* /var/lib/dokuwiki/
115
+		if [ ! "$?" = "0" ]; then
116
+			exit 868
117
+		fi
118
+		restore_directory_from_friend /root/tempwiki2 wiki2
119
+		cp -r /root/tempwiki2/etc/dokuwiki/* /etc/dokuwiki/
120
+		if [ ! "$?" = "0" ]; then
121
+			exit 869
122
+		fi
123
+		rm -rf /root/tempwiki
124
+		rm -rf /root/tempwiki2
125
+		chown -R www-data:www-data /var/lib/dokuwiki/*
126
+		# Ensure that the bundled SSL cert is being used
127
+		if [ -f /etc/ssl/certs/${WIKI_DOMAIN_NAME}.bundle.crt ]; then
128
+			sed -i "s|${WIKI_DOMAIN_NAME}.crt|${WIKI_DOMAIN_NAME}.bundle.crt|g" /etc/nginx/sites-available/${WIKI_DOMAIN_NAME}
129
+		fi
130
+		if [ -d /etc/letsencrypt/live/${WIKI_DOMAIN_NAME} ]; then
131
+			ln -s /etc/letsencrypt/live/${WIKI_DOMAIN_NAME}/privkey.pem /etc/ssl/private/${WIKI_DOMAIN_NAME}.key
132
+			ln -s /etc/letsencrypt/live/${WIKI_DOMAIN_NAME}/fullchain.pem /etc/ssl/certs/${WIKI_DOMAIN_NAME}.pem
133
+		fi
134
+		echo $"Restore of Wiki complete"
133 135
 	fi
134
-	echo $"Restore of Wiki complete"
135
-    fi
136 136
 }
137 137
 
138 138
 function remove_wiki {
139
-    if ! grep -Fxq "install_wiki" $COMPLETION_FILE; then
140
-	return
141
-    fi
142
-    function_check remove_onion_service
143
-    remove_onion_service wiki ${WIKI_ONION_PORT}
144
-    nginx_dissite $WIKI_DOMAIN_NAME
145
-    if [ -f /etc/nginx/sites-available/$WIKI_DOMAIN_NAME ]; then
146
-	rm /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
147
-    fi
148
-    apt-get -y remove --purge dokuwiki
149
-    if [ ! -d /var/www/$WIKI_DOMAIN_NAME ]; then
150
-	rm -rf /var/www/$WIKI_DOMAIN_NAME
151
-    fi
152
-    if [ -d /var/lib/dokuwiki ]; then
153
-	rm -rf /var/lib/dokuwiki
154
-    fi
155
-    if [ -d /etc/dokuwiki ]; then
156
-	rm -rf /etc/dokuwiki
157
-    fi
158
-    if [ -d /usr/share/dokuwiki ]; then
159
-	rm -rf /usr/share/dokuwiki
160
-    fi
161
-    sed -i '/install_wiki/d' $COMPLETION_FILE
139
+	if ! grep -Fxq "install_wiki" $COMPLETION_FILE; then
140
+		return
141
+	fi
142
+	function_check remove_onion_service
143
+	remove_onion_service wiki ${WIKI_ONION_PORT}
144
+	nginx_dissite $WIKI_DOMAIN_NAME
145
+	if [ -f /etc/nginx/sites-available/$WIKI_DOMAIN_NAME ]; then
146
+		rm /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
147
+	fi
148
+	apt-get -y remove --purge dokuwiki
149
+	if [ ! -d /var/www/$WIKI_DOMAIN_NAME ]; then
150
+		rm -rf /var/www/$WIKI_DOMAIN_NAME
151
+	fi
152
+	if [ -d /var/lib/dokuwiki ]; then
153
+		rm -rf /var/lib/dokuwiki
154
+	fi
155
+	if [ -d /etc/dokuwiki ]; then
156
+		rm -rf /etc/dokuwiki
157
+	fi
158
+	if [ -d /usr/share/dokuwiki ]; then
159
+		rm -rf /usr/share/dokuwiki
160
+	fi
161
+	sed -i '/install_wiki/d' $COMPLETION_FILE
162 162
 }
163 163
 
164 164
 function get_wiki_admin_password {
165
-    if [ -f /home/$MY_USERNAME/README ]; then
166
-	if grep -q "Wiki password" /home/$MY_USERNAME/README; then
167
-	    WIKI_ADMIN_PASSWORD=$(cat /home/$MY_USERNAME/README | grep "Wiki password:" | awk -F ':' '{print $2}' | sed 's/^ *//')
165
+	if [ -f /home/$MY_USERNAME/README ]; then
166
+		if grep -q "Wiki password" /home/$MY_USERNAME/README; then
167
+			WIKI_ADMIN_PASSWORD=$(cat /home/$MY_USERNAME/README | grep "Wiki password:" | awk -F ':' '{print $2}' | sed 's/^ *//')
168
+		fi
168 169
 	fi
169
-    fi
170 170
 }
171 171
 
172 172
 function install_wiki {
173
-    if grep -Fxq "install_wiki" $COMPLETION_FILE; then
174
-	return
175
-    fi
176
-    if [ ! $WIKI_DOMAIN_NAME ]; then
177
-	return
178
-    fi
179
-    apt-get -y install dokuwiki
180
-    apt-get -y remove --purge apache*
181
-    if [ -d /etc/apache2 ]; then
182
-	rm -rf /etc/apache2
183
-	echo $'Removed Apache installation after Dokuwiki install'
184
-    fi
185
-
186
-    if [ ! -d /var/www/$WIKI_DOMAIN_NAME ]; then
187
-	mkdir /var/www/$WIKI_DOMAIN_NAME
188
-    fi
189
-    if [ -d /var/www/$WIKI_DOMAIN_NAME/htdocs ]; then
190
-	rm -rf /var/www/$WIKI_DOMAIN_NAME/htdocs
191
-    fi
192
-
193
-    ln -s /usr/share/dokuwiki /var/www/$WIKI_DOMAIN_NAME/htdocs
194
-
195
-    mkdir /var/lib/dokuwiki/custom
196
-    cp /etc/dokuwiki/local.php.dist /var/lib/dokuwiki/custom/local.php
197
-    ln -s /var/lib/dokuwiki/custom/local.php /etc/dokuwiki/local.php
198
-
199
-    chown www-data /var/lib/dokuwiki/custom
200
-    chown www-data /var/lib/dokuwiki/custom/local.php
201
-    chown -R www-data /etc/dokuwiki
202
-    chown -R www-data /usr/share/dokuwiki/lib/
203
-    chmod 600 /var/lib/dokuwiki/custom/local.php
204
-    chmod -R 755 /usr/share/dokuwiki/lib
205
-
206
-    sed -i 's|//$conf|$conf|g' /var/lib/dokuwiki/custom/local.php
207
-    sed -i "s|joe|$MY_USERNAME|g" /var/lib/dokuwiki/custom/local.php
208
-
209
-    sed -i "s|Debian DokuWiki|$WIKI_TITLE|g" /etc/dokuwiki/local.php
210
-
211
-    # set the admin user
212
-    sed -i "s/@admin/$MY_USERNAME/g" /etc/dokuwiki/local.php
213
-
214
-    # disallow registration of new users
215
-    if ! grep -q "disableactions" /etc/dokuwiki/local.php; then
216
-	echo "\$conf['disableactions'] = 'register';" >> /etc/dokuwiki/local.php
217
-    fi
218
-    if ! grep -q "disableactions" /var/lib/dokuwiki/custom/local.php; then
219
-	echo "\$conf['disableactions'] = 'register';" >> /var/lib/dokuwiki/custom/local.php
220
-    fi
221
-
222
-    if ! grep -q "authtype" /var/lib/dokuwiki/custom/local.php; then
223
-	echo "\$conf['authtype'] = 'authplain';" >> /var/lib/dokuwiki/custom/local.php
224
-    fi
225
-    if ! grep -q "authtype" /etc/dokuwiki/local.php; then
226
-	echo "\$conf['authtype'] = 'authplain';" >> /etc/dokuwiki/local.php
227
-    fi
228
-
229
-    function_check get_wiki_admin_password
230
-    get_wiki_admin_password
231
-    if [ ! $WIKI_ADMIN_PASSWORD ]; then
232
-	if [ -f $IMAGE_PASSWORD_FILE ]; then
233
-	    WIKI_ADMIN_PASSWORD="$(printf `cat $IMAGE_PASSWORD_FILE`)"
173
+	if grep -Fxq "install_wiki" $COMPLETION_FILE; then
174
+		return
175
+	fi
176
+	if [ ! $WIKI_DOMAIN_NAME ]; then
177
+		return
178
+	fi
179
+	apt-get -y install dokuwiki
180
+	apt-get -y remove --purge apache*
181
+	if [ -d /etc/apache2 ]; then
182
+		rm -rf /etc/apache2
183
+		echo $'Removed Apache installation after Dokuwiki install'
184
+	fi
185
+
186
+	if [ ! -d /var/www/$WIKI_DOMAIN_NAME ]; then
187
+		mkdir /var/www/$WIKI_DOMAIN_NAME
188
+	fi
189
+	if [ -d /var/www/$WIKI_DOMAIN_NAME/htdocs ]; then
190
+		rm -rf /var/www/$WIKI_DOMAIN_NAME/htdocs
191
+	fi
192
+
193
+	ln -s /usr/share/dokuwiki /var/www/$WIKI_DOMAIN_NAME/htdocs
194
+
195
+	mkdir /var/lib/dokuwiki/custom
196
+	cp /etc/dokuwiki/local.php.dist /var/lib/dokuwiki/custom/local.php
197
+	ln -s /var/lib/dokuwiki/custom/local.php /etc/dokuwiki/local.php
198
+
199
+	chown www-data /var/lib/dokuwiki/custom
200
+	chown www-data /var/lib/dokuwiki/custom/local.php
201
+	chown -R www-data /etc/dokuwiki
202
+	chown -R www-data /usr/share/dokuwiki/lib/
203
+	chmod 600 /var/lib/dokuwiki/custom/local.php
204
+	chmod -R 755 /usr/share/dokuwiki/lib
205
+
206
+	sed -i 's|//$conf|$conf|g' /var/lib/dokuwiki/custom/local.php
207
+	sed -i "s|joe|$MY_USERNAME|g" /var/lib/dokuwiki/custom/local.php
208
+
209
+	sed -i "s|Debian DokuWiki|$WIKI_TITLE|g" /etc/dokuwiki/local.php
210
+
211
+	# set the admin user
212
+	sed -i "s/@admin/$MY_USERNAME/g" /etc/dokuwiki/local.php
213
+
214
+	# disallow registration of new users
215
+	if ! grep -q "disableactions" /etc/dokuwiki/local.php; then
216
+		echo "\$conf['disableactions'] = 'register';" >> /etc/dokuwiki/local.php
217
+	fi
218
+	if ! grep -q "disableactions" /var/lib/dokuwiki/custom/local.php; then
219
+		echo "\$conf['disableactions'] = 'register';" >> /var/lib/dokuwiki/custom/local.php
220
+	fi
221
+
222
+	if ! grep -q "authtype" /var/lib/dokuwiki/custom/local.php; then
223
+		echo "\$conf['authtype'] = 'authplain';" >> /var/lib/dokuwiki/custom/local.php
224
+	fi
225
+	if ! grep -q "authtype" /etc/dokuwiki/local.php; then
226
+		echo "\$conf['authtype'] = 'authplain';" >> /etc/dokuwiki/local.php
227
+	fi
228
+
229
+	function_check get_wiki_admin_password
230
+	get_wiki_admin_password
231
+	if [ ! $WIKI_ADMIN_PASSWORD ]; then
232
+		if [ -f $IMAGE_PASSWORD_FILE ]; then
233
+			WIKI_ADMIN_PASSWORD="$(printf `cat $IMAGE_PASSWORD_FILE`)"
234
+		else
235
+			WIKI_ADMIN_PASSWORD="$(create_password ${MINIMUM_PASSWORD_LENGTH})"
236
+		fi
237
+	fi
238
+	HASHED_WIKI_PASSWORD=$(echo -n "$WIKI_ADMIN_PASSWORD" | md5sum | awk -F ' ' '{print $1}')
239
+	echo -n "$MY_USERNAME:$HASHED_WIKI_PASSWORD:$MY_NAME:$MY_EMAIL:admin,user,upload" > /var/lib/dokuwiki/acl/users.auth.php
240
+	chmod 640 /var/lib/dokuwiki/acl/users.auth.php
241
+
242
+	if ! grep -q "video/ogg" /etc/dokuwiki/mime.conf; then
243
+		echo 'ogv     video/ogg' >> /etc/dokuwiki/mime.conf
244
+	fi
245
+	if ! grep -q "video/mp4" /etc/dokuwiki/mime.conf; then
246
+		echo 'mp4     video/mp4' >> /etc/dokuwiki/mime.conf
247
+	fi
248
+	if ! grep -q "video/webm" /etc/dokuwiki/mime.conf; then
249
+		echo 'webm    video/webm' >> /etc/dokuwiki/mime.conf
250
+	fi
251
+
252
+	WIKI_ONION_HOSTNAME=$(add_onion_service wiki 80 ${WIKI_ONION_PORT})
253
+
254
+	if [[ $ONION_ONLY == "no" ]]; then
255
+		echo 'server {' > /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
256
+		echo '    listen 80;' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
257
+		echo "    root /var/www/$WIKI_DOMAIN_NAME/htdocs;" >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
258
+		echo "    server_name $WIKI_DOMAIN_NAME;" >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
259
+		echo '    access_log off;' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
260
+		echo "    error_log /var/log/nginx/${WIKI_DOMAIN_NAME}_error.log $WEBSERVER_LOG_LEVEL;" >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
261
+		echo '    index index.php;' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
262
+		echo '    charset utf-8;' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
263
+		echo '    proxy_read_timeout 86400s;' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
264
+		echo '' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
265
+		function_check nginx_disable_sniffing
266
+		nginx_disable_sniffing $WIKI_DOMAIN_NAME
267
+		function_check nginx_limits
268
+		nginx_limits $WIKI_DOMAIN_NAME
269
+		echo '    # rewrite to front controller as default rule' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
270
+		echo '    location / {' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
271
+		echo '        rewrite ^/(.*) /index.php?q=$uri&$args last;' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
272
+		echo '    }' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
273
+		echo '' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
274
+		echo "    # make sure webfinger and other well known services aren't blocked" >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
275
+		echo '    # by denying dot files and rewrite request to the front controller' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
276
+		echo '    location ^~ /.well-known/ {' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
277
+		echo '        allow all;' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
278
+		echo '    }' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
279
+		echo '' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
280
+		echo '    # statically serve these file types when possible' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
281
+		echo '    # otherwise fall back to front controller' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
282
+		echo '    # allow browser to cache them' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
283
+		echo '    # added .htm for advanced source code editor library' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
284
+		echo '    location ~* \.(jpg|jpeg|gif|png|ico|css|js|htm|html|ttf|woff|svg)$ {' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
285
+		echo '        expires 30d;' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
286
+		echo '        try_files $uri /index.php?q=$uri&$args;' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
287
+		echo '    }' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
288
+		echo '' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
289
+		echo '    # block these file types' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
290
+		echo '    location ~* \.(tpl|md|tgz|log|out)$ {' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
291
+		echo '        deny all;' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
292
+		echo '    }' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
293
+		echo '' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
294
+		echo '    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
295
+		echo '    # or a unix socket' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
296
+		echo '    location ~* \.php$ {' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
297
+		echo '        # Zero-day exploit defense.' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
298
+		echo '        # http://forum.nginx.org/read.php?2,88845,page=3' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
299
+		echo "        # Won't work properly (404 error) if the file is not stored on this" >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
300
+		echo "        # server, which is entirely possible with php-fpm/php-fcgi." >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
301
+		echo "        # Comment the 'try_files' line out if you set up php-fpm/php-fcgi on" >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
302
+		echo "        # another machine. And then cross your fingers that you won't get hacked." >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
303
+		echo '        try_files $uri $uri/ /index.php;' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
304
+		echo '        # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
305
+		echo '        fastcgi_split_path_info ^(.+\.php)(/.+)$;' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
306
+		echo '        # With php5-cgi alone:' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
307
+		echo '        # fastcgi_pass 127.0.0.1:9000;' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
308
+		echo '        # With php5-fpm:' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
309
+		echo '        fastcgi_pass unix:/var/run/php5-fpm.sock;' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
310
+		echo '        include fastcgi_params;' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
311
+		echo '        fastcgi_index index.php;' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
312
+		echo '        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
313
+		echo '    }' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
314
+		echo '' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
315
+		echo '    # deny access to all dot files' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
316
+		echo '    location ~ /\. {' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
317
+		echo '        deny all;' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
318
+		echo '    }' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
319
+		echo '' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
320
+		echo '    #deny access to store' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
321
+		echo '    location ~ /store {' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
322
+		echo '        deny all;' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
323
+		echo '    }' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
324
+		echo '    location ~ /(data|conf|bin|inc)/ {' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
325
+		echo '      deny all;' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
326
+		echo '    }' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
327
+		echo '    location ~ /\.ht {' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
328
+		echo '      deny  all;' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
329
+		echo '    }' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
330
+		echo '}' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
331
+		echo '' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
332
+		echo 'server {' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
333
+		echo '    listen 443 ssl;' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
334
+		echo "    root /var/www/$WIKI_DOMAIN_NAME/htdocs;" >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
335
+		echo "    server_name $WIKI_DOMAIN_NAME;" >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
336
+		echo '    access_log off;' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
337
+		echo "    error_log /var/log/nginx/${WIKI_DOMAIN_NAME}_error_ssl.log $WEBSERVER_LOG_LEVEL;" >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
338
+		echo '    index index.php;' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
339
+		echo '    charset utf-8;' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
340
+		echo '    proxy_read_timeout 86400s;' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
341
+		function_check nginx_limits
342
+		nginx_limits $WIKI_DOMAIN_NAME
343
+		function_check nginx_ssl
344
+		nginx_ssl $WIKI_DOMAIN_NAME
345
+		function_check nginx_disable_sniffing
346
+		nginx_disable_sniffing $WIKI_DOMAIN_NAME
347
+		echo '    add_header Strict-Transport-Security "max-age=0;";' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
348
+		echo '' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
349
+		echo '    # webmail' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
350
+		echo '    location /webmail {' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
351
+		echo '        rewrite ^/(.*) /webmail/index.php last;' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
352
+		echo '        rewrite ^/(.*) /webmail/installer/index.php last;' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
353
+		echo '    }' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
354
+		echo '' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
355
+		echo '    # rewrite to front controller as default rule' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
356
+		echo '    location / {' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
357
+		echo '        rewrite ^/(.*) /index.php?q=$uri&$args last;' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
358
+		echo '    }' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
359
+		echo '' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
360
+		echo "    # make sure webfinger and other well known services aren't blocked" >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
361
+		echo '    # by denying dot files and rewrite request to the front controller' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
362
+		echo '    location ^~ /.well-known/ {' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
363
+		echo '        allow all;' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
364
+		echo '    }' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
365
+		echo '' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
366
+		echo '    # statically serve these file types when possible' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
367
+		echo '    # otherwise fall back to front controller' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
368
+		echo '    # allow browser to cache them' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
369
+		echo '    # added .htm for advanced source code editor library' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
370
+		echo '    location ~* \.(jpg|jpeg|gif|png|ico|css|js|htm|html|ttf|woff|svg)$ {' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
371
+		echo '        expires 30d;' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
372
+		echo '        try_files $uri /index.php?q=$uri&$args;' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
373
+		echo '    }' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
374
+		echo '' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
375
+		echo '    # block these file types' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
376
+		echo '    location ~* \.(tpl|md|tgz|log|out)$ {' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
377
+		echo '        deny all;' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
378
+		echo '    }' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
379
+		echo '' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
380
+		echo '    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
381
+		echo '    # or a unix socket' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
382
+		echo '    location ~* \.php$ {' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
383
+		echo '        # Zero-day exploit defense.' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
384
+		echo '        # http://forum.nginx.org/read.php?2,88845,page=3' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
385
+		echo "        # Won't work properly (404 error) if the file is not stored on this" >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
386
+		echo "        # server, which is entirely possible with php-fpm/php-fcgi." >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
387
+		echo "        # Comment the 'try_files' line out if you set up php-fpm/php-fcgi on" >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
388
+		echo "        # another machine. And then cross your fingers that you won't get hacked." >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
389
+		echo '        try_files $uri $uri/ /index.php;' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
390
+		echo '        # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
391
+		echo '        fastcgi_split_path_info ^(.+\.php)(/.+)$;' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
392
+		echo '        # With php5-cgi alone:' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
393
+		echo '        # fastcgi_pass 127.0.0.1:9000;' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
394
+		echo '        # With php5-fpm:' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
395
+		echo '        fastcgi_pass unix:/var/run/php5-fpm.sock;' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
396
+		echo '        include fastcgi_params;' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
397
+		echo '        fastcgi_index index.php;' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
398
+		echo '        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
399
+		echo '    }' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
400
+		echo '' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
401
+		echo '    # deny access to all dot files' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
402
+		echo '    location ~ /\. {' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
403
+		echo '        deny all;' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
404
+		echo '    }' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
405
+		echo '' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
406
+		echo '    #deny access to store' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
407
+		echo '    location ~ /store {' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
408
+		echo '        deny all;' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
409
+		echo '    }' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
410
+		echo '    location ~ /(data|conf|bin|inc)/ {' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
411
+		echo '      deny all;' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
412
+		echo '    }' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
413
+		echo '    location ~ /\.ht {' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
414
+		echo '      deny  all;' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
415
+		echo '    }' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
416
+		echo '}' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
417
+		echo '' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
234 418
 	else
235
-	    WIKI_ADMIN_PASSWORD="$(create_password ${MINIMUM_PASSWORD_LENGTH})"
419
+		echo -n '' > /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
236 420
 	fi
237
-    fi
238
-    HASHED_WIKI_PASSWORD=$(echo -n "$WIKI_ADMIN_PASSWORD" | md5sum | awk -F ' ' '{print $1}')
239
-    echo -n "$MY_USERNAME:$HASHED_WIKI_PASSWORD:$MY_NAME:$MY_EMAIL:admin,user,upload" > /var/lib/dokuwiki/acl/users.auth.php
240
-    chmod 640 /var/lib/dokuwiki/acl/users.auth.php
241
-
242
-    if ! grep -q "video/ogg" /etc/dokuwiki/mime.conf; then
243
-	echo 'ogv     video/ogg' >> /etc/dokuwiki/mime.conf
244
-    fi
245
-    if ! grep -q "video/mp4" /etc/dokuwiki/mime.conf; then
246
-	echo 'mp4     video/mp4' >> /etc/dokuwiki/mime.conf
247
-    fi
248
-    if ! grep -q "video/webm" /etc/dokuwiki/mime.conf; then
249
-	echo 'webm    video/webm' >> /etc/dokuwiki/mime.conf
250
-    fi
251
-
252
-    WIKI_ONION_HOSTNAME=$(add_onion_service wiki 80 ${WIKI_ONION_PORT})
253
-
254
-    if [[ $ONION_ONLY == "no" ]]; then
255
-	echo 'server {' > /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
256
-	echo '    listen 80;' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
257
-	echo "    root /var/www/$WIKI_DOMAIN_NAME/htdocs;" >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
258
-	echo "    server_name $WIKI_DOMAIN_NAME;" >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
259
-	echo '    access_log off;' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
260
-	echo "    error_log /var/log/nginx/${WIKI_DOMAIN_NAME}_error.log $WEBSERVER_LOG_LEVEL;" >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
261
-	echo '    index index.php;' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
262
-	echo '    charset utf-8;' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
263
-	echo '    proxy_read_timeout 86400s;' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
264
-	echo '' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
265
-	function_check nginx_disable_sniffing
266
-	nginx_disable_sniffing $WIKI_DOMAIN_NAME
267
-	function_check nginx_limits
268
-	nginx_limits $WIKI_DOMAIN_NAME
269
-	echo '    # rewrite to front controller as default rule' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
270
-	echo '    location / {' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
271
-	echo '        rewrite ^/(.*) /index.php?q=$uri&$args last;' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
272
-	echo '    }' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
273
-	echo '' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
274
-	echo "    # make sure webfinger and other well known services aren't blocked" >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
275
-	echo '    # by denying dot files and rewrite request to the front controller' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
276
-	echo '    location ^~ /.well-known/ {' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
277
-	echo '        allow all;' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
278
-	echo '    }' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
279
-	echo '' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
280
-	echo '    # statically serve these file types when possible' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
281
-	echo '    # otherwise fall back to front controller' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
282
-	echo '    # allow browser to cache them' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
283
-	echo '    # added .htm for advanced source code editor library' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
284
-	echo '    location ~* \.(jpg|jpeg|gif|png|ico|css|js|htm|html|ttf|woff|svg)$ {' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
285
-	echo '        expires 30d;' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
286
-	echo '        try_files $uri /index.php?q=$uri&$args;' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
287
-	echo '    }' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
288
-	echo '' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
289
-	echo '    # block these file types' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
290
-	echo '    location ~* \.(tpl|md|tgz|log|out)$ {' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
291
-	echo '        deny all;' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
292
-	echo '    }' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
293
-	echo '' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
294
-	echo '    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
295
-	echo '    # or a unix socket' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
296
-	echo '    location ~* \.php$ {' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
297
-	echo '        # Zero-day exploit defense.' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
298
-	echo '        # http://forum.nginx.org/read.php?2,88845,page=3' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
299
-	echo "        # Won't work properly (404 error) if the file is not stored on this" >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
300
-	echo "        # server, which is entirely possible with php-fpm/php-fcgi." >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
301
-	echo "        # Comment the 'try_files' line out if you set up php-fpm/php-fcgi on" >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
302
-	echo "        # another machine. And then cross your fingers that you won't get hacked." >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
303
-	echo '        try_files $uri $uri/ /index.php;' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
304
-	echo '        # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
305
-	echo '        fastcgi_split_path_info ^(.+\.php)(/.+)$;' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
306
-	echo '        # With php5-cgi alone:' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
307
-	echo '        # fastcgi_pass 127.0.0.1:9000;' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
308
-	echo '        # With php5-fpm:' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
309
-	echo '        fastcgi_pass unix:/var/run/php5-fpm.sock;' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
310
-	echo '        include fastcgi_params;' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
311
-	echo '        fastcgi_index index.php;' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
312
-	echo '        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
313
-	echo '    }' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
314
-	echo '' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
315
-	echo '    # deny access to all dot files' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
316
-	echo '    location ~ /\. {' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
317
-	echo '        deny all;' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
318
-	echo '    }' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
319
-	echo '' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
320
-	echo '    #deny access to store' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
321
-	echo '    location ~ /store {' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
322
-	echo '        deny all;' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
323
-	echo '    }' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
324
-	echo '    location ~ /(data|conf|bin|inc)/ {' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
325
-	echo '      deny all;' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
326
-	echo '    }' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
327
-	echo '    location ~ /\.ht {' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
328
-	echo '      deny  all;' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
329
-	echo '    }' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
330
-	echo '}' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
331
-	echo '' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
332 421
 	echo 'server {' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
333
-	echo '    listen 443 ssl;' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
422
+	echo "    listen 127.0.0.1:${WIKI_ONION_PORT} default_server;" >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
334 423
 	echo "    root /var/www/$WIKI_DOMAIN_NAME/htdocs;" >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
335
-	echo "    server_name $WIKI_DOMAIN_NAME;" >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
424
+	echo "    server_name $WIKI_ONION_HOSTNAME;" >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
336 425
 	echo '    access_log off;' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
337 426
 	echo "    error_log /var/log/nginx/${WIKI_DOMAIN_NAME}_error_ssl.log $WEBSERVER_LOG_LEVEL;" >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
338 427
 	echo '    index index.php;' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
@@ -340,18 +429,10 @@ function install_wiki {
340 429
 	echo '    proxy_read_timeout 86400s;' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
341 430
 	function_check nginx_limits
342 431
 	nginx_limits $WIKI_DOMAIN_NAME
343
-	function_check nginx_ssl
344
-	nginx_ssl $WIKI_DOMAIN_NAME
345 432
 	function_check nginx_disable_sniffing
346 433
 	nginx_disable_sniffing $WIKI_DOMAIN_NAME
347 434
 	echo '    add_header Strict-Transport-Security "max-age=0;";' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
348 435
 	echo '' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
349
-	echo '    # webmail' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
350
-	echo '    location /webmail {' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
351
-	echo '        rewrite ^/(.*) /webmail/index.php last;' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
352
-	echo '        rewrite ^/(.*) /webmail/installer/index.php last;' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
353
-	echo '    }' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
354
-	echo '' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
355 436
 	echo '    # rewrite to front controller as default rule' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
356 437
 	echo '    location / {' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
357 438
 	echo '        rewrite ^/(.*) /index.php?q=$uri&$args last;' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
@@ -414,124 +495,43 @@ function install_wiki {
414 495
 	echo '      deny  all;' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
415 496
 	echo '    }' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
416 497
 	echo '}' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
417
-	echo '' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
418
-    else
419
-	echo -n '' > /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
420
-    fi
421
-    echo 'server {' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
422
-    echo "    listen 127.0.0.1:${WIKI_ONION_PORT} default_server;" >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
423
-    echo "    root /var/www/$WIKI_DOMAIN_NAME/htdocs;" >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
424
-    echo "    server_name $WIKI_ONION_HOSTNAME;" >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
425
-    echo '    access_log off;' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
426
-    echo "    error_log /var/log/nginx/${WIKI_DOMAIN_NAME}_error_ssl.log $WEBSERVER_LOG_LEVEL;" >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
427
-    echo '    index index.php;' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
428
-    echo '    charset utf-8;' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
429
-    echo '    proxy_read_timeout 86400s;' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
430
-    function_check nginx_limits
431
-    nginx_limits $WIKI_DOMAIN_NAME
432
-    function_check nginx_disable_sniffing
433
-    nginx_disable_sniffing $WIKI_DOMAIN_NAME
434
-    echo '    add_header Strict-Transport-Security "max-age=0;";' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
435
-    echo '' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
436
-    echo '    # rewrite to front controller as default rule' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
437
-    echo '    location / {' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
438
-    echo '        rewrite ^/(.*) /index.php?q=$uri&$args last;' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
439
-    echo '    }' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
440
-    echo '' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
441
-    echo "    # make sure webfinger and other well known services aren't blocked" >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
442
-    echo '    # by denying dot files and rewrite request to the front controller' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
443
-    echo '    location ^~ /.well-known/ {' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
444
-    echo '        allow all;' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
445
-    echo '    }' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
446
-    echo '' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
447
-    echo '    # statically serve these file types when possible' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
448
-    echo '    # otherwise fall back to front controller' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
449
-    echo '    # allow browser to cache them' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
450
-    echo '    # added .htm for advanced source code editor library' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
451
-    echo '    location ~* \.(jpg|jpeg|gif|png|ico|css|js|htm|html|ttf|woff|svg)$ {' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
452
-    echo '        expires 30d;' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
453
-    echo '        try_files $uri /index.php?q=$uri&$args;' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
454
-    echo '    }' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
455
-    echo '' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
456
-    echo '    # block these file types' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
457
-    echo '    location ~* \.(tpl|md|tgz|log|out)$ {' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
458
-    echo '        deny all;' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
459
-    echo '    }' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
460
-    echo '' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
461
-    echo '    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
462
-    echo '    # or a unix socket' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
463
-    echo '    location ~* \.php$ {' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
464
-    echo '        # Zero-day exploit defense.' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
465
-    echo '        # http://forum.nginx.org/read.php?2,88845,page=3' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
466
-    echo "        # Won't work properly (404 error) if the file is not stored on this" >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
467
-    echo "        # server, which is entirely possible with php-fpm/php-fcgi." >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
468
-    echo "        # Comment the 'try_files' line out if you set up php-fpm/php-fcgi on" >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
469
-    echo "        # another machine. And then cross your fingers that you won't get hacked." >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
470
-    echo '        try_files $uri $uri/ /index.php;' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
471
-    echo '        # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
472
-    echo '        fastcgi_split_path_info ^(.+\.php)(/.+)$;' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
473
-    echo '        # With php5-cgi alone:' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
474
-    echo '        # fastcgi_pass 127.0.0.1:9000;' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
475
-    echo '        # With php5-fpm:' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
476
-    echo '        fastcgi_pass unix:/var/run/php5-fpm.sock;' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
477
-    echo '        include fastcgi_params;' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
478
-    echo '        fastcgi_index index.php;' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
479
-    echo '        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
480
-    echo '    }' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
481
-    echo '' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
482
-    echo '    # deny access to all dot files' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
483
-    echo '    location ~ /\. {' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
484
-    echo '        deny all;' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
485
-    echo '    }' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
486
-    echo '' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
487
-    echo '    #deny access to store' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
488
-    echo '    location ~ /store {' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
489
-    echo '        deny all;' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
490
-    echo '    }' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
491
-    echo '    location ~ /(data|conf|bin|inc)/ {' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
492
-    echo '      deny all;' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
493
-    echo '    }' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
494
-    echo '    location ~ /\.ht {' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
495
-    echo '      deny  all;' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
496
-    echo '    }' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
497
-    echo '}' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
498
-
499
-    function_check create_site_certificate
500
-    create_site_certificate $WIKI_DOMAIN_NAME
501
-
502
-    function_check configure_php
503
-    configure_php
504
-
505
-    nginx_ensite $WIKI_DOMAIN_NAME
506
-
507
-    systemctl restart php5-fpm
508
-    systemctl restart nginx
509
-
510
-    echo "Wiki onion domain:${WIKI_ONION_HOSTNAME}" >> $COMPLETION_FILE
511
-
512
-    function_check add_ddns_domain
513
-    add_ddns_domain $WIKI_DOMAIN_NAME
514
-
515
-    # add some post-install instructions
516
-    if ! grep -q $"Wiki password" /home/$MY_USERNAME/README; then
517
-	echo '' >> /home/$MY_USERNAME/README
518
-	echo '' >> /home/$MY_USERNAME/README
519
-	echo $'Wiki' >> /home/$MY_USERNAME/README
520
-	echo '====' >> /home/$MY_USERNAME/README
521
-	echo $"Wiki onion domain: ${WIKI_ONION_HOSTNAME}" >> /home/$MY_USERNAME/README
522
-	echo $"Wiki username: $MY_USERNAME" >> /home/$MY_USERNAME/README
523
-	echo $"Wiki password: $WIKI_ADMIN_PASSWORD" >> /home/$MY_USERNAME/README
524
-	echo '' >> /home/$MY_USERNAME/README
525
-	echo $'Once you have set up the wiki then remove the install file:' >> /home/$MY_USERNAME/README
526
-	echo '' >> /home/$MY_USERNAME/README
527
-	echo "  rm /var/www/$WIKI_DOMAIN_NAME/htdocs/install.php" >> /home/$MY_USERNAME/README
528
-	echo '' >> /home/$MY_USERNAME/README
529
-	chown $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/README
530
-	chmod 600 /home/$MY_USERNAME/README
531
-    fi
532
-
533
-    echo "Wiki domain:$WIKI_DOMAIN_NAME" >> $COMPLETION_FILE
534
-    echo 'install_wiki' >> $COMPLETION_FILE
498
+
499
+	function_check create_site_certificate
500
+	create_site_certificate $WIKI_DOMAIN_NAME
501
+
502
+	function_check configure_php
503
+	configure_php
504
+
505
+	nginx_ensite $WIKI_DOMAIN_NAME
506
+
507
+	systemctl restart php5-fpm
508
+	systemctl restart nginx
509
+
510
+	echo "Wiki onion domain:${WIKI_ONION_HOSTNAME}" >> $COMPLETION_FILE
511
+
512
+	function_check add_ddns_domain
513
+	add_ddns_domain $WIKI_DOMAIN_NAME
514
+
515
+	# add some post-install instructions
516
+	if ! grep -q $"Wiki password" /home/$MY_USERNAME/README; then
517
+		echo '' >> /home/$MY_USERNAME/README
518
+		echo '' >> /home/$MY_USERNAME/README
519
+		echo $'Wiki' >> /home/$MY_USERNAME/README
520
+		echo '====' >> /home/$MY_USERNAME/README
521
+		echo $"Wiki onion domain: ${WIKI_ONION_HOSTNAME}" >> /home/$MY_USERNAME/README
522
+		echo $"Wiki username: $MY_USERNAME" >> /home/$MY_USERNAME/README
523
+		echo $"Wiki password: $WIKI_ADMIN_PASSWORD" >> /home/$MY_USERNAME/README
524
+		echo '' >> /home/$MY_USERNAME/README
525
+		echo $'Once you have set up the wiki then remove the install file:' >> /home/$MY_USERNAME/README
526
+		echo '' >> /home/$MY_USERNAME/README
527
+		echo "  rm /var/www/$WIKI_DOMAIN_NAME/htdocs/install.php" >> /home/$MY_USERNAME/README
528
+		echo '' >> /home/$MY_USERNAME/README
529
+		chown $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/README
530
+		chmod 600 /home/$MY_USERNAME/README
531
+	fi
532
+
533
+	echo "Wiki domain:$WIKI_DOMAIN_NAME" >> $COMPLETION_FILE
534
+	echo 'install_wiki' >> $COMPLETION_FILE
535 535
 }
536 536
 
537 537
 # NOTE: deliberately no exit 0

+ 399
- 399
src/freedombone-app-xmpp Parādīt failu

@@ -38,444 +38,444 @@ XMPP_CIPHERS='"EDH+CAMELLIA:EDH+aRSA:EECDH+aRSA+AESGCM:EECDH+aRSA+SHA256:EECDH:+
38 38
 XMPP_ECC_CURVE='"secp384r1"'
39 39
 
40 40
 function reconfigure_xmpp {
41
-    echo -n ''
41
+	echo -n ''
42 42
 }
43 43
 
44 44
 function update_prosody_modules {
45
-    if [ ! -d $INSTALL_DIR/prosody-modules ]; then
46
-	return
47
-    fi
48
-    if [ ! -d /usr/lib/prosody ]; then
49
-	return
50
-    fi
51
-
52
-    cd $INSTALL_DIR/prosody-modules
53
-    hg pull
54
-    hg update
55
-
56
-    # support onion addresses
57
-    if [ -f $INSTALL_DIR/prosody-modules/mod_onions/mod_onions.lua ]; then
58
-	cp $INSTALL_DIR/prosody-modules/mod_onions/mod_onions.lua /usr/lib/prosody/modules/mod_onions.lua
59
-    fi
60
-
61
-    # XEP-0313 message archive management
62
-    # https://modules.prosody.im/mod_mam.html
63
-    # Allows you to download your previous messages onto a new client
64
-    # This only applies if you are not using forward secret crypto
65
-    # such as OTR or OMEMO (eg. OpenPGP)
66
-    if [ -d $INSTALL_DIR/prosody-modules/mod_mam ]; then
67
-	cp $INSTALL_DIR/prosody-modules/mod_mam/*.lua /usr/lib/prosody/modules
68
-    fi
69
-
70
-    # XEP-0352 Client State Indication
71
-    # Notifies the server if the app is in the background or not
72
-    if [ -d $INSTALL_DIR/prosody-modules/mod_csi ]; then
73
-	cp $INSTALL_DIR/prosody-modules/mod_csi/*.lua /usr/lib/prosody/modules
74
-    fi
75
-
76
-    # XEP-0280 Message Carbons
77
-    # Ensures all messages get delivered to all clients (if you have a mobile and desktop client)
78
-    if [ -d $INSTALL_DIR/prosody-modules/mod_carbons ]; then
79
-	cp $INSTALL_DIR/prosody-modules/mod_carbons/*.lua /usr/lib/prosody/modules
80
-    fi
81
-
82
-    # XEP-0198 Stream management
83
-    # Helps mobile apps recover when a device switches networks.
84
-    if [ -d $INSTALL_DIR/prosody-modules/mod_smacks ]; then
85
-	cp $INSTALL_DIR/prosody-modules/mod_smacks/*.lua /usr/lib/prosody/modules
86
-    fi
87
-    if [ -d $INSTALL_DIR/prosody-modules/mod_smacks_offline ]; then
88
-	cp $INSTALL_DIR/prosody-modules/mod_smacks_offline/*.lua /usr/lib/prosody/modules
89
-    fi
90
-
91
-    # XEP-0191: blocking
92
-    if [ -d $INSTALL_DIR/prosody-modules/mod_blocking ]; then
93
-	cp $INSTALL_DIR/prosody-modules/mod_blocking/*.lua /usr/lib/prosody/modules
94
-    fi
95
-
96
-    # XEP-0016 Privacy lists
97
-    if [ -d $INSTALL_DIR/prosody-modules/mod_privacy_lists ]; then
98
-	cp $INSTALL_DIR/prosody-modules/mod_privacy_lists/*.lua /usr/lib/prosody/modules
99
-    fi
45
+	if [ ! -d $INSTALL_DIR/prosody-modules ]; then
46
+		return
47
+	fi
48
+	if [ ! -d /usr/lib/prosody ]; then
49
+		return
50
+	fi
51
+
52
+	cd $INSTALL_DIR/prosody-modules
53
+	hg pull
54
+	hg update
55
+
56
+	# support onion addresses
57
+	if [ -f $INSTALL_DIR/prosody-modules/mod_onions/mod_onions.lua ]; then
58
+		cp $INSTALL_DIR/prosody-modules/mod_onions/mod_onions.lua /usr/lib/prosody/modules/mod_onions.lua
59
+	fi
60
+
61
+	# XEP-0313 message archive management
62
+	# https://modules.prosody.im/mod_mam.html
63
+	# Allows you to download your previous messages onto a new client
64
+	# This only applies if you are not using forward secret crypto
65
+	# such as OTR or OMEMO (eg. OpenPGP)
66
+	if [ -d $INSTALL_DIR/prosody-modules/mod_mam ]; then
67
+		cp $INSTALL_DIR/prosody-modules/mod_mam/*.lua /usr/lib/prosody/modules
68
+	fi
69
+
70
+	# XEP-0352 Client State Indication
71
+	# Notifies the server if the app is in the background or not
72
+	if [ -d $INSTALL_DIR/prosody-modules/mod_csi ]; then
73
+		cp $INSTALL_DIR/prosody-modules/mod_csi/*.lua /usr/lib/prosody/modules
74
+	fi
75
+
76
+	# XEP-0280 Message Carbons
77
+	# Ensures all messages get delivered to all clients (if you have a mobile and desktop client)
78
+	if [ -d $INSTALL_DIR/prosody-modules/mod_carbons ]; then
79
+		cp $INSTALL_DIR/prosody-modules/mod_carbons/*.lua /usr/lib/prosody/modules
80
+	fi
81
+
82
+	# XEP-0198 Stream management
83
+	# Helps mobile apps recover when a device switches networks.
84
+	if [ -d $INSTALL_DIR/prosody-modules/mod_smacks ]; then
85
+		cp $INSTALL_DIR/prosody-modules/mod_smacks/*.lua /usr/lib/prosody/modules
86
+	fi
87
+	if [ -d $INSTALL_DIR/prosody-modules/mod_smacks_offline ]; then
88
+		cp $INSTALL_DIR/prosody-modules/mod_smacks_offline/*.lua /usr/lib/prosody/modules
89
+	fi
90
+
91
+	# XEP-0191: blocking
92
+	if [ -d $INSTALL_DIR/prosody-modules/mod_blocking ]; then
93
+		cp $INSTALL_DIR/prosody-modules/mod_blocking/*.lua /usr/lib/prosody/modules
94
+	fi
95
+
96
+	# XEP-0016 Privacy lists
97
+	if [ -d $INSTALL_DIR/prosody-modules/mod_privacy_lists ]; then
98
+		cp $INSTALL_DIR/prosody-modules/mod_privacy_lists/*.lua /usr/lib/prosody/modules
99
+	fi
100 100
 }
101 101
 
102 102
 function upgrade_xmpp {
103
-    if ! grep -Fxq "install_xmpp_main" $COMPLETION_FILE; then
104
-	return
105
-    fi
106
-    function_check update_prosody_modules
107
-    update_prosody_modules
103
+	if ! grep -Fxq "install_xmpp_main" $COMPLETION_FILE; then
104
+		return
105
+	fi
106
+	function_check update_prosody_modules
107
+	update_prosody_modules
108 108
 }
109 109
 
110 110
 function backup_local_xmpp {
111
-    source_directory=/var/lib/prosody xmpp
112
-    if [ -d $source_directory ]; then
113
-	dest_directory=xmpp
114
-	echo $"Backing up $source_directory to $dest_directory"
111
+	source_directory=/var/lib/prosody xmpp
112
+	if [ -d $source_directory ]; then
113
+		dest_directory=xmpp
114
+		echo $"Backing up $source_directory to $dest_directory"
115 115
 
116
-	function_check backup_directory_to_usb
117
-	backup_directory_to_usb $source_directory $dest_directory
116
+		function_check backup_directory_to_usb
117
+		backup_directory_to_usb $source_directory $dest_directory
118 118
 
119
-	echo $"Backup to $dest_directory complete"
120
-    fi
119
+		echo $"Backup to $dest_directory complete"
120
+	fi
121 121
 }
122 122
 
123 123
 function restore_local_xmpp {
124
-    if [ -d /var/lib/prosody ]; then
125
-	echo $"Restoring XMPP settings"
126
-	temp_restore_dir=/root/tempxmpp
127
-	function_check restore_directory_from_usb
128
-	restore_directory_from_usb $temp_restore_dir xmpp
129
-	cp -r $temp_restore_dir/var/lib/prosody/* /var/lib/prosody
130
-	if [ ! "$?" = "0" ]; then
131
-	    function_check set_user_permissions
132
-	    set_user_permissions
133
-	    function_check backup_unmount_drive
134
-	    backup_unmount_drive
135
-	    exit 725
136
-	fi
137
-	rm -rf $temp_restore_dir
138
-	service prosody restart
139
-	chown -R prosody:prosody /var/lib/prosody/*
140
-	echo $"Restore of XMPP settings complete"
141
-    fi
124
+	if [ -d /var/lib/prosody ]; then
125
+		echo $"Restoring XMPP settings"
126
+		temp_restore_dir=/root/tempxmpp
127
+		function_check restore_directory_from_usb
128
+		restore_directory_from_usb $temp_restore_dir xmpp
129
+		cp -r $temp_restore_dir/var/lib/prosody/* /var/lib/prosody
130
+		if [ ! "$?" = "0" ]; then
131
+			function_check set_user_permissions
132
+			set_user_permissions
133
+			function_check backup_unmount_drive
134
+			backup_unmount_drive
135
+			exit 725
136
+		fi
137
+		rm -rf $temp_restore_dir
138
+		service prosody restart
139
+		chown -R prosody:prosody /var/lib/prosody/*
140
+		echo $"Restore of XMPP settings complete"
141
+	fi
142 142
 }
143 143
 
144 144
 function backup_remote_xmpp {
145
-    if [ -d /var/lib/prosody ]; then
146
-	echo $"Backing up the XMPP settings"
147
-	backup_directory_to_friend /var/lib/prosody xmpp
148
-	echo $"Backup of XMPP settings complete"
149
-    fi
145
+	if [ -d /var/lib/prosody ]; then
146
+		echo $"Backing up the XMPP settings"
147
+		backup_directory_to_friend /var/lib/prosody xmpp
148
+		echo $"Backup of XMPP settings complete"
149
+	fi
150 150
 }
151 151
 
152 152
 function restore_remote_xmpp {
153
-    if [ -d /var/lib/prosody ]; then
154
-	echo $"Restoring XMPP settings"
155
-	temp_restore_dir=/root/tempxmpp
156
-	function_check restore_directory_from_friend
157
-	restore_directory_from_friend $temp_restore_dir xmpp
158
-	cp -r $temp_restore_dir/var/lib/prosody/* /var/lib/prosody
159
-	if [ ! "$?" = "0" ]; then
160
-	    exit 725
161
-	fi
162
-	rm -rf $temp_restore_dir
163
-	service prosody restart
164
-	chown -R prosody:prosody /var/lib/prosody/*
165
-	echo $"Restore of XMPP settings complete"
166
-    fi
153
+	if [ -d /var/lib/prosody ]; then
154
+		echo $"Restoring XMPP settings"
155
+		temp_restore_dir=/root/tempxmpp
156
+		function_check restore_directory_from_friend
157
+		restore_directory_from_friend $temp_restore_dir xmpp
158
+		cp -r $temp_restore_dir/var/lib/prosody/* /var/lib/prosody
159
+		if [ ! "$?" = "0" ]; then
160
+			exit 725
161
+		fi
162
+		rm -rf $temp_restore_dir
163
+		service prosody restart
164
+		chown -R prosody:prosody /var/lib/prosody/*
165
+		echo $"Restore of XMPP settings complete"
166
+	fi
167 167
 }
168 168
 
169 169
 function configure_firewall_for_xmpp {
170
-    if [ ! -d /etc/prosody ]; then
171
-	return
172
-    fi
173
-    if grep -Fxq "configure_firewall_for_xmpp" $COMPLETION_FILE; then
174
-	return
175
-    fi
176
-    if [[ $INSTALLED_WITHIN_DOCKER == "yes" ]]; then
177
-	# docker does its own firewalling
178
-	return
179
-    fi
180
-    if [[ $ONION_ONLY != "no" ]]; then
181
-	return
182
-    fi
183
-    iptables -A INPUT -p tcp --dport 5222:5223 -j ACCEPT
184
-    iptables -A INPUT -p tcp --dport 5269 -j ACCEPT
185
-    iptables -A INPUT -p tcp --dport 5280:5281 -j ACCEPT
186
-    function_check save_firewall_settings
187
-    save_firewall_settings
188
-
189
-    OPEN_PORTS+=('XMPP     5222-5223')
190
-    OPEN_PORTS+=('XMPP     5269')
191
-    OPEN_PORTS+=('XMPP     5280-5281')
192
-    echo 'configure_firewall_for_xmpp' >> $COMPLETION_FILE
170
+	if [ ! -d /etc/prosody ]; then
171
+		return
172
+	fi
173
+	if grep -Fxq "configure_firewall_for_xmpp" $COMPLETION_FILE; then
174
+		return
175
+	fi
176
+	if [[ $INSTALLED_WITHIN_DOCKER == "yes" ]]; then
177
+		# docker does its own firewalling
178
+		return
179
+	fi
180
+	if [[ $ONION_ONLY != "no" ]]; then
181
+		return
182
+	fi
183
+	iptables -A INPUT -p tcp --dport 5222:5223 -j ACCEPT
184
+	iptables -A INPUT -p tcp --dport 5269 -j ACCEPT
185
+	iptables -A INPUT -p tcp --dport 5280:5281 -j ACCEPT
186
+	function_check save_firewall_settings
187
+	save_firewall_settings
188
+
189
+	OPEN_PORTS+=('XMPP     5222-5223')
190
+	OPEN_PORTS+=('XMPP     5269')
191
+	OPEN_PORTS+=('XMPP     5280-5281')
192
+	echo 'configure_firewall_for_xmpp' >> $COMPLETION_FILE
193 193
 }
194 194
 
195 195
 function remove_xmpp_client {
196
-    if ! grep -Fxq "install_xmpp_client" $COMPLETION_FILE; then
197
-	return
198
-    fi
199
-    apt-get -y remove --purge profanity
200
-    sed '/install_xmpp_client/d' $COMPLETION_FILE
196
+	if ! grep -Fxq "install_xmpp_client" $COMPLETION_FILE; then
197
+		return
198
+	fi
199
+	apt-get -y remove --purge profanity
200
+	sed '/install_xmpp_client/d' $COMPLETION_FILE
201 201
 }
202 202
 
203 203
 function remove_xmpp {
204
-    remove_xmpp_client
205
-    if ! grep -Fxq "install_xmpp" $COMPLETION_FILE; then
206
-	return
207
-    fi
208
-    iptables -D INPUT -p tcp --dport 5222:5223 -j ACCEPT
209
-    iptables -D INPUT -p tcp --dport 5269 -j ACCEPT
210
-    iptables -D INPUT -p tcp --dport 5280:5281 -j ACCEPT
211
-    function_check save_firewall_settings
212
-    save_firewall_settings
213
-
214
-    function_check remove_onion_service
215
-    remove_onion_service xmpp 5222 5223 5269
216
-
217
-    apt-get -y remove --purge prosody prosody-modules
218
-    if [ -d $INSTALL_DIR/prosody-modules ]; then
219
-	rm -rf $INSTALL_DIR/prosody-modules
220
-    fi
221
-    if [ -d /etc/prosody ]; then
222
-	rm -rf /etc/prosody
223
-    fi
224
-
225
-    sed '/install_xmpp/d' $COMPLETION_FILE
226
-    sed '/XMPP /d' $COMPLETION_FILE
204
+	remove_xmpp_client
205
+	if ! grep -Fxq "install_xmpp" $COMPLETION_FILE; then
206
+		return
207
+	fi
208
+	iptables -D INPUT -p tcp --dport 5222:5223 -j ACCEPT
209
+	iptables -D INPUT -p tcp --dport 5269 -j ACCEPT
210
+	iptables -D INPUT -p tcp --dport 5280:5281 -j ACCEPT
211
+	function_check save_firewall_settings
212
+	save_firewall_settings
213
+
214
+	function_check remove_onion_service
215
+	remove_onion_service xmpp 5222 5223 5269
216
+
217
+	apt-get -y remove --purge prosody prosody-modules
218
+	if [ -d $INSTALL_DIR/prosody-modules ]; then
219
+		rm -rf $INSTALL_DIR/prosody-modules
220
+	fi
221
+	if [ -d /etc/prosody ]; then
222
+		rm -rf /etc/prosody
223
+	fi
224
+
225
+	sed '/install_xmpp/d' $COMPLETION_FILE
226
+	sed '/XMPP /d' $COMPLETION_FILE
227 227
 }
228 228
 
229 229
 function install_xmpp_main {
230
-    update_prosody_modules
231
-
232
-    if grep -Fxq "install_xmpp_main" $COMPLETION_FILE; then
233
-	return
234
-    fi
235
-    apt-get -y install lua-sec lua-bitop
236
-    apt-get -y install prosody prosody-modules mercurial
237
-
238
-    if [ ! -d /etc/prosody ]; then
239
-	echo $"ERROR: prosody does not appear to have installed. $CHECK_MESSAGE"
240
-	exit 52
241
-    fi
242
-
243
-    # obtain the prosody modules
244
-    cd $INSTALL_DIR
245
-    hg clone https://hg.prosody.im/prosody-modules/ prosody-modules
246
-    if [ ! -d $INSTALL_DIR/prosody-modules/mod_onions ]; then
247
-	echo $'mod_onions prosody module could not be found'
248
-	exit 73254
249
-    fi
250
-
251
-    # install the onions module
252
-    update_prosody_modules
253
-    if [ ! -f /usr/lib/prosody/modules/mod_onions.lua ]; then
254
-	echo $'mod_onions.lua could not be copied to the prosody modules directory'
255
-	exit 63952
256
-    fi
257
-
258
-    # create a certificate
259
-    if [ ! -f /etc/ssl/certs/xmpp.dhparam ]; then
260
-	${PROJECT_NAME}-addcert -h xmpp --dhkey $DH_KEYLENGTH
261
-	check_certificates xmpp
262
-    fi
263
-    chown prosody:prosody /etc/ssl/private/xmpp.key
264
-    chown prosody:prosody /etc/ssl/certs/xmpp.*
265
-    cp -a /etc/prosody/conf.avail/example.com.cfg.lua /etc/prosody/conf.avail/xmpp.cfg.lua
266
-
267
-    sed -i 's|/etc/prosody/certs/example.com.key|/etc/ssl/private/xmpp.key|g' /etc/prosody/conf.avail/xmpp.cfg.lua
268
-    sed -i 's|/etc/prosody/certs/example.com.crt|/etc/ssl/certs/xmpp.crt|g' /etc/prosody/conf.avail/xmpp.cfg.lua
269
-    if ! grep -q "xmpp.dhparam" /etc/prosody/conf.avail/xmpp.cfg.lua; then
270
-	sed -i '/certificate =/a\        dhparam = "/etc/ssl/certs/xmpp.dhparam";' /etc/prosody/conf.avail/xmpp.cfg.lua
271
-    fi
272
-    if ! grep -q 'options = {"no_sslv2", "no_sslv3" }' /etc/prosody/conf.avail/xmpp.cfg.lua; then
273
-	sed -i '/certificate =/a\        options = {"no_sslv2", "no_sslv3" };' /etc/prosody/conf.avail/xmpp.cfg.lua
274
-    fi
275
-    if ! grep -q 'ciphers =' /etc/prosody/conf.avail/xmpp.cfg.lua; then
276
-	sed -i "/certificate =/a\        ciphers = $XMPP_CIPHERS;" /etc/prosody/conf.avail/xmpp.cfg.lua
277
-    fi
278
-    if ! grep -q 'depth = "1";' /etc/prosody/conf.avail/xmpp.cfg.lua; then
279
-	sed -i '/certificate =/a\        depth = "1";' /etc/prosody/conf.avail/xmpp.cfg.lua
280
-    fi
281
-    if ! grep -q 'curve =' /etc/prosody/conf.avail/xmpp.cfg.lua; then
282
-	sed -i "/certificate =/a\        curve = $XMPP_ECC_CURVE;" /etc/prosody/conf.avail/xmpp.cfg.lua
283
-    fi
284
-
285
-    sed -i "s/example.com/$DEFAULT_DOMAIN_NAME/g" /etc/prosody/conf.avail/xmpp.cfg.lua
286
-    sed -i 's/enabled = false -- Remove this line to enable this host//g' /etc/prosody/conf.avail/xmpp.cfg.lua
287
-
288
-    if ! grep -q "modules_enabled" /etc/prosody/conf.avail/xmpp.cfg.lua; then
289
-	echo '' >> /etc/prosody/conf.avail/xmpp.cfg.lua
290
-	echo 'modules_enabled = {' >> /etc/prosody/conf.avail/xmpp.cfg.lua
291
-	echo '  "bosh"; -- Enable mod_bosh' >> /etc/prosody/conf.avail/xmpp.cfg.lua
292
-	echo '  "tls"; -- Enable mod_tls' >> /etc/prosody/conf.avail/xmpp.cfg.lua
293
-	echo '  "saslauth"; -- Enable mod_saslauth' >> /etc/prosody/conf.avail/xmpp.cfg.lua
294
-	echo '  "onions"; -- Enable chat via onion service' >> /etc/prosody/conf.avail/xmpp.cfg.lua
295
-	echo '  "mam"; -- Message archive management' >> /etc/prosody/conf.avail/xmpp.cfg.lua
296
-	echo '  "csi"; -- Client state indication' >> /etc/prosody/conf.avail/xmpp.cfg.lua
297
-	echo '  "carbons"; -- Message carbons' >> /etc/prosody/conf.avail/xmpp.cfg.lua
298
-	echo '  "smacks"; -- Stream management' >> /etc/prosody/conf.avail/xmpp.cfg.lua
299
-	echo '  "smacks_offline"; -- Stream management' >> /etc/prosody/conf.avail/xmpp.cfg.lua
300
-	echo '  "pep"; -- Personal Eventing Protocol (to support OMEMO)' >> /etc/prosody/conf.avail/xmpp.cfg.lua
301
-	echo '  "privacy"; -- Privacy lists' >> /etc/prosody/conf.avail/xmpp.cfg.lua
302
-	echo '  "privacy_lists"; -- Privacy lists' >> /etc/prosody/conf.avail/xmpp.cfg.lua
303
-	echo '  "blocking"; -- Blocking command' >> /etc/prosody/conf.avail/xmpp.cfg.lua
304
-	echo '  "roster"; -- Roster versioning' >> /etc/prosody/conf.avail/xmpp.cfg.lua
305
-	echo '}' >> /etc/prosody/conf.avail/xmpp.cfg.lua
306
-	echo '' >> /etc/prosody/conf.avail/xmpp.cfg.lua
307
-	echo 'c2s_require_encryption = true' >> /etc/prosody/conf.avail/xmpp.cfg.lua
308
-	echo 's2s_require_encryption = true' >> /etc/prosody/conf.avail/xmpp.cfg.lua
309
-	echo 'allow_unencrypted_plain_auth = false' >> /etc/prosody/conf.avail/xmpp.cfg.lua
310
-    fi
311
-    ln -sf /etc/prosody/conf.avail/xmpp.cfg.lua /etc/prosody/conf.d/xmpp.cfg.lua
312
-
313
-    sed -i 's|/etc/prosody/certs/localhost.key|/etc/ssl/private/xmpp.key|g' /etc/prosody/prosody.cfg.lua
314
-    sed -i 's|/etc/prosody/certs/localhost.crt|/etc/ssl/certs/xmpp.crt|g' /etc/prosody/prosody.cfg.lua
315
-    if ! grep -q "xmpp.dhparam" /etc/prosody/prosody.cfg.lua; then
316
-	sed -i '/certificate =/a\    dhparam = "/etc/ssl/certs/xmpp.dhparam";' /etc/prosody/prosody.cfg.lua
317
-    fi
318
-    if ! grep -q 'options = {"no_sslv2", "no_sslv3" }' /etc/prosody/prosody.cfg.lua; then
319
-	sed -i '/certificate =/a\    options = {"no_sslv2", "no_sslv3" };' /etc/prosody/prosody.cfg.lua
320
-    fi
321
-    if ! grep -q 'ciphers =' /etc/prosody/prosody.cfg.lua; then
322
-	sed -i "/certificate =/a\    ciphers = $XMPP_CIPHERS;" /etc/prosody/prosody.cfg.lua
323
-    fi
324
-    if ! grep -q 'depth = "1";' /etc/prosody/prosody.cfg.lua; then
325
-	sed -i '/certificate =/a\    depth = "1";' /etc/prosody/prosody.cfg.lua
326
-    fi
327
-    if ! grep -q 'curve =' /etc/prosody/prosody.cfg.lua; then
328
-	sed -i "/certificate =/a\    curve = $XMPP_ECC_CURVE;" /etc/prosody/prosody.cfg.lua
329
-    fi
330
-    sed -i 's/c2s_require_encryption = false/c2s_require_encryption = true/g' /etc/prosody/prosody.cfg.lua
331
-    if ! grep -q "s2s_require_encryption" /etc/prosody/prosody.cfg.lua; then
332
-	sed -i '/c2s_require_encryption/a\s2s_require_encryption = true' /etc/prosody/prosody.cfg.lua
333
-    fi
334
-    if ! grep -q "allow_unencrypted_plain_auth" /etc/prosody/prosody.cfg.lua; then
335
-	echo 'allow_unencrypted_plain_auth = false' >> /etc/prosody/conf.avail/xmpp.cfg.lua
336
-    fi
337
-    sed -i 's/--"bosh";/"bosh";/g' /etc/prosody/prosody.cfg.lua
338
-    sed -i 's/authentication = "internal_plain"/authentication = "internal_hashed"/g' /etc/prosody/prosody.cfg.lua
339
-    sed -i 's/enabled = false -- Remove this line to enable this host//g' /etc/prosody/prosody.cfg.lua
340
-    sed -i 's|key = "/etc/prosody/certs/example.com.key"|key = "/etc/ssl/private/xmpp.key"|g' /etc/prosody/prosody.cfg.lua
341
-    sed -i 's|certificate = "/etc/prosody/certs/example.com.crt"|certificate = "/etc/ssl/certs/xmpp.crt"|g' /etc/prosody/prosody.cfg.lua
342
-    sed -i "s/example.com/$DEFAULT_DOMAIN_NAME/g" /etc/prosody/prosody.cfg.lua
343
-
344
-    systemctl restart prosody
345
-    touch /home/$MY_USERNAME/README
346
-
347
-    if [ ! -d /var/lib/tor ]; then
348
-	echo $'No Tor installation found. XMPP onion site cannot be configured.'
349
-	exit 877367
350
-    fi
351
-    if ! grep -q "hidden_service_xmpp" /etc/tor/torrc; then
352
-	echo 'HiddenServiceDir /var/lib/tor/hidden_service_xmpp/' >> /etc/tor/torrc
353
-	echo "HiddenServicePort 5222 127.0.0.1:5222" >> /etc/tor/torrc
354
-	echo "HiddenServicePort 5269 127.0.0.1:5269" >> /etc/tor/torrc
355
-	echo $'Added onion site for XMPP chat'
356
-    fi
357
-
358
-    systemctl restart tor
359
-    wait_for_onion_service 'xmpp'
360
-
361
-    if [ ! -f /var/lib/tor/hidden_service_xmpp/hostname ]; then
362
-	echo $'XMPP onion site hostname not found'
363
-	exit 65349
364
-    fi
365
-    XMPP_ONION_HOSTNAME=$(cat /var/lib/tor/hidden_service_xmpp/hostname)
366
-    if ! grep -q "${XMPP_ONION_HOSTNAME}" /etc/prosody/conf.avail/xmpp.cfg.lua; then
367
-	echo '' >> /etc/prosody/conf.avail/xmpp.cfg.lua
368
-	echo "VirtualHost \"${XMPP_ONION_HOSTNAME}\"" >> /etc/prosody/conf.avail/xmpp.cfg.lua
369
-	echo '    modules_enabled = { "onions" };' >> /etc/prosody/conf.avail/xmpp.cfg.lua
370
-    fi
371
-    if ! grep -q "XMPP onion domain" $COMPLETION_FILE; then
372
-	echo "XMPP onion domain:${XMPP_ONION_HOSTNAME}" >> $COMPLETION_FILE
373
-    else
374
-	sed -i "s|XMPP onion domain.*|XMPP onion domain:${XMPP_ONION_HOSTNAME}|g" $COMPLETION_FILE
375
-    fi
376
-
377
-    if ! grep -q "Your XMPP password is" /home/$MY_USERNAME/README; then
378
-	if [ ${#XMPP_PASSWORD} -lt 8 ]; then
379
-	    if [ -f $IMAGE_PASSWORD_FILE ]; then
380
-		XMPP_PASSWORD="$(printf `cat $IMAGE_PASSWORD_FILE`)"
381
-	    else
382
-		XMPP_PASSWORD="$(create_password ${MINIMUM_PASSWORD_LENGTH})"
383
-	    fi
384
-	fi
385
-	prosodyctl register $MY_USERNAME $DEFAULT_DOMAIN_NAME $XMPP_PASSWORD
386
-	echo '' >> /home/$MY_USERNAME/README
387
-	echo '' >> /home/$MY_USERNAME/README
388
-	echo $'XMPP' >> /home/$MY_USERNAME/README
389
-	echo '====' >> /home/$MY_USERNAME/README
390
-	echo $"XMPP onion domain: ${XMPP_ONION_HOSTNAME}" >> /home/$MY_USERNAME/README
391
-	echo $"Your XMPP password is: $XMPP_PASSWORD" >> /home/$MY_USERNAME/README
392
-	echo $'You can change it with: ' >> /home/$MY_USERNAME/README
393
-	echo '' >> /home/$MY_USERNAME/README
394
-	echo "    prosodyctl passwd $MY_EMAIL_ADDRESS" >> /home/$MY_USERNAME/README
395
-	chown $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/README
396
-	chmod 600 /home/$MY_USERNAME/README
397
-    fi
398
-
399
-    function_check configure_firewall_for_xmpp
400
-    configure_firewall_for_xmpp
401
-
402
-    echo 'install_xmpp_main' >> $COMPLETION_FILE
230
+	update_prosody_modules
231
+
232
+	if grep -Fxq "install_xmpp_main" $COMPLETION_FILE; then
233
+		return
234
+	fi
235
+	apt-get -y install lua-sec lua-bitop
236
+	apt-get -y install prosody prosody-modules mercurial
237
+
238
+	if [ ! -d /etc/prosody ]; then
239
+		echo $"ERROR: prosody does not appear to have installed. $CHECK_MESSAGE"
240
+		exit 52
241
+	fi
242
+
243
+	# obtain the prosody modules
244
+	cd $INSTALL_DIR
245
+	hg clone https://hg.prosody.im/prosody-modules/ prosody-modules
246
+	if [ ! -d $INSTALL_DIR/prosody-modules/mod_onions ]; then
247
+		echo $'mod_onions prosody module could not be found'
248
+		exit 73254
249
+	fi
250
+
251
+	# install the onions module
252
+	update_prosody_modules
253
+	if [ ! -f /usr/lib/prosody/modules/mod_onions.lua ]; then
254
+		echo $'mod_onions.lua could not be copied to the prosody modules directory'
255
+		exit 63952
256
+	fi
257
+
258
+	# create a certificate
259
+	if [ ! -f /etc/ssl/certs/xmpp.dhparam ]; then
260
+		${PROJECT_NAME}-addcert -h xmpp --dhkey $DH_KEYLENGTH
261
+		check_certificates xmpp
262
+	fi
263
+	chown prosody:prosody /etc/ssl/private/xmpp.key
264
+	chown prosody:prosody /etc/ssl/certs/xmpp.*
265
+	cp -a /etc/prosody/conf.avail/example.com.cfg.lua /etc/prosody/conf.avail/xmpp.cfg.lua
266
+
267
+	sed -i 's|/etc/prosody/certs/example.com.key|/etc/ssl/private/xmpp.key|g' /etc/prosody/conf.avail/xmpp.cfg.lua
268
+	sed -i 's|/etc/prosody/certs/example.com.crt|/etc/ssl/certs/xmpp.crt|g' /etc/prosody/conf.avail/xmpp.cfg.lua
269
+	if ! grep -q "xmpp.dhparam" /etc/prosody/conf.avail/xmpp.cfg.lua; then
270
+		sed -i '/certificate =/a\        dhparam = "/etc/ssl/certs/xmpp.dhparam";' /etc/prosody/conf.avail/xmpp.cfg.lua
271
+	fi
272
+	if ! grep -q 'options = {"no_sslv2", "no_sslv3" }' /etc/prosody/conf.avail/xmpp.cfg.lua; then
273
+		sed -i '/certificate =/a\        options = {"no_sslv2", "no_sslv3" };' /etc/prosody/conf.avail/xmpp.cfg.lua
274
+	fi
275
+	if ! grep -q 'ciphers =' /etc/prosody/conf.avail/xmpp.cfg.lua; then
276
+		sed -i "/certificate =/a\        ciphers = $XMPP_CIPHERS;" /etc/prosody/conf.avail/xmpp.cfg.lua
277
+	fi
278
+	if ! grep -q 'depth = "1";' /etc/prosody/conf.avail/xmpp.cfg.lua; then
279
+		sed -i '/certificate =/a\        depth = "1";' /etc/prosody/conf.avail/xmpp.cfg.lua
280
+	fi
281
+	if ! grep -q 'curve =' /etc/prosody/conf.avail/xmpp.cfg.lua; then
282
+		sed -i "/certificate =/a\        curve = $XMPP_ECC_CURVE;" /etc/prosody/conf.avail/xmpp.cfg.lua
283
+	fi
284
+
285
+	sed -i "s/example.com/$DEFAULT_DOMAIN_NAME/g" /etc/prosody/conf.avail/xmpp.cfg.lua
286
+	sed -i 's/enabled = false -- Remove this line to enable this host//g' /etc/prosody/conf.avail/xmpp.cfg.lua
287
+
288
+	if ! grep -q "modules_enabled" /etc/prosody/conf.avail/xmpp.cfg.lua; then
289
+		echo '' >> /etc/prosody/conf.avail/xmpp.cfg.lua
290
+		echo 'modules_enabled = {' >> /etc/prosody/conf.avail/xmpp.cfg.lua
291
+		echo '  "bosh"; -- Enable mod_bosh' >> /etc/prosody/conf.avail/xmpp.cfg.lua
292
+		echo '  "tls"; -- Enable mod_tls' >> /etc/prosody/conf.avail/xmpp.cfg.lua
293
+		echo '  "saslauth"; -- Enable mod_saslauth' >> /etc/prosody/conf.avail/xmpp.cfg.lua
294
+		echo '  "onions"; -- Enable chat via onion service' >> /etc/prosody/conf.avail/xmpp.cfg.lua
295
+		echo '  "mam"; -- Message archive management' >> /etc/prosody/conf.avail/xmpp.cfg.lua
296
+		echo '  "csi"; -- Client state indication' >> /etc/prosody/conf.avail/xmpp.cfg.lua
297
+		echo '  "carbons"; -- Message carbons' >> /etc/prosody/conf.avail/xmpp.cfg.lua
298
+		echo '  "smacks"; -- Stream management' >> /etc/prosody/conf.avail/xmpp.cfg.lua
299
+		echo '  "smacks_offline"; -- Stream management' >> /etc/prosody/conf.avail/xmpp.cfg.lua
300
+		echo '  "pep"; -- Personal Eventing Protocol (to support OMEMO)' >> /etc/prosody/conf.avail/xmpp.cfg.lua
301
+		echo '  "privacy"; -- Privacy lists' >> /etc/prosody/conf.avail/xmpp.cfg.lua
302
+		echo '  "privacy_lists"; -- Privacy lists' >> /etc/prosody/conf.avail/xmpp.cfg.lua
303
+		echo '  "blocking"; -- Blocking command' >> /etc/prosody/conf.avail/xmpp.cfg.lua
304
+		echo '  "roster"; -- Roster versioning' >> /etc/prosody/conf.avail/xmpp.cfg.lua
305
+		echo '}' >> /etc/prosody/conf.avail/xmpp.cfg.lua
306
+		echo '' >> /etc/prosody/conf.avail/xmpp.cfg.lua
307
+		echo 'c2s_require_encryption = true' >> /etc/prosody/conf.avail/xmpp.cfg.lua
308
+		echo 's2s_require_encryption = true' >> /etc/prosody/conf.avail/xmpp.cfg.lua
309
+		echo 'allow_unencrypted_plain_auth = false' >> /etc/prosody/conf.avail/xmpp.cfg.lua
310
+	fi
311
+	ln -sf /etc/prosody/conf.avail/xmpp.cfg.lua /etc/prosody/conf.d/xmpp.cfg.lua
312
+
313
+	sed -i 's|/etc/prosody/certs/localhost.key|/etc/ssl/private/xmpp.key|g' /etc/prosody/prosody.cfg.lua
314
+	sed -i 's|/etc/prosody/certs/localhost.crt|/etc/ssl/certs/xmpp.crt|g' /etc/prosody/prosody.cfg.lua
315
+	if ! grep -q "xmpp.dhparam" /etc/prosody/prosody.cfg.lua; then
316
+		sed -i '/certificate =/a\    dhparam = "/etc/ssl/certs/xmpp.dhparam";' /etc/prosody/prosody.cfg.lua
317
+	fi
318
+	if ! grep -q 'options = {"no_sslv2", "no_sslv3" }' /etc/prosody/prosody.cfg.lua; then
319
+		sed -i '/certificate =/a\    options = {"no_sslv2", "no_sslv3" };' /etc/prosody/prosody.cfg.lua
320
+	fi
321
+	if ! grep -q 'ciphers =' /etc/prosody/prosody.cfg.lua; then
322
+		sed -i "/certificate =/a\    ciphers = $XMPP_CIPHERS;" /etc/prosody/prosody.cfg.lua
323
+	fi
324
+	if ! grep -q 'depth = "1";' /etc/prosody/prosody.cfg.lua; then
325
+		sed -i '/certificate =/a\    depth = "1";' /etc/prosody/prosody.cfg.lua
326
+	fi
327
+	if ! grep -q 'curve =' /etc/prosody/prosody.cfg.lua; then
328
+		sed -i "/certificate =/a\    curve = $XMPP_ECC_CURVE;" /etc/prosody/prosody.cfg.lua
329
+	fi
330
+	sed -i 's/c2s_require_encryption = false/c2s_require_encryption = true/g' /etc/prosody/prosody.cfg.lua
331
+	if ! grep -q "s2s_require_encryption" /etc/prosody/prosody.cfg.lua; then
332
+		sed -i '/c2s_require_encryption/a\s2s_require_encryption = true' /etc/prosody/prosody.cfg.lua
333
+	fi
334
+	if ! grep -q "allow_unencrypted_plain_auth" /etc/prosody/prosody.cfg.lua; then
335
+		echo 'allow_unencrypted_plain_auth = false' >> /etc/prosody/conf.avail/xmpp.cfg.lua
336
+	fi
337
+	sed -i 's/--"bosh";/"bosh";/g' /etc/prosody/prosody.cfg.lua
338
+	sed -i 's/authentication = "internal_plain"/authentication = "internal_hashed"/g' /etc/prosody/prosody.cfg.lua
339
+	sed -i 's/enabled = false -- Remove this line to enable this host//g' /etc/prosody/prosody.cfg.lua
340
+	sed -i 's|key = "/etc/prosody/certs/example.com.key"|key = "/etc/ssl/private/xmpp.key"|g' /etc/prosody/prosody.cfg.lua
341
+	sed -i 's|certificate = "/etc/prosody/certs/example.com.crt"|certificate = "/etc/ssl/certs/xmpp.crt"|g' /etc/prosody/prosody.cfg.lua
342
+	sed -i "s/example.com/$DEFAULT_DOMAIN_NAME/g" /etc/prosody/prosody.cfg.lua
343
+
344
+	systemctl restart prosody
345
+	touch /home/$MY_USERNAME/README
346
+
347
+	if [ ! -d /var/lib/tor ]; then
348
+		echo $'No Tor installation found. XMPP onion site cannot be configured.'
349
+		exit 877367
350
+	fi
351
+	if ! grep -q "hidden_service_xmpp" /etc/tor/torrc; then
352
+		echo 'HiddenServiceDir /var/lib/tor/hidden_service_xmpp/' >> /etc/tor/torrc
353
+		echo "HiddenServicePort 5222 127.0.0.1:5222" >> /etc/tor/torrc
354
+		echo "HiddenServicePort 5269 127.0.0.1:5269" >> /etc/tor/torrc
355
+		echo $'Added onion site for XMPP chat'
356
+	fi
357
+
358
+	systemctl restart tor
359
+	wait_for_onion_service 'xmpp'
360
+
361
+	if [ ! -f /var/lib/tor/hidden_service_xmpp/hostname ]; then
362
+		echo $'XMPP onion site hostname not found'
363
+		exit 65349
364
+	fi
365
+	XMPP_ONION_HOSTNAME=$(cat /var/lib/tor/hidden_service_xmpp/hostname)
366
+	if ! grep -q "${XMPP_ONION_HOSTNAME}" /etc/prosody/conf.avail/xmpp.cfg.lua; then
367
+		echo '' >> /etc/prosody/conf.avail/xmpp.cfg.lua
368
+		echo "VirtualHost \"${XMPP_ONION_HOSTNAME}\"" >> /etc/prosody/conf.avail/xmpp.cfg.lua
369
+		echo '    modules_enabled = { "onions" };' >> /etc/prosody/conf.avail/xmpp.cfg.lua
370
+	fi
371
+	if ! grep -q "XMPP onion domain" $COMPLETION_FILE; then
372
+		echo "XMPP onion domain:${XMPP_ONION_HOSTNAME}" >> $COMPLETION_FILE
373
+	else
374
+		sed -i "s|XMPP onion domain.*|XMPP onion domain:${XMPP_ONION_HOSTNAME}|g" $COMPLETION_FILE
375
+	fi
376
+
377
+	if ! grep -q "Your XMPP password is" /home/$MY_USERNAME/README; then
378
+		if [ ${#XMPP_PASSWORD} -lt 8 ]; then
379
+			if [ -f $IMAGE_PASSWORD_FILE ]; then
380
+				XMPP_PASSWORD="$(printf `cat $IMAGE_PASSWORD_FILE`)"
381
+			else
382
+				XMPP_PASSWORD="$(create_password ${MINIMUM_PASSWORD_LENGTH})"
383
+			fi
384
+		fi
385
+		prosodyctl register $MY_USERNAME $DEFAULT_DOMAIN_NAME $XMPP_PASSWORD
386
+		echo '' >> /home/$MY_USERNAME/README
387
+		echo '' >> /home/$MY_USERNAME/README
388
+		echo $'XMPP' >> /home/$MY_USERNAME/README
389
+		echo '====' >> /home/$MY_USERNAME/README
390
+		echo $"XMPP onion domain: ${XMPP_ONION_HOSTNAME}" >> /home/$MY_USERNAME/README
391
+		echo $"Your XMPP password is: $XMPP_PASSWORD" >> /home/$MY_USERNAME/README
392
+		echo $'You can change it with: ' >> /home/$MY_USERNAME/README
393
+		echo '' >> /home/$MY_USERNAME/README
394
+		echo "    prosodyctl passwd $MY_EMAIL_ADDRESS" >> /home/$MY_USERNAME/README
395
+		chown $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/README
396
+		chmod 600 /home/$MY_USERNAME/README
397
+	fi
398
+
399
+	function_check configure_firewall_for_xmpp
400
+	configure_firewall_for_xmpp
401
+
402
+	echo 'install_xmpp_main' >> $COMPLETION_FILE
403 403
 }
404 404
 
405 405
 function install_xmpp_client {
406
-    if grep -Fxq "install_xmpp_client" $COMPLETION_FILE; then
407
-	return
408
-    fi
409
-    apt-get -y install profanity
410
-
411
-    XMPP_CLIENT_DIR=/home/$MY_USERNAME/.local/share/profanity
412
-    XMPP_CLIENT_ACCOUNTS=$XMPP_CLIENT_DIR/accounts
413
-    if [ ! -d $XMPP_CLIENT_DIR ]; then
414
-	mkdir -p $XMPP_CLIENT_DIR
415
-    fi
416
-
417
-    if [[ $ONION_ONLY == 'no' ]]; then
418
-	echo "[${MY_USERNAME}@${DEFAULT_DOMAIN_NAME}]" > $XMPP_CLIENT_ACCOUNTS
419
-	echo 'enabled=true' >> $XMPP_CLIENT_ACCOUNTS
420
-	echo "jid=${MY_USERNAME}@${DEFAULT_DOMAIN_NAME}" >> $XMPP_CLIENT_ACCOUNTS
421
-	echo 'resource=profanity' >> $XMPP_CLIENT_ACCOUNTS
422
-	echo "muc.service=conference.${DEFAULT_DOMAIN_NAME}" >> $XMPP_CLIENT_ACCOUNTS
423
-	echo "muc.nick=${MY_USERNAME}" >> $XMPP_CLIENT_ACCOUNTS
424
-	echo 'presence.last=online' >> $XMPP_CLIENT_ACCOUNTS
425
-	echo 'presence.login=online' >> $XMPP_CLIENT_ACCOUNTS
426
-	echo 'priority.online=0' >> $XMPP_CLIENT_ACCOUNTS
427
-	echo 'priority.chat=0' >> $XMPP_CLIENT_ACCOUNTS
428
-	echo 'priority.away=0' >> $XMPP_CLIENT_ACCOUNTS
429
-	echo 'priority.xa=0' >> $XMPP_CLIENT_ACCOUNTS
430
-	echo 'priority.dnd=0' >> $XMPP_CLIENT_ACCOUNTS
431
-	if [ ${#XMPP_PASSWORD} -gt 2 ]; then
432
-	    echo "password=$XMPP_PASSWORD" >> $XMPP_CLIENT_ACCOUNTS
433
-	fi
434
-    fi
435
-
436
-    if [ -f /var/lib/tor/hidden_service_xmpp/hostname ]; then
437
-	XMPP_ONION_HOSTNAME=$(cat /var/lib/tor/hidden_service_xmpp/hostname)
438
-	echo "[${MY_USERNAME}@${XMPP_ONION_HOSTNAME}]" >> $XMPP_CLIENT_ACCOUNTS
406
+	if grep -Fxq "install_xmpp_client" $COMPLETION_FILE; then
407
+		return
408
+	fi
409
+	apt-get -y install profanity
410
+
411
+	XMPP_CLIENT_DIR=/home/$MY_USERNAME/.local/share/profanity
412
+	XMPP_CLIENT_ACCOUNTS=$XMPP_CLIENT_DIR/accounts
413
+	if [ ! -d $XMPP_CLIENT_DIR ]; then
414
+		mkdir -p $XMPP_CLIENT_DIR
415
+	fi
416
+
439 417
 	if [[ $ONION_ONLY == 'no' ]]; then
440
-	    echo 'enabled=false' >> $XMPP_CLIENT_ACCOUNTS
441
-	else
442
-	    echo 'enabled=true' >> $XMPP_CLIENT_ACCOUNTS
443
-	fi
444
-	echo "jid=${MY_USERNAME}@${XMPP_ONION_HOSTNAME}" >> $XMPP_CLIENT_ACCOUNTS
445
-	echo 'resource=profanity' >> $XMPP_CLIENT_ACCOUNTS
446
-	echo "muc.service=conference.${XMPP_ONION_HOSTNAME}" >> $XMPP_CLIENT_ACCOUNTS
447
-	echo "muc.nick=${MY_USERNAME}" >> $XMPP_CLIENT_ACCOUNTS
448
-	echo 'presence.last=online' >> $XMPP_CLIENT_ACCOUNTS
449
-	echo 'presence.login=online' >> $XMPP_CLIENT_ACCOUNTS
450
-	echo 'priority.online=0' >> $XMPP_CLIENT_ACCOUNTS
451
-	echo 'priority.chat=0' >> $XMPP_CLIENT_ACCOUNTS
452
-	echo 'priority.away=0' >> $XMPP_CLIENT_ACCOUNTS
453
-	echo 'priority.xa=0' >> $XMPP_CLIENT_ACCOUNTS
454
-	echo 'priority.dnd=0' >> $XMPP_CLIENT_ACCOUNTS
455
-	if [ ${#XMPP_PASSWORD} -gt 2 ]; then
456
-	    echo "password=$XMPP_PASSWORD" >> $XMPP_CLIENT_ACCOUNTS
457
-	fi
458
-    fi
459
-
460
-    if [ ! -d /home/$MY_USERNAME/.config/profanity ]; then
461
-	mkdir /home/$MY_USERNAME/.config/profanity
462
-    fi
463
-    echo '[connection]' > /home/$MY_USERNAME/.config/profanity/profrc
464
-    echo "account=${MY_USERNAME}@${DEFAULT_DOMAIN_NAME}" >> /home/$MY_USERNAME/.config/profanity/profrc
465
-
466
-    chown -R $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/.local
467
-    chown -R $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/.config
468
-
469
-    echo 'install_xmpp_client' >> $COMPLETION_FILE
418
+		echo "[${MY_USERNAME}@${DEFAULT_DOMAIN_NAME}]" > $XMPP_CLIENT_ACCOUNTS
419
+		echo 'enabled=true' >> $XMPP_CLIENT_ACCOUNTS
420
+		echo "jid=${MY_USERNAME}@${DEFAULT_DOMAIN_NAME}" >> $XMPP_CLIENT_ACCOUNTS
421
+		echo 'resource=profanity' >> $XMPP_CLIENT_ACCOUNTS
422
+		echo "muc.service=conference.${DEFAULT_DOMAIN_NAME}" >> $XMPP_CLIENT_ACCOUNTS
423
+		echo "muc.nick=${MY_USERNAME}" >> $XMPP_CLIENT_ACCOUNTS
424
+		echo 'presence.last=online' >> $XMPP_CLIENT_ACCOUNTS
425
+		echo 'presence.login=online' >> $XMPP_CLIENT_ACCOUNTS
426
+		echo 'priority.online=0' >> $XMPP_CLIENT_ACCOUNTS
427
+		echo 'priority.chat=0' >> $XMPP_CLIENT_ACCOUNTS
428
+		echo 'priority.away=0' >> $XMPP_CLIENT_ACCOUNTS
429
+		echo 'priority.xa=0' >> $XMPP_CLIENT_ACCOUNTS
430
+		echo 'priority.dnd=0' >> $XMPP_CLIENT_ACCOUNTS
431
+		if [ ${#XMPP_PASSWORD} -gt 2 ]; then
432
+			echo "password=$XMPP_PASSWORD" >> $XMPP_CLIENT_ACCOUNTS
433
+		fi
434
+	fi
435
+
436
+	if [ -f /var/lib/tor/hidden_service_xmpp/hostname ]; then
437
+		XMPP_ONION_HOSTNAME=$(cat /var/lib/tor/hidden_service_xmpp/hostname)
438
+		echo "[${MY_USERNAME}@${XMPP_ONION_HOSTNAME}]" >> $XMPP_CLIENT_ACCOUNTS
439
+		if [[ $ONION_ONLY == 'no' ]]; then
440
+			echo 'enabled=false' >> $XMPP_CLIENT_ACCOUNTS
441
+		else
442
+			echo 'enabled=true' >> $XMPP_CLIENT_ACCOUNTS
443
+		fi
444
+		echo "jid=${MY_USERNAME}@${XMPP_ONION_HOSTNAME}" >> $XMPP_CLIENT_ACCOUNTS
445
+		echo 'resource=profanity' >> $XMPP_CLIENT_ACCOUNTS
446
+		echo "muc.service=conference.${XMPP_ONION_HOSTNAME}" >> $XMPP_CLIENT_ACCOUNTS
447
+		echo "muc.nick=${MY_USERNAME}" >> $XMPP_CLIENT_ACCOUNTS
448
+		echo 'presence.last=online' >> $XMPP_CLIENT_ACCOUNTS
449
+		echo 'presence.login=online' >> $XMPP_CLIENT_ACCOUNTS
450
+		echo 'priority.online=0' >> $XMPP_CLIENT_ACCOUNTS
451
+		echo 'priority.chat=0' >> $XMPP_CLIENT_ACCOUNTS
452
+		echo 'priority.away=0' >> $XMPP_CLIENT_ACCOUNTS
453
+		echo 'priority.xa=0' >> $XMPP_CLIENT_ACCOUNTS
454
+		echo 'priority.dnd=0' >> $XMPP_CLIENT_ACCOUNTS
455
+		if [ ${#XMPP_PASSWORD} -gt 2 ]; then
456
+			echo "password=$XMPP_PASSWORD" >> $XMPP_CLIENT_ACCOUNTS
457
+		fi
458
+	fi
459
+
460
+	if [ ! -d /home/$MY_USERNAME/.config/profanity ]; then
461
+		mkdir /home/$MY_USERNAME/.config/profanity
462
+	fi
463
+	echo '[connection]' > /home/$MY_USERNAME/.config/profanity/profrc
464
+	echo "account=${MY_USERNAME}@${DEFAULT_DOMAIN_NAME}" >> /home/$MY_USERNAME/.config/profanity/profrc
465
+
466
+	chown -R $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/.local
467
+	chown -R $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/.config
468
+
469
+	echo 'install_xmpp_client' >> $COMPLETION_FILE
470 470
 }
471 471
 
472 472
 function install_xmpp {
473
-    if grep -Fxq "install_xmpp" $COMPLETION_FILE; then
474
-	return
475
-    fi
476
-    install_xmpp_main
477
-    install_xmpp_client
478
-    echo 'install_xmpp' >> $COMPLETION_FILE
473
+	if grep -Fxq "install_xmpp" $COMPLETION_FILE; then
474
+		return
475
+	fi
476
+	install_xmpp_main
477
+	install_xmpp_client
478
+	echo 'install_xmpp' >> $COMPLETION_FILE
479 479
 }
480 480
 
481 481
 # NOTE: deliberately no exit 0

+ 555
- 555
src/freedombone-app-zeronet
Failā izmaiņas netiks attēlotas, jo tās ir par lielu
Parādīt failu