| 
				
			 | 
			
			
				@@ -13,7 +13,7 @@ 
			 | 
		
	
		
			
			| 
				13
			 | 
			
				13
			 | 
			
			
				 # License 
			 | 
		
	
		
			
			| 
				14
			 | 
			
				14
			 | 
			
			
				 # ======= 
			 | 
		
	
		
			
			| 
				15
			 | 
			
				15
			 | 
			
			
				 # 
			 | 
		
	
		
			
			| 
				16
			 | 
			
				
			 | 
			
			
				-# Copyright (C) 2016 Bob Mottram <bob@freedombone.net> 
			 | 
		
	
		
			
			| 
				
			 | 
			
				16
			 | 
			
			
				+# Copyright (C) 2016-2017 Bob Mottram <bob@freedombone.net> 
			 | 
		
	
		
			
			| 
				17
			 | 
			
				17
			 | 
			
			
				 # 
			 | 
		
	
		
			
			| 
				18
			 | 
			
				18
			 | 
			
			
				 # This program is free software: you can redistribute it and/or modify 
			 | 
		
	
		
			
			| 
				19
			 | 
			
				19
			 | 
			
			
				 # it under the terms of the GNU Affero General Public License as published by 
			 | 
		
	
	
		
			
			| 
				
			 | 
			
			
				@@ -110,118 +110,19 @@ function upgrade_mailpile { 
			 | 
		
	
		
			
			| 
				110
			 | 
			
				110
			 | 
			
			
				 } 
			 | 
		
	
		
			
			| 
				111
			 | 
			
				111
			 | 
			
			
				  
			 | 
		
	
		
			
			| 
				112
			 | 
			
				112
			 | 
			
			
				 function backup_local_mailpile { 
			 | 
		
	
		
			
			| 
				113
			 | 
			
				
			 | 
			
			
				-    if [ ! -f /etc/systemd/system/mailpile.service ]; then 
			 | 
		
	
		
			
			| 
				114
			 | 
			
				
			 | 
			
			
				-        return 
			 | 
		
	
		
			
			| 
				115
			 | 
			
				
			 | 
			
			
				-    fi 
			 | 
		
	
		
			
			| 
				116
			 | 
			
				
			 | 
			
			
				-    MAILPILE_DOMAIN_NAME='mailpile.local' 
			 | 
		
	
		
			
			| 
				117
			 | 
			
				
			 | 
			
			
				-    if grep -q "mailpile domain" $COMPLETION_FILE; then 
			 | 
		
	
		
			
			| 
				118
			 | 
			
				
			 | 
			
			
				-        MAILPILE_DOMAIN_NAME=$(get_completion_param "mailpile domain") 
			 | 
		
	
		
			
			| 
				119
			 | 
			
				
			 | 
			
			
				-    fi 
			 | 
		
	
		
			
			| 
				120
			 | 
			
				
			 | 
			
			
				-    source_directory=/var/www/${MAILPILE_DOMAIN_NAME}/mail/.local 
			 | 
		
	
		
			
			| 
				121
			 | 
			
				
			 | 
			
			
				-    if [ -d $source_directory ]; then 
			 | 
		
	
		
			
			| 
				122
			 | 
			
				
			 | 
			
			
				-        systemctl stop mailpile 
			 | 
		
	
		
			
			| 
				123
			 | 
			
				
			 | 
			
			
				- 
			 | 
		
	
		
			
			| 
				124
			 | 
			
				
			 | 
			
			
				-        function_check backup_directory_to_usb 
			 | 
		
	
		
			
			| 
				125
			 | 
			
				
			 | 
			
			
				-        backup_directory_to_usb $source_directory mailpile 
			 | 
		
	
		
			
			| 
				126
			 | 
			
				
			 | 
			
			
				- 
			 | 
		
	
		
			
			| 
				127
			 | 
			
				
			 | 
			
			
				-        systemctl start mailpile 
			 | 
		
	
		
			
			| 
				128
			 | 
			
				
			 | 
			
			
				-    fi 
			 | 
		
	
		
			
			| 
				
			 | 
			
				113
			 | 
			
			
				+    echo -n '' 
			 | 
		
	
		
			
			| 
				129
			 | 
			
				114
			 | 
			
			
				 } 
			 | 
		
	
		
			
			| 
				130
			 | 
			
				115
			 | 
			
			
				  
			 | 
		
	
		
			
			| 
				131
			 | 
			
				116
			 | 
			
			
				 function restore_local_mailpile { 
			 | 
		
	
		
			
			| 
				132
			 | 
			
				
			 | 
			
			
				-    if [ ! -f /etc/systemd/system/mailpile.service ]; then 
			 | 
		
	
		
			
			| 
				133
			 | 
			
				
			 | 
			
			
				-        return 
			 | 
		
	
		
			
			| 
				134
			 | 
			
				
			 | 
			
			
				-    fi 
			 | 
		
	
		
			
			| 
				135
			 | 
			
				
			 | 
			
			
				-    MAILPILE_DOMAIN_NAME='mailpile.local' 
			 | 
		
	
		
			
			| 
				136
			 | 
			
				
			 | 
			
			
				-    if grep -q "mailpile domain" $COMPLETION_FILE; then 
			 | 
		
	
		
			
			| 
				137
			 | 
			
				
			 | 
			
			
				-        MAILPILE_DOMAIN_NAME=$(get_completion_param "mailpile domain") 
			 | 
		
	
		
			
			| 
				138
			 | 
			
				
			 | 
			
			
				-    fi 
			 | 
		
	
		
			
			| 
				139
			 | 
			
				
			 | 
			
			
				-    if [ $MAILPILE_DOMAIN_NAME ]; then 
			 | 
		
	
		
			
			| 
				140
			 | 
			
				
			 | 
			
			
				-        systemctl stop mailpile 
			 | 
		
	
		
			
			| 
				141
			 | 
			
				
			 | 
			
			
				- 
			 | 
		
	
		
			
			| 
				142
			 | 
			
				
			 | 
			
			
				-        temp_restore_dir=/root/tempmailpile 
			 | 
		
	
		
			
			| 
				143
			 | 
			
				
			 | 
			
			
				-        restore_directory_from_usb $temp_restore_dir mailpile 
			 | 
		
	
		
			
			| 
				144
			 | 
			
				
			 | 
			
			
				-        if [ -d /var/www/${MAILPILE_DOMAIN_NAME}/mail/.local ]; then 
			 | 
		
	
		
			
			| 
				145
			 | 
			
				
			 | 
			
			
				-            mv /var/www/${MAILPILE_DOMAIN_NAME}/mail/.local /var/www/${MAILPILE_DOMAIN_NAME}/mail/.previous 
			 | 
		
	
		
			
			| 
				146
			 | 
			
				
			 | 
			
			
				-        fi 
			 | 
		
	
		
			
			| 
				147
			 | 
			
				
			 | 
			
			
				-        temp_source_dir=$(find ${temp_restore_dir} -name ".local") 
			 | 
		
	
		
			
			| 
				148
			 | 
			
				
			 | 
			
			
				-        cp -r ${temp_source_dir} /var/www/${MAILPILE_DOMAIN_NAME}/mail/ 
			 | 
		
	
		
			
			| 
				149
			 | 
			
				
			 | 
			
			
				-        if [ ! "$?" = "0" ]; then 
			 | 
		
	
		
			
			| 
				150
			 | 
			
				
			 | 
			
			
				-            if [ -d mv /var/www/${MAILPILE_DOMAIN_NAME}/mail/.previous ]; then 
			 | 
		
	
		
			
			| 
				151
			 | 
			
				
			 | 
			
			
				-                if [ -d /var/www/${MAILPILE_DOMAIN_NAME}/mail/.previous ]; then 
			 | 
		
	
		
			
			| 
				152
			 | 
			
				
			 | 
			
			
				-                    rm -rf /var/www/${MAILPILE_DOMAIN_NAME}/mail/.previous 
			 | 
		
	
		
			
			| 
				153
			 | 
			
				
			 | 
			
			
				-                fi 
			 | 
		
	
		
			
			| 
				154
			 | 
			
				
			 | 
			
			
				-                mv /var/www/${MAILPILE_DOMAIN_NAME}/mail/.previous /var/www/${MAILPILE_DOMAIN_NAME}/mail/.local 
			 | 
		
	
		
			
			| 
				155
			 | 
			
				
			 | 
			
			
				-            fi 
			 | 
		
	
		
			
			| 
				156
			 | 
			
				
			 | 
			
			
				-            backup_unmount_drive 
			 | 
		
	
		
			
			| 
				157
			 | 
			
				
			 | 
			
			
				-            exit 3685 
			 | 
		
	
		
			
			| 
				158
			 | 
			
				
			 | 
			
			
				-        fi 
			 | 
		
	
		
			
			| 
				159
			 | 
			
				
			 | 
			
			
				-        rm -rf ${temp_restore_dir} 
			 | 
		
	
		
			
			| 
				160
			 | 
			
				
			 | 
			
			
				-        chown -R mailpile: /var/www/$MAILPILE_DOMAIN_NAME/mail/ 
			 | 
		
	
		
			
			| 
				161
			 | 
			
				
			 | 
			
			
				- 
			 | 
		
	
		
			
			| 
				162
			 | 
			
				
			 | 
			
			
				-        if [ -d /etc/letsencrypt/live/${MAILPILE_DOMAIN_NAME} ]; then 
			 | 
		
	
		
			
			| 
				163
			 | 
			
				
			 | 
			
			
				-            ln -s /etc/letsencrypt/live/${MAILPILE_DOMAIN_NAME}/privkey.pem /etc/ssl/private/${MAILPILE_DOMAIN_NAME}.key 
			 | 
		
	
		
			
			| 
				164
			 | 
			
				
			 | 
			
			
				-            ln -s /etc/letsencrypt/live/${MAILPILE_DOMAIN_NAME}/fullchain.pem /etc/ssl/certs/${MAILPILE_DOMAIN_NAME}.pem 
			 | 
		
	
		
			
			| 
				165
			 | 
			
				
			 | 
			
			
				-        fi 
			 | 
		
	
		
			
			| 
				166
			 | 
			
				
			 | 
			
			
				- 
			 | 
		
	
		
			
			| 
				167
			 | 
			
				
			 | 
			
			
				-        systemctl start mailpile 
			 | 
		
	
		
			
			| 
				168
			 | 
			
				
			 | 
			
			
				-    fi 
			 | 
		
	
		
			
			| 
				
			 | 
			
				117
			 | 
			
			
				+    echo -n '' 
			 | 
		
	
		
			
			| 
				169
			 | 
			
				118
			 | 
			
			
				 } 
			 | 
		
	
		
			
			| 
				170
			 | 
			
				119
			 | 
			
			
				  
			 | 
		
	
		
			
			| 
				171
			 | 
			
				120
			 | 
			
			
				 function backup_remote_mailpile { 
			 | 
		
	
		
			
			| 
				172
			 | 
			
				
			 | 
			
			
				-    if [ ! -f /etc/systemd/system/mailpile.service ]; then 
			 | 
		
	
		
			
			| 
				173
			 | 
			
				
			 | 
			
			
				-        return 
			 | 
		
	
		
			
			| 
				174
			 | 
			
				
			 | 
			
			
				-    fi 
			 | 
		
	
		
			
			| 
				175
			 | 
			
				
			 | 
			
			
				-    MAILPILE_DOMAIN_NAME='mailpile.local' 
			 | 
		
	
		
			
			| 
				176
			 | 
			
				
			 | 
			
			
				-    if grep -q "mailpile domain" $COMPLETION_FILE; then 
			 | 
		
	
		
			
			| 
				177
			 | 
			
				
			 | 
			
			
				-        MAILPILE_DOMAIN_NAME=$(get_completion_param "mailpile domain") 
			 | 
		
	
		
			
			| 
				178
			 | 
			
				
			 | 
			
			
				-    fi 
			 | 
		
	
		
			
			| 
				179
			 | 
			
				
			 | 
			
			
				-    source_directory=/var/www/${MAILPILE_DOMAIN_NAME}/mail/.local 
			 | 
		
	
		
			
			| 
				180
			 | 
			
				
			 | 
			
			
				-    if [ -d $source_directory ]; then 
			 | 
		
	
		
			
			| 
				181
			 | 
			
				
			 | 
			
			
				-        systemctl stop mailpile 
			 | 
		
	
		
			
			| 
				182
			 | 
			
				
			 | 
			
			
				- 
			 | 
		
	
		
			
			| 
				183
			 | 
			
				
			 | 
			
			
				-        function_check backup_directory_to_usb 
			 | 
		
	
		
			
			| 
				184
			 | 
			
				
			 | 
			
			
				-        backup_directory_to_friend $source_directory mailpile 
			 | 
		
	
		
			
			| 
				185
			 | 
			
				
			 | 
			
			
				- 
			 | 
		
	
		
			
			| 
				186
			 | 
			
				
			 | 
			
			
				-        systemctl start mailpile 
			 | 
		
	
		
			
			| 
				187
			 | 
			
				
			 | 
			
			
				-    fi 
			 | 
		
	
		
			
			| 
				
			 | 
			
				121
			 | 
			
			
				+    echo -n '' 
			 | 
		
	
		
			
			| 
				188
			 | 
			
				122
			 | 
			
			
				 } 
			 | 
		
	
		
			
			| 
				189
			 | 
			
				123
			 | 
			
			
				  
			 | 
		
	
		
			
			| 
				190
			 | 
			
				124
			 | 
			
			
				 function restore_remote_mailpile { 
			 | 
		
	
		
			
			| 
				191
			 | 
			
				
			 | 
			
			
				-    if [ ! -f /etc/systemd/system/mailpile.service ]; then 
			 | 
		
	
		
			
			| 
				192
			 | 
			
				
			 | 
			
			
				-        return 
			 | 
		
	
		
			
			| 
				193
			 | 
			
				
			 | 
			
			
				-    fi 
			 | 
		
	
		
			
			| 
				194
			 | 
			
				
			 | 
			
			
				-    MAILPILE_DOMAIN_NAME='mailpile.local' 
			 | 
		
	
		
			
			| 
				195
			 | 
			
				
			 | 
			
			
				-    if grep -q "mailpile domain" $COMPLETION_FILE; then 
			 | 
		
	
		
			
			| 
				196
			 | 
			
				
			 | 
			
			
				-        MAILPILE_DOMAIN_NAME=$(get_completion_param "mailpile domain") 
			 | 
		
	
		
			
			| 
				197
			 | 
			
				
			 | 
			
			
				-    fi 
			 | 
		
	
		
			
			| 
				198
			 | 
			
				
			 | 
			
			
				-    if [ $MAILPILE_DOMAIN_NAME ]; then 
			 | 
		
	
		
			
			| 
				199
			 | 
			
				
			 | 
			
			
				-        systemctl stop mailpile 
			 | 
		
	
		
			
			| 
				200
			 | 
			
				
			 | 
			
			
				- 
			 | 
		
	
		
			
			| 
				201
			 | 
			
				
			 | 
			
			
				-        temp_restore_dir=/root/tempmailpile 
			 | 
		
	
		
			
			| 
				202
			 | 
			
				
			 | 
			
			
				-        restore_directory_from_friend $temp_restore_dir mailpile 
			 | 
		
	
		
			
			| 
				203
			 | 
			
				
			 | 
			
			
				-        if [ -d /var/www/${MAILPILE_DOMAIN_NAME}/mail/.local ]; then 
			 | 
		
	
		
			
			| 
				204
			 | 
			
				
			 | 
			
			
				-            mv /var/www/${MAILPILE_DOMAIN_NAME}/mail/.local /var/www/${MAILPILE_DOMAIN_NAME}/mail/.previous 
			 | 
		
	
		
			
			| 
				205
			 | 
			
				
			 | 
			
			
				-        fi 
			 | 
		
	
		
			
			| 
				206
			 | 
			
				
			 | 
			
			
				-        temp_source_dir=$(find ${temp_restore_dir} -name ".local") 
			 | 
		
	
		
			
			| 
				207
			 | 
			
				
			 | 
			
			
				-        cp -r ${temp_source_dir} /var/www/${MAILPILE_DOMAIN_NAME}/mail/ 
			 | 
		
	
		
			
			| 
				208
			 | 
			
				
			 | 
			
			
				-        if [ ! "$?" = "0" ]; then 
			 | 
		
	
		
			
			| 
				209
			 | 
			
				
			 | 
			
			
				-            if [ -d mv /var/www/${MAILPILE_DOMAIN_NAME}/mail/.previous ]; then 
			 | 
		
	
		
			
			| 
				210
			 | 
			
				
			 | 
			
			
				-                mv /var/www/${MAILPILE_DOMAIN_NAME}/mail/.previous /var/www/${MAILPILE_DOMAIN_NAME}/mail/.local 
			 | 
		
	
		
			
			| 
				211
			 | 
			
				
			 | 
			
			
				-            fi 
			 | 
		
	
		
			
			| 
				212
			 | 
			
				
			 | 
			
			
				-            backup_unmount_drive 
			 | 
		
	
		
			
			| 
				213
			 | 
			
				
			 | 
			
			
				-            exit 36732 
			 | 
		
	
		
			
			| 
				214
			 | 
			
				
			 | 
			
			
				-        fi 
			 | 
		
	
		
			
			| 
				215
			 | 
			
				
			 | 
			
			
				-        rm -rf ${temp_restore_dir} 
			 | 
		
	
		
			
			| 
				216
			 | 
			
				
			 | 
			
			
				-        chown -R mailpile: /var/www/$MAILPILE_DOMAIN_NAME/mail/ 
			 | 
		
	
		
			
			| 
				217
			 | 
			
				
			 | 
			
			
				- 
			 | 
		
	
		
			
			| 
				218
			 | 
			
				
			 | 
			
			
				-        if [ -d /etc/letsencrypt/live/${MAILPILE_DOMAIN_NAME} ]; then 
			 | 
		
	
		
			
			| 
				219
			 | 
			
				
			 | 
			
			
				-            ln -s /etc/letsencrypt/live/${MAILPILE_DOMAIN_NAME}/privkey.pem /etc/ssl/private/${MAILPILE_DOMAIN_NAME}.key 
			 | 
		
	
		
			
			| 
				220
			 | 
			
				
			 | 
			
			
				-            ln -s /etc/letsencrypt/live/${MAILPILE_DOMAIN_NAME}/fullchain.pem /etc/ssl/certs/${MAILPILE_DOMAIN_NAME}.pem 
			 | 
		
	
		
			
			| 
				221
			 | 
			
				
			 | 
			
			
				-        fi 
			 | 
		
	
		
			
			| 
				222
			 | 
			
				
			 | 
			
			
				- 
			 | 
		
	
		
			
			| 
				223
			 | 
			
				
			 | 
			
			
				-        systemctl start mailpile 
			 | 
		
	
		
			
			| 
				224
			 | 
			
				
			 | 
			
			
				-    fi 
			 | 
		
	
		
			
			| 
				
			 | 
			
				125
			 | 
			
			
				+    echo -n '' 
			 | 
		
	
		
			
			| 
				225
			 | 
			
				126
			 | 
			
			
				 } 
			 | 
		
	
		
			
			| 
				226
			 | 
			
				127
			 | 
			
			
				  
			 | 
		
	
		
			
			| 
				227
			 | 
			
				128
			 | 
			
			
				 function remove_mailpile { 
			 |