freedombone-utils-backup 18KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512
  1. #!/bin/bash
  2. #
  3. # .---. . .
  4. # | | |
  5. # |--- .--. .-. .-. .-.| .-. .--.--. |.-. .-. .--. .-.
  6. # | | (.-' (.-' ( | ( )| | | | )( )| | (.-'
  7. # ' ' --' --' -' - -' ' ' -' -' -' ' - --'
  8. #
  9. # Freedom in the Cloud
  10. #
  11. # Backup functions
  12. #
  13. # License
  14. # =======
  15. #
  16. # Copyright (C) 2014-2016 Bob Mottram <bob@robotics.uk.to>
  17. #
  18. # This program is free software: you can redistribute it and/or modify
  19. # it under the terms of the GNU Affero General Public License as published by
  20. # the Free Software Foundation, either version 3 of the License, or
  21. # (at your option) any later version.
  22. #
  23. # This program is distributed in the hope that it will be useful,
  24. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  25. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  26. # GNU Affero General Public License for more details.
  27. #
  28. # You should have received a copy of the GNU Affero General Public License
  29. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  30. # whether a given site is being suspended during backup
  31. SUSPENDED_SITE=
  32. function suspend_site {
  33. # suspends a given website
  34. SUSPENDED_SITE="$1"
  35. nginx_dissite $SUSPENDED_SITE
  36. service nginx reload
  37. }
  38. function restart_site {
  39. # restarts a given website
  40. if [ ! $SUSPENDED_SITE ]; then
  41. return
  42. fi
  43. nginx_ensite $SUSPENDED_SITE
  44. service nginx reload
  45. SUSPENDED_SITE=
  46. }
  47. function configure_backup_key {
  48. if grep -Fxq "configure_backup_key" $COMPLETION_FILE; then
  49. return
  50. fi
  51. apt-get -y install gnupg
  52. BACKUP_KEY_EXISTS=$(gpg_key_exists "root" "$MY_NAME (backup key)")
  53. if [[ $BACKUP_KEY_EXISTS == "yes" ]]; then
  54. return
  55. fi
  56. # Generate a GPG key for backups
  57. BACKUP_KEY_EXISTS=$(gpg_key_exists "$MY_USERNAME" "$MY_NAME (backup key)")
  58. if [[ $BACKUP_KEY_EXISTS == "no" ]]; then
  59. echo 'Key-Type: 1' > /home/$MY_USERNAME/gpg-genkey.conf
  60. echo 'Key-Length: 4096' >> /home/$MY_USERNAME/gpg-genkey.conf
  61. echo 'Subkey-Type: 1' >> /home/$MY_USERNAME/gpg-genkey.conf
  62. echo 'Subkey-Length: 4096' >> /home/$MY_USERNAME/gpg-genkey.conf
  63. echo "Name-Real: $MY_NAME" >> /home/$MY_USERNAME/gpg-genkey.conf
  64. echo "Name-Email: $MY_EMAIL_ADDRESS" >> /home/$MY_USERNAME/gpg-genkey.conf
  65. echo "Name-Comment: backup key" >> /home/$MY_USERNAME/gpg-genkey.conf
  66. echo 'Expire-Date: 0' >> /home/$MY_USERNAME/gpg-genkey.conf
  67. chown $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/gpg-genkey.conf
  68. echo $'Backup key does not exist. Creating it.'
  69. su -c "gpg --batch --gen-key /home/$MY_USERNAME/gpg-genkey.conf" - $MY_USERNAME
  70. shred -zu /home/$MY_USERNAME/gpg-genkey.conf
  71. echo $'Checking that the Backup key was created'
  72. BACKUP_KEY_EXISTS=$(gpg_key_exists "$MY_USERNAME" "$MY_NAME (backup key)")
  73. if [[ $BACKUP_KEY_EXISTS == "no" ]]; then
  74. echo $'Backup key could not be created'
  75. exit 43382
  76. fi
  77. fi
  78. MY_BACKUP_KEY_ID=$(su -c "gpg --list-keys \"$MY_NAME (backup key)\" | grep 'pub '" - $MY_USERNAME | awk -F ' ' '{print $2}' | awk -F '/' '{print $2}')
  79. echo "Backup key: $MY_BACKUP_KEY_ID"
  80. MY_BACKUP_KEY=/home/$MY_USERNAME/backup_key
  81. su -c "gpg --output ${MY_BACKUP_KEY}_public.asc --armor --export $MY_BACKUP_KEY_ID" - $MY_USERNAME
  82. su -c "gpg --output ${MY_BACKUP_KEY}_private.asc --armor --export-secret-key $MY_BACKUP_KEY_ID" - $MY_USERNAME
  83. if [ ! -f ${MY_BACKUP_KEY}_public.asc ]; then
  84. echo 'Public backup key could not be exported'
  85. exit 36829
  86. fi
  87. if [ ! -f ${MY_BACKUP_KEY}_private.asc ]; then
  88. echo 'Private backup key could not be exported'
  89. exit 29235
  90. fi
  91. # import backup key to root user
  92. gpg --import --import ${MY_BACKUP_KEY}_public.asc
  93. gpg --allow-secret-key-import --import ${MY_BACKUP_KEY}_private.asc
  94. shred -zu ${MY_BACKUP_KEY}_public.asc
  95. shred -zu ${MY_BACKUP_KEY}_private.asc
  96. echo 'configure_backup_key' >> $COMPLETION_FILE
  97. }
  98. function backup_to_friends_servers {
  99. # update crontab
  100. echo '#!/bin/bash' > /etc/cron.daily/backuptofriends
  101. echo "if [ -f /usr/local/bin/${PROJECT_NAME}-backup-remote ]; then" >> /etc/cron.daily/backuptofriends
  102. echo " /usr/local/bin/${PROJECT_NAME}-backup-remote" >> /etc/cron.daily/backuptofriends
  103. echo 'else' >> /etc/cron.daily/backuptofriends
  104. echo " /usr/bin/${PROJECT_NAME}-backup-remote" >> /etc/cron.daily/backuptofriends
  105. echo 'fi' >> /etc/cron.daily/backuptofriends
  106. chmod +x /etc/cron.daily/backuptofriends
  107. }
  108. function backup_mount_drive {
  109. if [ $1 ]; then
  110. USB_DRIVE=/dev/${1}1
  111. fi
  112. # get the admin user
  113. ADMIN_USERNAME=$(cat $COMPLETION_FILE | grep "Admin user" | awk -F ':' '{print $2}')
  114. if [ $2 ]; then
  115. ADMIN_USERNAME=$2
  116. fi
  117. ADMIN_NAME=$(getent passwd $ADMIN_USERNAME | cut -d: -f5 | cut -d, -f1)
  118. if [ $3 ]; then
  119. RESTORE_APP=$3
  120. fi
  121. # check that the backup destination is available
  122. if [ ! -b $USB_DRIVE ]; then
  123. echo $"Please attach a USB drive"
  124. exit 1
  125. fi
  126. # unmount if already mounted
  127. umount -f $USB_MOUNT
  128. if [ ! -d $USB_MOUNT ]; then
  129. mkdir $USB_MOUNT
  130. fi
  131. if [ -f /dev/mapper/encrypted_usb ]; then
  132. rm -rf /dev/mapper/encrypted_usb
  133. fi
  134. cryptsetup luksClose encrypted_usb
  135. # mount the encrypted backup drive
  136. cryptsetup luksOpen $USB_DRIVE encrypted_usb
  137. if [ "$?" = "0" ]; then
  138. USB_DRIVE=/dev/mapper/encrypted_usb
  139. fi
  140. mount $USB_DRIVE $USB_MOUNT
  141. if [ ! "$?" = "0" ]; then
  142. echo $"There was a problem mounting the USB drive to $USB_MOUNT"
  143. rm -rf $USB_MOUNT
  144. exit 783452
  145. fi
  146. }
  147. function backup_unmount_drive {
  148. if [ $1 ]; then
  149. USB_DRIVE=${1}
  150. if [ $2 ]; then
  151. USB_MOUNT=${2}
  152. fi
  153. fi
  154. sync
  155. umount $USB_MOUNT
  156. if [ ! "$?" = "0" ]; then
  157. echo $"Unable to unmount the drive."
  158. rm -rf $USB_MOUNT
  159. exit 9
  160. fi
  161. rm -rf $USB_MOUNT
  162. if [[ $USB_DRIVE == /dev/mapper/encrypted_usb ]]; then
  163. echo $"Unmount encrypted USB"
  164. cryptsetup luksClose encrypted_usb
  165. fi
  166. if [ -f /dev/mapper/encrypted_usb ]; then
  167. rm -rf /dev/mapper/encrypted_usb
  168. fi
  169. }
  170. function backup_database_local {
  171. if [ ${#DATABASE_PASSWORD} -lt 2 ]; then
  172. echo $"No MariaDB password was given"
  173. function_check restart_site
  174. restart_site
  175. exit 10
  176. fi
  177. if [ ! -d $USB_MOUNT/backup/${1} ]; then
  178. mkdir -p $USB_MOUNT/backup/${1}
  179. fi
  180. if [ ! -d $USB_MOUNT/backup/${1}data ]; then
  181. mkdir -p $USB_MOUNT/backup/${1}data
  182. fi
  183. if [ ! -d /root/temp${1}data ]; then
  184. mkdir -p /root/temp${1}data
  185. fi
  186. echo $"Obtaining ${1} database backup"
  187. mysqldump --lock-tables --password="$DATABASE_PASSWORD" ${1} > /root/temp${1}data/${1}.sql
  188. if [ ! -s /root/temp${1}data/${1}.sql ]; then
  189. echo $"${1} database could not be saved"
  190. shred -zu /root/temp${1}data/*
  191. rm -rf /root/temp${1}data
  192. umount $USB_MOUNT
  193. rm -rf $USB_MOUNT
  194. restart_site
  195. exit 6835872
  196. fi
  197. }
  198. function backup_directory_to_usb {
  199. if [ ! -d ${1} ]; then
  200. echo $"WARNING: directory does not exist: ${1}"
  201. else
  202. BACKUP_KEY_EXISTS=$(gpg --list-keys "$ADMIN_NAME (backup key)")
  203. if [ ! "$?" = "0" ]; then
  204. echo $"Backup key could not be found"
  205. function_check restart_site
  206. restart_site
  207. exit 6
  208. fi
  209. MY_BACKUP_KEY_ID=$(gpg --list-keys "$ADMIN_NAME (backup key)" | grep 'pub ' | awk -F ' ' '{print $2}' | awk -F '/' '{print $2}')
  210. if [ ! -d $USB_MOUNT/backup/${2} ]; then
  211. mkdir -p $USB_MOUNT/backup/${2}
  212. fi
  213. obnam force-lock -r $USB_MOUNT/backup/${2} --encrypt-with $MY_BACKUP_KEY_ID ${1}
  214. obnam backup -r $USB_MOUNT/backup/${2} --encrypt-with $MY_BACKUP_KEY_ID ${1}
  215. if [[ $ENABLE_BACKUP_VERIFICATION == "yes" ]]; then
  216. obnam verify -r $USB_MOUNT/backup/${2} --encrypt-with $MY_BACKUP_KEY_ID ${1}
  217. if [ ! "$?" = "0" ]; then
  218. umount $USB_MOUNT
  219. rm -rf $USB_MOUNT
  220. if [[ ${1} == "/root/temp"* || ${1} == *"tempbackup" ]]; then
  221. shred -zu ${1}/*
  222. rm -rf ${1}
  223. fi
  224. function_check restart_site
  225. restart_site
  226. exit 683252
  227. fi
  228. fi
  229. obnam forget --keep=30d -r $USB_MOUNT/backup/${2} --encrypt-with $MY_BACKUP_KEY_ID
  230. if [ ! "$?" = "0" ]; then
  231. umount $USB_MOUNT
  232. rm -rf $USB_MOUNT
  233. if [[ ${1} == "/root/temp"* || ${1} == *"tempbackup" ]]; then
  234. shred -zu ${1}/*
  235. rm -rf ${1}
  236. fi
  237. function_check restart_site
  238. restart_site
  239. exit 7
  240. fi
  241. if [[ ${1} == "/root/temp"* || ${1} == *"tempbackup" ]]; then
  242. shred -zu ${1}/*
  243. rm -rf ${1}
  244. fi
  245. fi
  246. }
  247. function backup_database_to_usb {
  248. database_name=$1
  249. backup_database_local $database_name
  250. backup_directory_to_usb /root/temp${database_name}data ${database_name}data
  251. }
  252. # after user files have been restored permissions may need to be set
  253. function set_user_permissions {
  254. echo $"Setting permissions"
  255. for d in /home/*/ ; do
  256. USERNAME=$(echo "$d" | awk -F '/' '{print $3}')
  257. if [[ $USERNAME != "git" && $USERNAME != "mirrors" && $USERNAME != "sync" ]]; then
  258. chown -R $USERNAME:$USERNAME /home/$USERNAME
  259. fi
  260. done
  261. }
  262. function backup_directory_to_friend {
  263. BACKUP_KEY_EXISTS=$(gpg --list-keys "$ADMIN_NAME (backup key)")
  264. if [ ! "$?" = "0" ]; then
  265. echo $"Backup key could not be found"
  266. function_check restart_site
  267. restart_site
  268. exit 43382
  269. fi
  270. ADMIN_BACKUP_KEY_ID=$(gpg --list-keys "$ADMIN_NAME (backup key)" | grep 'pub ' | awk -F ' ' '{print $2}' | awk -F '/' '{print $2}')
  271. if [ ! -d $SERVER_DIRECTORY/backup/${2} ]; then
  272. mkdir -p $SERVER_DIRECTORY/backup/${2}
  273. fi
  274. obnam force-lock -r $SERVER_DIRECTORY/backup/${2} --encrypt-with ${ADMIN_BACKUP_KEY_ID} ${1}
  275. obnam backup -r $SERVER_DIRECTORY/backup/${2} --encrypt-with ${ADMIN_BACKUP_KEY_ID} ${1}
  276. if [[ $ENABLE_VERIFICATION == "yes" ]]; then
  277. obnam verify -r $SERVER_DIRECTORY/backup/${2} --encrypt-with ${ADMIN_BACKUP_KEY_ID} ${1}
  278. if [ ! "$?" = "0" ]; then
  279. if [[ ${1} == "/root/temp"* || ${1} == *"tempbackup" ]]; then
  280. shred -zu /root/temp${2}/*
  281. rm -rf /root/temp${2}
  282. fi
  283. # Send a warning email
  284. echo "Unable to verify ${2}" | mail -s "${PROJECT_NAME} backup to friends" ${ADMIN_EMAIL_ADDRESS}
  285. function_check restart_site
  286. restart_site
  287. exit 953
  288. fi
  289. fi
  290. obnam forget --keep=30d -r $SERVER_DIRECTORY/backup/${2} --encrypt-with ${ADMIN_BACKUP_KEY_ID}
  291. if [ ! "$?" = "0" ]; then
  292. if [[ ${1} == "/root/temp"* || ${1} == *"tempbackup" ]]; then
  293. shred -zu /root/temp${2}/*
  294. rm -rf /root/temp${2}
  295. fi
  296. # Send a warning email
  297. echo "Unable to backup ${2}" | mail -s "${PROJECT_NAME} backup to friends" ${ADMIN_EMAIL_ADDRESS}
  298. function_check restart_site
  299. restart_site
  300. exit 853
  301. fi
  302. if [[ ${1} == "/root/temp"* || ${1} == *"tempbackup" ]]; then
  303. shred -zu /root/temp${2}/*
  304. rm -rf /root/temp${2}
  305. fi
  306. }
  307. function backup_database_remote {
  308. if [ ${#DATABASE_PASSWORD} -lt 2 ]; then
  309. echo $"No MariaDB password was given"
  310. function_check restart_site
  311. restart_site
  312. exit 5783
  313. fi
  314. if [ ! -d $SERVER_DIRECTORY/backup/${1} ]; then
  315. mkdir -p $SERVER_DIRECTORY/backup/${1}
  316. fi
  317. if [ ! -d $SERVER_DIRECTORY/backup/${1}data ]; then
  318. mkdir -p $SERVER_DIRECTORY/backup/${1}data
  319. fi
  320. if [ ! -d /root/temp${1}data ]; then
  321. mkdir -p /root/temp${1}data
  322. fi
  323. echo "Obtaining ${1} database backup"
  324. mysqldump --password=$DATABASE_PASSWORD ${1} > /root/temp${1}data/${1}.sql
  325. if [ ! -s /root/temp${1}data/${1}.sql ]; then
  326. echo $"${1} database could not be saved"
  327. shred -zu /root/temp${1}data/*
  328. rm -rf /root/temp${1}data
  329. # Send a warning email
  330. echo $"Unable to export ${1} database" | mail -s $"${PROJECT_NAME} backup to friends" $ADMIN_EMAIL_ADDRESS
  331. function_check restart_site
  332. restart_site
  333. exit 5738
  334. fi
  335. }
  336. function backup_database_to_friend {
  337. database_name=$1
  338. backup_database_remote $database_name
  339. backup_directory_to_friend /root/temp${database_name}data ${database_name}data
  340. }
  341. function backup_apps {
  342. localremote=$1
  343. FILES=/usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-*
  344. BACKUP_APPS_COMPLETED=()
  345. # for all the app scripts
  346. for filename in $FILES
  347. do
  348. app_name=$(echo "${filename}" | awk -F '-app-' '{print $2}')
  349. if [[ $(item_in_array ${app_name} ${BACKUP_APPS_COMPLETED[@]}) != 0 ]]; then
  350. if [[ "$(app_is_installed $a)" == "1" ]]; then
  351. BACKUP_APPS_COMPLETED+=("${app_name}")
  352. backup_${localremote}_${app_name}
  353. fi
  354. fi
  355. done
  356. }
  357. function restore_apps {
  358. localremote=$1
  359. FILES=/usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-*
  360. RESTORE_APPS_COMPLETED=()
  361. # for all the app scripts
  362. for filename in $FILES
  363. do
  364. app_name=$(echo "${filename}" | awk -F '-app-' '{print $2}')
  365. if [[ $RESTORE_APP == 'all' || $RESTORE_APP == "${app_name}" ]]; then
  366. if [[ $(item_in_array ${app_name} ${RESTORE_APPS_COMPLETED[@]}) != 0 ]]; then
  367. function_check app_is_installed
  368. if [[ "$(app_is_installed $a)" == "1" ]]; then
  369. RESTORE_APPS_COMPLETED+=("${app_name}")
  370. function_check restore_${localremote}_${app_name}
  371. restore_${localremote}_${app_name}
  372. fi
  373. fi
  374. fi
  375. done
  376. }
  377. function restore_database_from_friend {
  378. DATABASE_PASSWORD=
  379. RESTORE_SUBDIR="root"
  380. if [ -d $SERVER_DIRECTORY/backup/${1} ]; then
  381. echo $"Restoring ${1} database"
  382. restore_directory_from_friend /root/temp${1}data ${1}data
  383. if [ ! -f /root/temp${1}data/${RESTORE_SUBDIR}/temp${1}data/${1}.sql ]; then
  384. echo $"Unable to restore ${1} database"
  385. rm -rf /root/temp${1}data
  386. exit 503
  387. fi
  388. mysqlsuccess=$(mysql -u root --password="$DATABASE_PASSWORD" ${1} -o < /root/temp${1}data/${RESTORE_SUBDIR}/temp${1}data/${1}.sql)
  389. if [ ! "$?" = "0" ]; then
  390. echo "$mysqlsuccess"
  391. exit 964
  392. fi
  393. shred -zu /root/temp${1}data/${RESTORE_SUBDIR}/temp${1}data/*
  394. rm -rf /root/temp${1}data
  395. echo $"Restoring ${1} installation"
  396. restore_directory_from_friend /root/temp${1} ${1}
  397. RESTORE_SUBDIR="var"
  398. if [ ${1} ]; then
  399. if [ -d /var/www/${2}/htdocs ]; then
  400. if [ -d /root/temp${1}/${RESTORE_SUBDIR}/www/${2}/htdocs ]; then
  401. rm -rf /var/www/${2}/htdocs
  402. mv /root/temp${1}/${RESTORE_SUBDIR}/www/${2}/htdocs /var/www/${2}/
  403. if [ ! "$?" = "0" ]; then
  404. exit 683
  405. fi
  406. if [ -d /etc/letsencrypt/live/${2} ]; then
  407. ln -s /etc/letsencrypt/live/${2}/privkey.pem /etc/ssl/private/${2}.key
  408. ln -s /etc/letsencrypt/live/${2}/fullchain.pem /etc/ssl/certs/${2}.pem
  409. else
  410. # Ensure that the bundled SSL cert is being used
  411. if [ -f /etc/ssl/certs/${2}.bundle.crt ]; then
  412. sed -i "s|${2}.crt|${2}.bundle.crt|g" /etc/nginx/sites-available/${2}
  413. fi
  414. fi
  415. fi
  416. fi
  417. fi
  418. fi
  419. }
  420. function restore_database {
  421. RESTORE_SUBDIR="root"
  422. if [ -d $USB_MOUNT/backup/${1} ]; then
  423. echo $"Restoring ${1} database"
  424. function_check restore_directory_from_usb
  425. restore_directory_from_usb "/root/temp${1}data" "${1}data"
  426. if [ ! -f /root/temp${1}data/${RESTORE_SUBDIR}/temp${1}data/${1}.sql ]; then
  427. echo $"Unable to restore ${1} database"
  428. rm -rf /root/temp${1}data
  429. function_check set_user_permissions
  430. set_user_permissions
  431. function_check backup_unmount_drive
  432. backup_unmount_drive
  433. exit 503
  434. fi
  435. mysqlsuccess=$(mysql -u root --password=$DATABASE_PASSWORD ${1} -o < /root/temp${1}data/${RESTORE_SUBDIR}/temp${1}data/${1}.sql)
  436. if [ ! "$?" = "0" ]; then
  437. echo "$mysqlsuccess"
  438. function_check set_user_permissions
  439. set_user_permissions
  440. function_check set_user_permissions
  441. backup_unmount_drive
  442. exit 964
  443. fi
  444. shred -zu /root/temp${1}data/${RESTORE_SUBDIR}/temp${1}data/*
  445. rm -rf /root/temp${1}data
  446. echo $"Restoring ${1} installation"
  447. if [ ! -d /root/temp${1} ]; then
  448. mkdir /root/temp${1}
  449. fi
  450. function_check restore_directory_from_usb
  451. restore_directory_from_usb "/root/temp${1}" "${1}"
  452. RESTORE_SUBDIR="var"
  453. if [ ${2} ]; then
  454. if [ -d /var/www/${2}/htdocs ]; then
  455. if [ -d /root/temp${1}/${RESTORE_SUBDIR}/www/${2}/htdocs ]; then
  456. rm -rf /var/www/${2}/htdocs
  457. mv /root/temp${1}/${RESTORE_SUBDIR}/www/${2}/htdocs /var/www/${2}/
  458. if [ ! "$?" = "0" ]; then
  459. set_user_permissions
  460. backup_unmount_drive
  461. exit 683
  462. fi
  463. if [ -d /etc/letsencrypt/live/${2} ]; then
  464. ln -s /etc/letsencrypt/live/${2}/privkey.pem /etc/ssl/private/${2}.key
  465. ln -s /etc/letsencrypt/live/${2}/fullchain.pem /etc/ssl/certs/${2}.pem
  466. else
  467. # Ensure that the bundled SSL cert is being used
  468. if [ -f /etc/ssl/certs/${2}.bundle.crt ]; then
  469. sed -i "s|${2}.crt|${2}.bundle.crt|g" /etc/nginx/sites-available/${2}
  470. fi
  471. fi
  472. fi
  473. fi
  474. fi
  475. fi
  476. }
  477. # NOTE: deliberately no exit 0