freedombone-app-ghost 23KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626
  1. #!/bin/bash
  2. #
  3. # .---. . .
  4. # | | |
  5. # |--- .--. .-. .-. .-.| .-. .--.--. |.-. .-. .--. .-.
  6. # | | (.-' (.-' ( | ( )| | | | )( )| | (.-'
  7. # ' ' --' --' -' - -' ' ' -' -' -' ' - --'
  8. #
  9. # Freedom in the Cloud
  10. #
  11. # Ghost blog
  12. #
  13. # License
  14. # =======
  15. #
  16. # Copyright (C) 2016-2017 Bob Mottram <bob@freedombone.net>
  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. VARIANTS="full full-vim writer"
  31. IN_DEFAULT_INSTALL=0
  32. SHOW_ON_ABOUT=1
  33. GHOST_DOMAIN_NAME=
  34. GHOST_CODE=
  35. GHOST_ONION_PORT=8104
  36. GHOST_PORT=2368
  37. GHOST_VERSION='0.11.8'
  38. GHOST_HASH='244faad0b16eb1b90c8095f1e536db65299a3a2d85a20af76342be3707522b38'
  39. GHOST_DOWNLOAD_URL="https://github.com/TryGhost/Ghost/releases/download/${GHOST_VERSION}/Ghost-${GHOST_VERSION}.zip"
  40. ghost_variables=(GHOST_DOMAIN_NAME
  41. GHOST_CODE
  42. GHOST_ADMIN_PASSWORD
  43. ONION_ONLY
  44. DDNS_PROVIDER
  45. MY_USERNAME)
  46. function ghost_replace_jquery {
  47. sed -i "s|code.jquery.com/jquery-${previous_jquery_version}.min.js|$GHOST_DOMAIN_NAME/jquery-${jquery_version}.js|g" content/themes/casper/default.hbs
  48. sed -i "s|code.jquery.com/jquery-${previous_jquery_version}.min.js|$GHOST_DOMAIN_NAME/jquery-${jquery_version}.js|g" core/server/data/migration/fixtures/004/01-move-jquery-with-alert.js
  49. sed -i "s|code.jquery.com/jquery-${previous_jquery_version}.min.js|$GHOST_DOMAIN_NAME/jquery-${jquery_version}.js|g" node_modules/gscan/app/tpl/layouts/default.hbs
  50. }
  51. function ghost_remove_offsite_links {
  52. cd /var/www/$GHOST_DOMAIN_NAME/htdocs
  53. # remove google font links
  54. # Note that the privacy options in config.js aren't sufficient to remove Google's tentacles
  55. sed -i "s/fonts.googleapis.com/$GHOST_DOMAIN_NAME/g" content/themes/casper/default.hbs
  56. sed -i "s/fonts.googleapis.com/$GHOST_DOMAIN_NAME/g" core/server/apps/amp/lib/views/amp.hbs
  57. # copy jquery locally
  58. previous_jquery_version='1.12.0'
  59. jquery_version='1.12.4'
  60. if [ ! -f /var/www/$GHOST_DOMAIN_NAME/htdocs/jquery-${jquery_version}.js ]; then
  61. wget https://code.jquery.com/jquery-${jquery_version}.js
  62. jquery_hash=$(sha256sum jquery-${jquery_version}.js | awk -F ' ' '{print $1}')
  63. if [[ "$jquery_hash" != '430f36f9b5f21aae8cc9dca6a81c4d3d84da5175eaedcf2fdc2c226302cb3575' ]]; then
  64. echo $'Unexpected jquery hash value'
  65. exit 258442
  66. fi
  67. fi
  68. ghost_replace_jquery
  69. previous_jquery_version='1.11.3'
  70. ghost_replace_jquery
  71. }
  72. function ghost_replace_proprietary_services {
  73. replace_file=$1
  74. sed -i 's|Twitter Profile|GNU Social Profile|g' $replace_file
  75. sed -i 's|Twitter Username|GNU Social Username|g' $replace_file
  76. sed -i 's|twitter.com|quitter.se|g' $replace_file
  77. sed -i 's|Facebook Page|Hubzilla Channel|g' $replace_file
  78. sed -i 's|www.facebook.com/username|hubzilladomain/username|g' $replace_file
  79. sed -i 's|www.facebook.com/ghost|hubzilladomain/username|g' $replace_file
  80. sed -i 's|www.facebook.com/testuser|hubzilladomain/username|g' $replace_file
  81. sed -i 's|www.facebook.com/testing|hubzilladomain/username|g' $replace_file
  82. sed -i 's|www.facebook.com/test|hubzilladomain/username|g' $replace_file
  83. sed -i 's|www.facebook.com/yourUsername|hubzilladomain/username|g' $replace_file
  84. sed -i 's|www.facebook.com/yourPage|hubzilladomain/username|g' $replace_file
  85. sed -i 's|Facebook Username|Hubzilla Channel|g' $replace_file
  86. sed -i 's|www.facebook.com|hubzilladomain|g' $replace_file
  87. sed -i 's|facebook value|hubzilla value|g' $replace_file
  88. sed -i '/<section class="share">/,/<\/section>/d' $replace_file
  89. }
  90. function ghost_replace_services {
  91. ghost_replace_proprietary_services /var/www/${GHOST_DOMAIN_NAME}/htdocs/core/built/assets/ghost.js
  92. ghost_replace_proprietary_services /var/www/${GHOST_DOMAIN_NAME}/htdocs/core/built/assets/ghost.min.js
  93. ghost_replace_proprietary_services /var/www/${GHOST_DOMAIN_NAME}/htdocs/content/themes/casper/post.hbs
  94. }
  95. function remove_user_ghost {
  96. remove_username="$1"
  97. }
  98. function add_user_ghost {
  99. if [[ $(app_is_installed ghost) == "0" ]]; then
  100. echo '0'
  101. return
  102. fi
  103. new_username="$1"
  104. new_user_password="$2"
  105. echo '0'
  106. }
  107. function install_interactive_ghost {
  108. if [ ! $ONION_ONLY ]; then
  109. ONION_ONLY='no'
  110. fi
  111. if [[ $ONION_ONLY != "no" ]]; then
  112. GHOST_DOMAIN_NAME='ghost.local'
  113. write_config_param "GHOST_DOMAIN_NAME" "$GHOST_DOMAIN_NAME"
  114. else
  115. function_check interactive_site_details
  116. interactive_site_details "ghost" "GHOST_DOMAIN_NAME" "GHOST_CODE"
  117. fi
  118. APP_INSTALLED=1
  119. }
  120. function change_password_ghost {
  121. GHOST_USERNAME="$1"
  122. GHOST_PASSWORD="$2"
  123. if [ ${#GHOST_PASSWORD} -lt 8 ]; then
  124. echo $'Ghost password is too short'
  125. return
  126. fi
  127. #${PROJECT_NAME}-pass -u $GHOST_USERNAME -a ghost -p "$GHOST_PASSWORD"
  128. }
  129. function reconfigure_ghost {
  130. echo -n ''
  131. }
  132. function upgrade_ghost {
  133. if [ ! -d /var/www/$GHOST_DOMAIN_NAME/htdocs ]; then
  134. return
  135. fi
  136. if ! grep -q "ghost version:" $COMPLETION_FILE; then
  137. CURR_GHOST_VERSION=${GHOST_VERSION}b
  138. else
  139. CURR_GHOST_VERSION=$(get_completion_param "ghost version")
  140. fi
  141. if [[ "$GHOST_VERSION" == "$CURR_GHOST_VERSION" ]]; then
  142. return
  143. fi
  144. read_config_param "GHOST_DOMAIN_NAME"
  145. GHOST_PATH=/var/www/$GHOST_DOMAIN_NAME/htdocs
  146. cd $GHOST_PATH
  147. if [ ! -f ghost-${GHOST_VERSION}.zip ]; then
  148. wget ${GHOST_DOWNLOAD_URL}
  149. fi
  150. if [ ! -f Ghost-${GHOST_VERSION}.zip ]; then
  151. echo $'Unable to download ghost'
  152. exit 367245
  153. fi
  154. # check the hash
  155. hash=$(sha256sum Ghost-${GHOST_VERSION}.zip | awk -F ' ' '{print $1}')
  156. if [[ "$hash" != "$GHOST_HASH" ]]; then
  157. echo $'ghost hash does not match'
  158. exit 729856
  159. fi
  160. unzip -o Ghost-${GHOST_VERSION}.zip
  161. if [ ! -f $GHOST_PATH/index.js ]; then
  162. echo $'ghost failed to unzip'
  163. exit 63835
  164. fi
  165. sed -i "/sqlite/d" $GHOST_PATH/package.json
  166. npm install --production
  167. chown -R ghost: $GHOST_PATH/
  168. ghost_replace_services
  169. chown -R ghost: /var/www/${GHOST_DOMAIN_NAME}/htdocs
  170. ghost_remove_offsite_links
  171. sed -i "s|ghost version.*|ghost version:${GHOST_VERSION}|g" ${COMPLETION_FILE}
  172. systemctl restart ghost
  173. }
  174. function backup_local_ghost {
  175. GHOST_DOMAIN_NAME='ghost.local'
  176. if grep -q "ghost domain" $COMPLETION_FILE; then
  177. GHOST_DOMAIN_NAME=$(get_completion_param "ghost domain")
  178. fi
  179. ghost_path=/var/www/${GHOST_DOMAIN_NAME}/htdocs
  180. if [ -d $ghost_path ]; then
  181. function_check backup_database_to_usb
  182. backup_database_to_usb ghost
  183. backup_directory_to_usb $ghost_path ghost
  184. restart_site
  185. fi
  186. }
  187. function restore_local_ghost {
  188. GHOST_DOMAIN_NAME='ghost.local'
  189. if grep -q "ghost domain" $COMPLETION_FILE; then
  190. GHOST_DOMAIN_NAME=$(get_completion_param "ghost domain")
  191. fi
  192. if [ $GHOST_DOMAIN_NAME ]; then
  193. systemctl stop ghost
  194. function_check ghost_create_database
  195. ghost_create_database
  196. function_check restore_database
  197. restore_database ghost ${GHOST_DOMAIN_NAME}
  198. systemctl start ghost
  199. restart_site
  200. fi
  201. }
  202. function backup_remote_ghost {
  203. GHOST_DOMAIN_NAME='ghost.local'
  204. if grep -q "ghost domain" $COMPLETION_FILE; then
  205. GHOST_DOMAIN_NAME=$(get_completion_param "ghost domain")
  206. fi
  207. temp_backup_dir=/var/www/${GHOST_DOMAIN_NAME}/htdocs
  208. if [ -d $temp_backup_dir ]; then
  209. suspend_site ${GHOST_DOMAIN_NAME}
  210. backup_database_to_friend ghost
  211. backup_directory_to_friend $temp_backup_dir ghost
  212. restart_site
  213. else
  214. echo $"Ghost domain specified but not found in /var/www/${GHOST_DOMAIN_NAME}"
  215. exit 2578
  216. fi
  217. }
  218. function restore_remote_ghost {
  219. GHOST_DOMAIN_NAME='ghost.local'
  220. if grep -q "ghost domain" $COMPLETION_FILE; then
  221. GHOST_DOMAIN_NAME=$(get_completion_param "ghost domain")
  222. fi
  223. systemctl stop ghost
  224. function_check get_mariadb_password
  225. get_mariadb_password
  226. function_check restore_database_from_friend
  227. function_check ghost_create_database
  228. ghost_create_database
  229. restore_database_from_friend ghost ${GHOST_DOMAIN_NAME}
  230. systemctl start ghost
  231. restart_site
  232. chown -R ghost: /var/www/$GHOST_DOMAIN_NAME/htdocs/
  233. }
  234. function remove_ghost {
  235. if [ ${#GHOST_DOMAIN_NAME} -eq 0 ]; then
  236. return
  237. fi
  238. systemctl stop ghost
  239. systemctl disable ghost
  240. rm /etc/systemd/system/ghost.service
  241. systemctl daemon-reload
  242. function_check remove_nodejs
  243. remove_nodejs ghost
  244. drop_database ghost
  245. remove_backup_database_local ghost
  246. read_config_param "GHOST_DOMAIN_NAME"
  247. nginx_dissite $GHOST_DOMAIN_NAME
  248. remove_certs ${GHOST_DOMAIN_NAME}
  249. if [ -f /etc/nginx/sites-available/$GHOST_DOMAIN_NAME ]; then
  250. rm -f /etc/nginx/sites-available/$GHOST_DOMAIN_NAME
  251. fi
  252. if [ -d /var/www/$GHOST_DOMAIN_NAME ]; then
  253. rm -rf /var/www/$GHOST_DOMAIN_NAME
  254. fi
  255. remove_config_param GHOST_DOMAIN_NAME
  256. remove_config_param GHOST_CODE
  257. function_check remove_onion_service
  258. remove_onion_service ghost ${GHOST_ONION_PORT}
  259. remove_completion_param "install_ghost"
  260. sed -i '/Ghost/d' $COMPLETION_FILE
  261. sed -i '/ghost/d' $COMPLETION_FILE
  262. groupdel -f ghost
  263. userdel -r ghost
  264. function_check remove_ddns_domain
  265. remove_ddns_domain $GHOST_DOMAIN_NAME
  266. }
  267. function ghost_create_config {
  268. ghost_config=/var/www/${GHOST_DOMAIN_NAME}/htdocs/config.js
  269. echo "var path = require('path')," > $ghost_config
  270. echo ' config;' >> $ghost_config
  271. echo '' >> $ghost_config
  272. echo 'config = {' >> $ghost_config
  273. echo ' production: {' >> $ghost_config
  274. echo ' // This needs to be http and NOT https' >> $ghost_config
  275. echo " url: 'http://${GHOST_DOMAIN_NAME}'," >> $ghost_config
  276. echo ' mail: {' >> $ghost_config
  277. echo " transport: 'SMTP'," >> $ghost_config
  278. echo ' options: {' >> $ghost_config
  279. echo " service: 'Sendmail'," >> $ghost_config
  280. echo ' }' >> $ghost_config
  281. echo ' },' >> $ghost_config
  282. echo ' database: {' >> $ghost_config
  283. echo " client: 'mysql'," >> $ghost_config
  284. echo ' connection: {' >> $ghost_config
  285. echo " host : '127.0.0.1'," >> $ghost_config
  286. echo " user : 'root'," >> $ghost_config
  287. echo " password : '${MARIADB_PASSWORD}'," >> $ghost_config
  288. echo " database : 'ghost'," >> $ghost_config
  289. echo " charset : 'utf8'" >> $ghost_config
  290. echo ' }' >> $ghost_config
  291. echo ' },' >> $ghost_config
  292. echo '' >> $ghost_config
  293. echo ' server: {' >> $ghost_config
  294. echo " host: '127.0.0.1'," >> $ghost_config
  295. echo " port: '${GHOST_PORT}'" >> $ghost_config
  296. echo ' },' >> $ghost_config
  297. echo ' privacy: {' >> $ghost_config
  298. echo ' useTinfoil: true,' >> $ghost_config
  299. echo ' },' >> $ghost_config
  300. echo ' logging: false' >> $ghost_config
  301. echo ' }' >> $ghost_config
  302. echo '};' >> $ghost_config
  303. echo '' >> $ghost_config
  304. echo 'module.exports = config;' >> $ghost_config
  305. chmod 700 $ghost_config
  306. }
  307. function ghost_create_database {
  308. if [ -f ${IMAGE_PASSWORD_FILE} ]; then
  309. GIT_ADMIN_PASSWORD="$(printf `cat $IMAGE_PASSWORD_FILE`)"
  310. else
  311. if [ ! ${GIT_ADMIN_PASSWORD} ]; then
  312. GIT_ADMIN_PASSWORD="$(create_password ${MINIMUM_PASSWORD_LENGTH})"
  313. fi
  314. fi
  315. if [ ! $GIT_ADMIN_PASSWORD ]; then
  316. return
  317. fi
  318. function_check get_mariadb_password
  319. get_mariadb_password
  320. function_check create_database
  321. create_database ghost "$GHOST_ADMIN_PASSWORD"
  322. }
  323. function install_ghost {
  324. if [ ! $ONION_ONLY ]; then
  325. ONION_ONLY='no'
  326. fi
  327. if [ ! $GHOST_DOMAIN_NAME ]; then
  328. echo $'The ghost domain name was not specified'
  329. exit 5062
  330. fi
  331. # for the avatar changing command
  332. apt-get -yq install unzip wget
  333. if [ ! -d /var/www/$GHOST_DOMAIN_NAME/htdocs ]; then
  334. mkdir -p /var/www/$GHOST_DOMAIN_NAME/htdocs
  335. fi
  336. cd /var/www/$GHOST_DOMAIN_NAME/htdocs
  337. wget ${GHOST_DOWNLOAD_URL}
  338. if [ ! -f Ghost-${GHOST_VERSION}.zip ]; then
  339. echo $'Unable to download ghost'
  340. rm -rf /var/www/$GHOST_DOMAIN_NAME
  341. exit 63892
  342. fi
  343. # check the hash
  344. hash=$(sha256sum Ghost-${GHOST_VERSION}.zip | awk -F ' ' '{print $1}')
  345. if [[ "$hash" != "$GHOST_HASH" ]]; then
  346. echo $'ghost hash does not match'
  347. exit 729856
  348. fi
  349. unzip -o Ghost-${GHOST_VERSION}.zip
  350. if [ ! -f /var/www/${GHOST_DOMAIN_NAME}/htdocs/index.js ]; then
  351. echo $'ghost failed to unzip'
  352. rm -rf /var/www/$GHOST_DOMAIN_NAME
  353. exit 63835
  354. fi
  355. function_check install_nodejs
  356. install_nodejs ghost
  357. sed -i "/sqlite/d" /var/www/${GHOST_DOMAIN_NAME}/htdocs/package.json
  358. cd /var/www/$GHOST_DOMAIN_NAME/htdocs
  359. npm install -g jison@0.4.13 --save
  360. npm install moment-timezone@0.5.13
  361. npm install express@4.15.3
  362. npm install lodash@4.17.4
  363. npm install uuid@3.0.1
  364. npm install bluebird@3.5.0
  365. npm install chalk@1.1.3
  366. npm install intl-messageformat@1.3.0
  367. npm install validator@7.0.0
  368. npm install express-hbs@1.0.4
  369. npm install glob@7.1.2
  370. npm install unidecode@0.1.8
  371. npm install csv-parser@1.11.0
  372. npm install archiver@1.3.0
  373. npm install fs-extra@3.0.1
  374. npm install extract-zip-fork@1.5.1
  375. npm install moment@2.18.1
  376. npm install nodemailer@4.0.1
  377. npm install html-to-text@3.3.0
  378. npm install gscan@1.1.0
  379. npm install body-parser@1.17.2
  380. npm install compression@1.6.2
  381. npm install morgan@1.8.2
  382. npm install semver@5.3.0
  383. npm install path-match@1.2.4
  384. npm install downsize@0.0.8
  385. npm install rss@1.2.2
  386. npm install cheerio@1.0.0-rc.1
  387. npm install passport@0.3.2
  388. npm install xml@1.0.1
  389. npm install multer@1.3.0
  390. npm install oauth2orize@1.8.0
  391. npm install connect-slashes@1.3.1
  392. npm install cors@2.8.3
  393. npm install netjet@1.1.3
  394. npm install jsonpath@0.2.11
  395. npm install image-size@0.5.4
  396. npm install passport-oauth2-client-password@0.1.2
  397. npm install passport-http-bearer@1.0.1
  398. npm install amperize@0.3.4
  399. npm install bcryptjs@2.4.3
  400. npm install knex@0.12.9
  401. npm install bookshelf@0.10.2
  402. npm install cookie-session@1.2.0
  403. npm install ghost-gql@0.0.6
  404. npm install intl@1.2.5
  405. npm install sanitize-html@1.14.1
  406. npm install showdown-ghost@0.3.6
  407. npm install superagent@3.5.2
  408. npm install mysql@2.1.1
  409. npm install --production
  410. function_check install_mariadb
  411. install_mariadb
  412. function_check get_mariadb_password
  413. get_mariadb_password
  414. function_check ghost_create_database
  415. ghost_create_database
  416. ghost_create_config
  417. adduser --system --home=/var/www/${GHOST_DOMAIN_NAME}/htdocs/ --group ghost
  418. chown -R ghost: /var/www/${GHOST_DOMAIN_NAME}/htdocs
  419. echo '[Unit]' > /etc/systemd/system/ghost.service
  420. echo 'Description=Ghost Blog' >> /etc/systemd/system/ghost.service
  421. echo 'After=syslog.target' >> /etc/systemd/system/ghost.service
  422. echo 'After=network.target' >> /etc/systemd/system/ghost.service
  423. echo 'After=mysqld.service' >> /etc/systemd/system/ghost.service
  424. echo '' >> /etc/systemd/system/ghost.service
  425. echo '[Service]' >> /etc/systemd/system/ghost.service
  426. echo 'Type=simple' >> /etc/systemd/system/ghost.service
  427. echo 'User=ghost' >> /etc/systemd/system/ghost.service
  428. echo 'Group=ghost' >> /etc/systemd/system/ghost.service
  429. echo "WorkingDirectory=/var/www/${GHOST_DOMAIN_NAME}/htdocs" >> /etc/systemd/system/ghost.service
  430. echo "ExecStart=/usr/local/bin/node /var/www/${GHOST_DOMAIN_NAME}/htdocs/index.js" >> /etc/systemd/system/ghost.service
  431. echo 'Restart=always' >> /etc/systemd/system/ghost.service
  432. echo 'RestartSec=60' >> /etc/systemd/system/ghost.service
  433. echo "Environment=NODE_ENV=production PORT=${GHOST_PORT}" >> /etc/systemd/system/ghost.service
  434. echo '' >> /etc/systemd/system/ghost.service
  435. echo '[Install]' >> /etc/systemd/system/ghost.service
  436. echo 'WantedBy=multi-user.target' >> /etc/systemd/system/ghost.service
  437. ghost_remove_offsite_links
  438. systemctl enable ghost
  439. systemctl daemon-reload
  440. systemctl start ghost
  441. GHOST_ONION_HOSTNAME=$(add_onion_service ghost 80 ${GHOST_ONION_PORT})
  442. if [[ ${ONION_ONLY} == "no" ]]; then
  443. function_check nginx_http_redirect
  444. nginx_http_redirect ${GHOST_DOMAIN_NAME}
  445. echo 'server {' >> /etc/nginx/sites-available/${GHOST_DOMAIN_NAME}
  446. echo ' listen 443 ssl;' >> /etc/nginx/sites-available/${GHOST_DOMAIN_NAME}
  447. echo ' listen [::]:443 ssl;' >> /etc/nginx/sites-available/${GHOST_DOMAIN_NAME}
  448. echo " root /var/www/${GHOST_DOMAIN_NAME}/htdocs;" >> /etc/nginx/sites-available/${GHOST_DOMAIN_NAME}
  449. echo " server_name ${GHOST_DOMAIN_NAME};" >> /etc/nginx/sites-available/${GHOST_DOMAIN_NAME}
  450. echo ' access_log /dev/null;' >> /etc/nginx/sites-available/${GHOST_DOMAIN_NAME}
  451. echo " error_log /dev/null;" >> /etc/nginx/sites-available/${GHOST_DOMAIN_NAME}
  452. echo '' >> /etc/nginx/sites-available/${GHOST_DOMAIN_NAME}
  453. function_check nginx_ssl
  454. nginx_ssl ${GHOST_DOMAIN_NAME}
  455. function_check nginx_disable_sniffing
  456. nginx_disable_sniffing ${GHOST_DOMAIN_NAME}
  457. echo ' add_header Strict-Transport-Security max-age=0;' >> /etc/nginx/sites-available/${GHOST_DOMAIN_NAME}
  458. echo '' >> /etc/nginx/sites-available/${GHOST_DOMAIN_NAME}
  459. echo ' location / {' >> /etc/nginx/sites-available/${GHOST_DOMAIN_NAME}
  460. function_check nginx_limits
  461. nginx_limits ${GHOST_DOMAIN_NAME} '10G'
  462. echo " proxy_pass http://localhost:${GHOST_PORT};" >> /etc/nginx/sites-available/${GHOST_DOMAIN_NAME}
  463. echo ' }' >> /etc/nginx/sites-available/${GHOST_DOMAIN_NAME}
  464. echo '' >> /etc/nginx/sites-available/${GHOST_DOMAIN_NAME}
  465. echo ' fastcgi_buffers 64 4K;' >> /etc/nginx/sites-available/${GHOST_DOMAIN_NAME}
  466. echo '' >> /etc/nginx/sites-available/${GHOST_DOMAIN_NAME}
  467. echo ' error_page 403 /core/templates/403.php;' >> /etc/nginx/sites-available/${GHOST_DOMAIN_NAME}
  468. echo ' error_page 404 /core/templates/404.php;' >> /etc/nginx/sites-available/${GHOST_DOMAIN_NAME}
  469. echo '' >> /etc/nginx/sites-available/${GHOST_DOMAIN_NAME}
  470. echo ' location = /robots.txt {' >> /etc/nginx/sites-available/${GHOST_DOMAIN_NAME}
  471. echo ' allow all;' >> /etc/nginx/sites-available/${GHOST_DOMAIN_NAME}
  472. echo ' log_not_found off;' >> /etc/nginx/sites-available/${GHOST_DOMAIN_NAME}
  473. echo ' access_log /dev/null;' >> /etc/nginx/sites-available/${GHOST_DOMAIN_NAME}
  474. echo ' }' >> /etc/nginx/sites-available/${GHOST_DOMAIN_NAME}
  475. echo '' >> /etc/nginx/sites-available/${GHOST_DOMAIN_NAME}
  476. nginx_keybase $GHOST_DOMAIN_NAME
  477. echo '}' >> /etc/nginx/sites-available/${GHOST_DOMAIN_NAME}
  478. echo '' >> /etc/nginx/sites-available/${GHOST_DOMAIN_NAME}
  479. else
  480. echo -n '' > /etc/nginx/sites-available/${GHOST_DOMAIN_NAME}
  481. fi
  482. echo 'server {' >> /etc/nginx/sites-available/${GHOST_DOMAIN_NAME}
  483. echo " listen 127.0.0.1:${GHOST_ONION_PORT} default_server;" >> /etc/nginx/sites-available/${GHOST_DOMAIN_NAME}
  484. echo " root /var/www/$GHOST_DOMAIN_NAME/htdocs;" >> /etc/nginx/sites-available/${GHOST_DOMAIN_NAME}
  485. echo " server_name $GHOST_ONION_HOSTNAME;" >> /etc/nginx/sites-available/${GHOST_DOMAIN_NAME}
  486. echo ' access_log /dev/null;' >> /etc/nginx/sites-available/${GHOST_DOMAIN_NAME}
  487. echo " error_log /dev/null;" >> /etc/nginx/sites-available/${GHOST_DOMAIN_NAME}
  488. echo '' >> /etc/nginx/sites-available/${GHOST_DOMAIN_NAME}
  489. function_check nginx_disable_sniffing
  490. nginx_disable_sniffing ${GHOST_DOMAIN_NAME}
  491. echo ' add_header Strict-Transport-Security max-age=0;' >> /etc/nginx/sites-available/${GHOST_DOMAIN_NAME}
  492. echo '' >> /etc/nginx/sites-available/${GHOST_DOMAIN_NAME}
  493. echo ' location / {' >> /etc/nginx/sites-available/${GHOST_DOMAIN_NAME}
  494. function_check nginx_limits
  495. nginx_limits ${GHOST_DOMAIN_NAME} '10G'
  496. echo " proxy_pass http://localhost:${GHOST_PORT};" >> /etc/nginx/sites-available/${GHOST_DOMAIN_NAME}
  497. echo ' }' >> /etc/nginx/sites-available/${GHOST_DOMAIN_NAME}
  498. echo '' >> /etc/nginx/sites-available/${GHOST_DOMAIN_NAME}
  499. echo ' fastcgi_buffers 64 4K;' >> /etc/nginx/sites-available/${GHOST_DOMAIN_NAME}
  500. echo '' >> /etc/nginx/sites-available/${GHOST_DOMAIN_NAME}
  501. echo ' error_page 403 /core/templates/403.php;' >> /etc/nginx/sites-available/${GHOST_DOMAIN_NAME}
  502. echo ' error_page 404 /core/templates/404.php;' >> /etc/nginx/sites-available/${GHOST_DOMAIN_NAME}
  503. echo '' >> /etc/nginx/sites-available/${GHOST_DOMAIN_NAME}
  504. echo ' location = /robots.txt {' >> /etc/nginx/sites-available/${GHOST_DOMAIN_NAME}
  505. echo ' allow all;' >> /etc/nginx/sites-available/${GHOST_DOMAIN_NAME}
  506. echo ' log_not_found off;' >> /etc/nginx/sites-available/${GHOST_DOMAIN_NAME}
  507. echo ' access_log /dev/null;' >> /etc/nginx/sites-available/${GHOST_DOMAIN_NAME}
  508. echo ' }' >> /etc/nginx/sites-available/${GHOST_DOMAIN_NAME}
  509. echo '' >> /etc/nginx/sites-available/${GHOST_DOMAIN_NAME}
  510. nginx_keybase ${GHOST_DOMAIN_NAME}
  511. echo '}' >> /etc/nginx/sites-available/${GHOST_DOMAIN_NAME}
  512. function_check create_site_certificate
  513. create_site_certificate $GHOST_DOMAIN_NAME 'yes'
  514. function_check configure_php
  515. configure_php
  516. if [[ $ONION_ONLY != 'no' ]]; then
  517. sed -i "s|url: .*|url: 'http://${GHOST_ONION_HOSTNAME}',|g" /var/www/${GHOST_DOMAIN_NAME}/htdocs/config.js
  518. systemctl restart mariadb
  519. systemctl restart ghost
  520. fi
  521. ghost_replace_services
  522. function_check nginx_ensite
  523. nginx_ensite $GHOST_DOMAIN_NAME
  524. systemctl restart nginx
  525. systemctl restart mariadb
  526. ${PROJECT_NAME}-pass -u $MY_USERNAME -a ghost -p "$GHOST_ADMIN_PASSWORD"
  527. function_check add_ddns_domain
  528. add_ddns_domain $GHOST_DOMAIN_NAME
  529. chown -R ghost: /var/www/${GHOST_DOMAIN_NAME}/htdocs
  530. set_completion_param "ghost domain" "$GHOST_DOMAIN_NAME"
  531. if ! grep -q "ghost version:" ${COMPLETION_FILE}; then
  532. echo "ghost version:${GHOST_VERSION}" >> ${COMPLETION_FILE}
  533. else
  534. sed -i "s|ghost version.*|ghost version:${GHOST_VERSION}|g" ${COMPLETION_FILE}
  535. fi
  536. APP_INSTALLED=1
  537. }
  538. # NOTE: deliberately no exit 0