freedombone-app-ghost 24KB

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