freedombone-app-ghost 21KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568
  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_VERSION=1.19.0
  35. GHOST_DOMAIN_NAME=
  36. GHOST_CODE=
  37. GHOST_ONION_PORT=8104
  38. GHOST_PORT=2368
  39. ghost_variables=(GHOST_DOMAIN_NAME
  40. GHOST_CODE
  41. GHOST_ADMIN_PASSWORD
  42. ONION_ONLY
  43. DDNS_PROVIDER
  44. MY_USERNAME)
  45. function ghost_bust {
  46. # kill the started ghost process
  47. kill_pid=$(ps aux | grep "ghost run" | awk -F ' ' '{print $2}' | head -n 1)
  48. kill -9 $kill_pid
  49. kill_pid=$(ps aux | grep "ghost" | awk -F ' ' '{print $2}' | head -n 1)
  50. kill -9 $kill_pid
  51. kill_pid=$(ps aux | grep "ghost" | awk -F ' ' '{print $2}' | head -n 1)
  52. kill -9 $kill_pid
  53. }
  54. function logging_on_ghost {
  55. echo -n ''
  56. }
  57. function logging_off_ghost {
  58. echo -n ''
  59. }
  60. function ghost_replace_jquery {
  61. curr_domain="https://$GHOST_DOMAIN_NAME"
  62. if [[ "$ONION_ONLY" != 'no' ]]; then
  63. curr_domain="http://$GHOST_ONION_HOSTNAME"
  64. fi
  65. sed -i "s|src=\"https://code.jquery.com/jquery-.*|src=\"$curr_domain/jquery-${jquery_version}.js\"|g" current/content/themes/casper/default.hbs
  66. sed -i "s|src=\"https://code.jquery.com/jquery-.*|src=\"$curr_domain/jquery-${jquery_version}.js\"></script>|g" current/node_modules/gscan/app/tpl/layouts/default.hbs
  67. sed -i "s|http://code.jquery.com/jquery.js|$curr_domain/jquery-${jquery_version}.js|g" current/node_modules/jsdom/README.md
  68. sed -i "s|https://code.jquery.com/jquery.js|$curr_domain/jquery-${jquery_version}.js|g" current/node_modules/jsdom/README.md
  69. cd /var/www/${GHOST_DOMAIN_NAME}/htdocs/current
  70. find ./ -type f -exec sed -i -e 's|https://code.jquery.com|$curr_domain|g' {} \;
  71. find ./ -type f -exec sed -i -e 's|http://code.jquery.com|$curr_domain|g' {} \;
  72. }
  73. function ghost_rss_button {
  74. # remove feedly -aaargh!
  75. sed -i 's|http://cloud.feedly.com/#subscription/feed/{{@blog.url}}/rss/|{{@blog.url}}/rss/|g' /var/www/$GHOST_DOMAIN_NAME/htdocs/current/content/themes/casper/partials/site-nav.hbs
  76. sed -i 's|http://cloud.feedly.com/#subscription/feed/{{url absolute="true"}}/rss/|{{url absolute="true"}}rss/|g' /var/www/$GHOST_DOMAIN_NAME/htdocs/current/content/themes/casper/author.hbs
  77. }
  78. function ghost_remove_offsite_links {
  79. curr_domain="$GHOST_DOMAIN_NAME"
  80. if [[ "$ONION_ONLY" != 'no' ]]; then
  81. curr_domain="$GHOST_ONION_HOSTNAME"
  82. fi
  83. ghost_rss_button
  84. # remove google font links
  85. cd /var/www/$GHOST_DOMAIN_NAME/htdocs/current
  86. find ./ -type f -exec sed -i -e 's/fonts.googleapis.com/$curr_domain/g' {} \;
  87. # copy jquery locally
  88. previous_jquery_version='1.12.0'
  89. jquery_version='1.12.4'
  90. if [ ! -f /var/www/$GHOST_DOMAIN_NAME/htdocs/jquery-${jquery_version}.js ]; then
  91. cd /var/www/$GHOST_DOMAIN_NAME/htdocs
  92. wget https://code.jquery.com/jquery-${jquery_version}.js
  93. jquery_hash=$(sha256sum jquery-${jquery_version}.js | awk -F ' ' '{print $1}')
  94. if [[ "$jquery_hash" != '430f36f9b5f21aae8cc9dca6a81c4d3d84da5175eaedcf2fdc2c226302cb3575' ]]; then
  95. echo $'Unexpected jquery hash value'
  96. exit 258442
  97. fi
  98. fi
  99. ghost_replace_jquery
  100. previous_jquery_version='1.11.3'
  101. ghost_replace_jquery
  102. }
  103. function ghost_replace_proprietary_services {
  104. replace_file=$1
  105. sed -i 's|Twitter Profile|GNU Social Profile|g' $replace_file
  106. sed -i 's|Twitter profile|GNU Social Profile|g' $replace_file
  107. sed -i 's|Twitter Username|GNU Social Username|g' $replace_file
  108. sed -i 's|twitter.com|quitter.se|g' $replace_file
  109. sed -i 's|Facebook Page|Hubzilla Channel|g' $replace_file
  110. sed -i 's|Facebook Profile|Hubzilla Channel|g' $replace_file
  111. sed -i 's|Facebook profile|Hubzilla Channel|g' $replace_file
  112. sed -i 's|www.facebook.com/username|hubzilladomain/username|g' $replace_file
  113. sed -i 's|www.facebook.com/ghost|hubzilladomain/username|g' $replace_file
  114. sed -i 's|www.facebook.com/testuser|hubzilladomain/username|g' $replace_file
  115. sed -i 's|www.facebook.com/testing|hubzilladomain/username|g' $replace_file
  116. sed -i 's|www.facebook.com/test|hubzilladomain/username|g' $replace_file
  117. sed -i 's|www.facebook.com/yourUsername|hubzilladomain/username|g' $replace_file
  118. sed -i 's|www.facebook.com/yourPage|hubzilladomain/username|g' $replace_file
  119. sed -i 's|Facebook Username|Hubzilla Channel|g' $replace_file
  120. sed -i 's|www.facebook.com|hubzilladomain|g' $replace_file
  121. sed -i 's|facebook value|hubzilla value|g' $replace_file
  122. sed -i '/<section class="share">/,/<\/section>/d' $replace_file
  123. }
  124. function ghost_replace_services {
  125. ghost_replace_proprietary_services /var/www/${GHOST_DOMAIN_NAME}/htdocs/content/themes/casper/post.hbs
  126. }
  127. function remove_user_ghost {
  128. remove_username="$1"
  129. }
  130. function add_user_ghost {
  131. if [[ $(app_is_installed ghost) == "0" ]]; then
  132. echo '0'
  133. return
  134. fi
  135. new_username="$1"
  136. new_user_password="$2"
  137. echo '0'
  138. }
  139. function install_interactive_ghost {
  140. if [ ! $ONION_ONLY ]; then
  141. ONION_ONLY='no'
  142. fi
  143. if [[ $ONION_ONLY != "no" ]]; then
  144. GHOST_DOMAIN_NAME='ghost.local'
  145. write_config_param "GHOST_DOMAIN_NAME" "$GHOST_DOMAIN_NAME"
  146. else
  147. function_check interactive_site_details
  148. interactive_site_details "ghost" "GHOST_DOMAIN_NAME" "GHOST_CODE"
  149. fi
  150. APP_INSTALLED=1
  151. }
  152. function change_password_ghost {
  153. GHOST_USERNAME="$1"
  154. GHOST_PASSWORD="$2"
  155. if [ ${#GHOST_PASSWORD} -lt 8 ]; then
  156. echo $'Ghost password is too short'
  157. return
  158. fi
  159. #${PROJECT_NAME}-pass -u $GHOST_USERNAME -a ghost -p "$GHOST_PASSWORD"
  160. }
  161. function reconfigure_ghost {
  162. echo -n ''
  163. }
  164. function upgrade_ghost {
  165. CURR_GHOST_VERSION=$(get_completion_param "ghost version")
  166. if [[ "${CURR_GHOST_VERSION}" == "${GHOST_VERSION}" ]]; then
  167. return
  168. fi
  169. read_config_param GHOST_DOMAIN_NAME
  170. if [ ! -d /var/www/$GHOST_DOMAIN_NAME/htdocs ]; then
  171. return
  172. fi
  173. systemctl stop ghost
  174. ghost_bust
  175. cd /var/www/$GHOST_DOMAIN_NAME/htdocs
  176. npm i -g ghost-cli
  177. /usr/local/bin/ghost update &
  178. sleep 200
  179. ghost_bust
  180. ghost_replace_services
  181. ghost_remove_offsite_links
  182. chown root:root /usr/local/bin/ghost
  183. chown -R root:root /usr/local/lib
  184. chown -R ghost: /var/www/${GHOST_DOMAIN_NAME}/htdocs
  185. systemctl restart ghost
  186. sed -i "s|ghost version.*|ghost version:${GHOST_VERSION}|g" ${COMPLETION_FILE}
  187. }
  188. function backup_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. ghost_path=/var/www/${GHOST_DOMAIN_NAME}/htdocs/content
  194. if [ -d $ghost_path ]; then
  195. suspend_site ${GHOST_DOMAIN_NAME}
  196. systemctl stop ghost
  197. backup_directory_to_usb $ghost_path ghostcontent
  198. systemctl start ghost
  199. restart_site
  200. fi
  201. }
  202. function restore_local_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. if [ $GHOST_DOMAIN_NAME ]; then
  208. suspend_site ${GHOST_DOMAIN_NAME}
  209. systemctl stop ghost
  210. temp_restore_dir=/root/tempghostcontent
  211. function_check restore_directory_from_usb
  212. restore_directory_from_usb $temp_restore_dir ghostcontent
  213. if [ -d $temp_restore_dir ]; then
  214. if [ -d $temp_restore_dir/var/www/$GHOST_DOMAIN_NAME/htdocs/content ]; then
  215. cp -r $temp_restore_dir/var/www/$GHOST_DOMAIN_NAME/htdocs/content/* /var/www/$GHOST_DOMAIN_NAME/htdocs/content/
  216. else
  217. cp -r $temp_restore_dir/* /var/www/$GHOST_DOMAIN_NAME/htdocs/content/
  218. fi
  219. chown -R ghost:ghost /var/www/$GHOST_DOMAIN_NAME/htdocs/content
  220. rm -rf $temp_restore_dir
  221. fi
  222. systemctl start ghost
  223. restart_site
  224. fi
  225. }
  226. function backup_remote_ghost {
  227. GHOST_DOMAIN_NAME='ghost.local'
  228. if grep -q "ghost domain" $COMPLETION_FILE; then
  229. GHOST_DOMAIN_NAME=$(get_completion_param "ghost domain")
  230. fi
  231. temp_backup_dir=/var/www/${GHOST_DOMAIN_NAME}/htdocs/content
  232. if [ -d $temp_backup_dir ]; then
  233. suspend_site ${GHOST_DOMAIN_NAME}
  234. backup_directory_to_friend $temp_backup_dir ghostcontent
  235. restart_site
  236. else
  237. echo $"Ghost domain specified but not found in /var/www/${GHOST_DOMAIN_NAME}"
  238. exit 2578
  239. fi
  240. }
  241. function restore_remote_ghost {
  242. GHOST_DOMAIN_NAME='ghost.local'
  243. if grep -q "ghost domain" $COMPLETION_FILE; then
  244. GHOST_DOMAIN_NAME=$(get_completion_param "ghost domain")
  245. fi
  246. suspend_site ${GHOST_DOMAIN_NAME}
  247. systemctl stop ghost
  248. temp_restore_dir=/root/tempghostcontent
  249. function_check restore_directory_from_friend
  250. restore_directory_from_friend $temp_restore_dir ghostcontent
  251. if [ -d $temp_restore_dir ]; then
  252. if [ -d $temp_restore_dir/var/www/$GHOST_DOMAIN_NAME/htdocs/content ]; then
  253. cp -r $temp_restore_dir/var/www/$GHOST_DOMAIN_NAME/htdocs/content/* /var/www/$GHOST_DOMAIN_NAME/htdocs/content/
  254. else
  255. cp -r $temp_restore_dir/* /var/www/$GHOST_DOMAIN_NAME/htdocs/content/
  256. fi
  257. chown -R ghost: /var/www/$GHOST_DOMAIN_NAME/htdocs
  258. rm -rf $temp_restore_dir
  259. fi
  260. systemctl start ghost
  261. restart_site
  262. }
  263. function remove_ghost {
  264. if [ ${#GHOST_DOMAIN_NAME} -eq 0 ]; then
  265. return
  266. fi
  267. systemctl stop ghost
  268. systemctl disable ghost
  269. rm /etc/systemd/system/ghost.service
  270. systemctl daemon-reload
  271. function_check remove_nodejs
  272. remove_nodejs ghost
  273. read_config_param "GHOST_DOMAIN_NAME"
  274. nginx_dissite $GHOST_DOMAIN_NAME
  275. remove_certs ${GHOST_DOMAIN_NAME}
  276. if [ -f /etc/nginx/sites-available/$GHOST_DOMAIN_NAME ]; then
  277. rm -f /etc/nginx/sites-available/$GHOST_DOMAIN_NAME
  278. fi
  279. if [ -d /var/www/$GHOST_DOMAIN_NAME ]; then
  280. rm -rf /var/www/$GHOST_DOMAIN_NAME
  281. fi
  282. remove_config_param GHOST_DOMAIN_NAME
  283. remove_config_param GHOST_CODE
  284. function_check remove_onion_service
  285. remove_onion_service ghost ${GHOST_ONION_PORT}
  286. remove_completion_param "install_ghost"
  287. sed -i '/Ghost/d' $COMPLETION_FILE
  288. sed -i '/ghost/d' $COMPLETION_FILE
  289. groupdel -f ghost
  290. userdel -r ghost
  291. function_check remove_ddns_domain
  292. remove_ddns_domain $GHOST_DOMAIN_NAME
  293. }
  294. function install_ghost {
  295. if [ ! $ONION_ONLY ]; then
  296. ONION_ONLY='no'
  297. fi
  298. if [ ! $GHOST_DOMAIN_NAME ]; then
  299. echo $'The ghost domain name was not specified'
  300. exit 5062
  301. fi
  302. # for the avatar changing command
  303. apt-get -yq install unzip wget
  304. if [ ! -d /var/www/$GHOST_DOMAIN_NAME/htdocs ]; then
  305. mkdir -p /var/www/$GHOST_DOMAIN_NAME/htdocs
  306. fi
  307. cd /var/www/$GHOST_DOMAIN_NAME/htdocs
  308. function_check install_nodejs
  309. install_nodejs ghost
  310. # Some dependencies of ghost
  311. npm install -g jison@0.4.13 --save
  312. npm install moment-timezone@0.5.13
  313. npm install express@4.15.3
  314. npm install lodash@4.17.4
  315. npm install uuid@3.0.1
  316. npm install bluebird@3.5.0
  317. npm install chalk@1.1.3
  318. npm install intl-messageformat@1.3.0
  319. npm install validator@7.0.0
  320. npm install express-hbs@1.0.4
  321. npm install glob@7.1.2
  322. npm install unidecode@0.1.8
  323. npm install csv-parser@1.11.0
  324. npm install archiver@1.3.0
  325. npm install fs-extra@3.0.1
  326. npm install extract-zip-fork@1.5.1
  327. npm install moment@2.18.1
  328. npm install nodemailer@4.0.1
  329. npm install html-to-text@3.3.0
  330. npm install gscan@1.1.0
  331. npm install body-parser@1.17.2
  332. npm install compression@1.6.2
  333. npm install morgan@1.8.2
  334. npm install semver@5.3.0
  335. npm install path-match@1.2.4
  336. npm install downsize@0.0.8
  337. npm install rss@1.2.2
  338. npm install cheerio@1.0.0-rc.1
  339. npm install passport@0.3.2
  340. npm install xml@1.0.1
  341. npm install multer@1.3.0
  342. npm install oauth2orize@1.8.0
  343. npm install connect-slashes@1.3.1
  344. npm install cors@2.8.3
  345. npm install netjet@1.1.3
  346. npm install jsonpath@0.2.11
  347. npm install image-size@0.5.4
  348. npm install passport-oauth2-client-password@0.1.2
  349. npm install passport-http-bearer@1.0.1
  350. npm install amperize@0.3.4
  351. npm install bcryptjs@2.4.3
  352. npm install knex@0.12.9
  353. npm install bookshelf@0.10.2
  354. npm install cookie-session@1.2.0
  355. npm install ghost-gql@0.0.6
  356. npm install intl@1.2.5
  357. npm install sanitize-html@1.14.1
  358. npm install showdown-ghost@0.3.6
  359. npm install superagent@3.5.2
  360. npm install mysql@2.1.1
  361. npm install mariasql@0.2.6
  362. npm install debug@2.6.8
  363. npm install nconf@0.8.4
  364. npm install -g knex-migrator
  365. knex-migrator init
  366. # now install ghost itself
  367. npm install -g ghost-cli
  368. GHOST_ONION_HOSTNAME=$(add_onion_service ghost 80 ${GHOST_ONION_PORT})
  369. ghost install local --port ${GHOST_PORT}
  370. ghost_bust
  371. # NOTE: this has to be http, not https
  372. sed -i "s|\"url\":|\"url\": \"http://${GHOST_DOMAIN_NAME}/\",|g" /var/www/${GHOST_DOMAIN_NAME}/htdocs/config.development.json
  373. adduser --system --home=/var/www/${GHOST_DOMAIN_NAME}/htdocs/ --group ghost
  374. echo '[Unit]' > /etc/systemd/system/ghost.service
  375. echo 'Description=Ghost Blog' >> /etc/systemd/system/ghost.service
  376. echo 'After=syslog.target' >> /etc/systemd/system/ghost.service
  377. echo 'After=network.target' >> /etc/systemd/system/ghost.service
  378. echo '' >> /etc/systemd/system/ghost.service
  379. echo '[Service]' >> /etc/systemd/system/ghost.service
  380. echo 'Type=simple' >> /etc/systemd/system/ghost.service
  381. echo 'User=ghost' >> /etc/systemd/system/ghost.service
  382. echo 'Group=ghost' >> /etc/systemd/system/ghost.service
  383. echo "WorkingDirectory=/var/www/${GHOST_DOMAIN_NAME}/htdocs" >> /etc/systemd/system/ghost.service
  384. echo "ExecStart=/usr/local/bin/ghost run -D" >> /etc/systemd/system/ghost.service
  385. echo "ExecStop=/usr/local/bin/ghost stop" >> /etc/systemd/system/ghost.service
  386. echo "ExecRestart=/usr/local/bin/ghost restart" >> /etc/systemd/system/ghost.service
  387. echo 'Restart=always' >> /etc/systemd/system/ghost.service
  388. echo 'RestartSec=60' >> /etc/systemd/system/ghost.service
  389. echo "Environment=NODE_ENV=development PORT=${GHOST_PORT}" >> /etc/systemd/system/ghost.service
  390. echo '' >> /etc/systemd/system/ghost.service
  391. echo '[Install]' >> /etc/systemd/system/ghost.service
  392. echo 'WantedBy=multi-user.target' >> /etc/systemd/system/ghost.service
  393. ghost_remove_offsite_links
  394. chown -R ghost: /var/www/${GHOST_DOMAIN_NAME}/htdocs
  395. systemctl enable ghost
  396. systemctl daemon-reload
  397. systemctl start ghost
  398. if [[ ${ONION_ONLY} == "no" ]]; then
  399. function_check nginx_http_redirect
  400. nginx_http_redirect ${GHOST_DOMAIN_NAME}
  401. echo 'server {' >> /etc/nginx/sites-available/${GHOST_DOMAIN_NAME}
  402. echo ' listen 443 ssl;' >> /etc/nginx/sites-available/${GHOST_DOMAIN_NAME}
  403. echo ' listen [::]:443 ssl;' >> /etc/nginx/sites-available/${GHOST_DOMAIN_NAME}
  404. echo " root /var/www/${GHOST_DOMAIN_NAME}/htdocs;" >> /etc/nginx/sites-available/${GHOST_DOMAIN_NAME}
  405. echo " server_name ${GHOST_DOMAIN_NAME};" >> /etc/nginx/sites-available/${GHOST_DOMAIN_NAME}
  406. echo ' access_log /dev/null;' >> /etc/nginx/sites-available/${GHOST_DOMAIN_NAME}
  407. echo " error_log /dev/null;" >> /etc/nginx/sites-available/${GHOST_DOMAIN_NAME}
  408. echo '' >> /etc/nginx/sites-available/${GHOST_DOMAIN_NAME}
  409. function_check nginx_ssl
  410. nginx_ssl ${GHOST_DOMAIN_NAME}
  411. function_check nginx_disable_sniffing
  412. nginx_disable_sniffing ${GHOST_DOMAIN_NAME}
  413. echo ' add_header Strict-Transport-Security max-age=0;' >> /etc/nginx/sites-available/${GHOST_DOMAIN_NAME}
  414. echo '' >> /etc/nginx/sites-available/${GHOST_DOMAIN_NAME}
  415. echo ' location / {' >> /etc/nginx/sites-available/${GHOST_DOMAIN_NAME}
  416. function_check nginx_limits
  417. nginx_limits ${GHOST_DOMAIN_NAME} '10G'
  418. echo " proxy_pass http://localhost:${GHOST_PORT};" >> /etc/nginx/sites-available/${GHOST_DOMAIN_NAME}
  419. echo ' }' >> /etc/nginx/sites-available/${GHOST_DOMAIN_NAME}
  420. echo '' >> /etc/nginx/sites-available/${GHOST_DOMAIN_NAME}
  421. echo ' fastcgi_buffers 64 4K;' >> /etc/nginx/sites-available/${GHOST_DOMAIN_NAME}
  422. echo '' >> /etc/nginx/sites-available/${GHOST_DOMAIN_NAME}
  423. echo ' error_page 403 /core/templates/403.php;' >> /etc/nginx/sites-available/${GHOST_DOMAIN_NAME}
  424. echo ' error_page 404 /core/templates/404.php;' >> /etc/nginx/sites-available/${GHOST_DOMAIN_NAME}
  425. echo '' >> /etc/nginx/sites-available/${GHOST_DOMAIN_NAME}
  426. echo ' location = /robots.txt {' >> /etc/nginx/sites-available/${GHOST_DOMAIN_NAME}
  427. echo ' allow all;' >> /etc/nginx/sites-available/${GHOST_DOMAIN_NAME}
  428. echo ' log_not_found off;' >> /etc/nginx/sites-available/${GHOST_DOMAIN_NAME}
  429. echo ' access_log /dev/null;' >> /etc/nginx/sites-available/${GHOST_DOMAIN_NAME}
  430. echo ' }' >> /etc/nginx/sites-available/${GHOST_DOMAIN_NAME}
  431. echo '' >> /etc/nginx/sites-available/${GHOST_DOMAIN_NAME}
  432. nginx_keybase $GHOST_DOMAIN_NAME
  433. echo '}' >> /etc/nginx/sites-available/${GHOST_DOMAIN_NAME}
  434. echo '' >> /etc/nginx/sites-available/${GHOST_DOMAIN_NAME}
  435. else
  436. echo -n '' > /etc/nginx/sites-available/${GHOST_DOMAIN_NAME}
  437. fi
  438. echo 'server {' >> /etc/nginx/sites-available/${GHOST_DOMAIN_NAME}
  439. echo " listen 127.0.0.1:${GHOST_ONION_PORT} default_server;" >> /etc/nginx/sites-available/${GHOST_DOMAIN_NAME}
  440. echo " root /var/www/$GHOST_DOMAIN_NAME/htdocs;" >> /etc/nginx/sites-available/${GHOST_DOMAIN_NAME}
  441. echo " server_name $GHOST_ONION_HOSTNAME;" >> /etc/nginx/sites-available/${GHOST_DOMAIN_NAME}
  442. echo ' access_log /dev/null;' >> /etc/nginx/sites-available/${GHOST_DOMAIN_NAME}
  443. echo " error_log /dev/null;" >> /etc/nginx/sites-available/${GHOST_DOMAIN_NAME}
  444. echo '' >> /etc/nginx/sites-available/${GHOST_DOMAIN_NAME}
  445. function_check nginx_disable_sniffing
  446. nginx_disable_sniffing ${GHOST_DOMAIN_NAME}
  447. echo ' add_header Strict-Transport-Security max-age=0;' >> /etc/nginx/sites-available/${GHOST_DOMAIN_NAME}
  448. echo '' >> /etc/nginx/sites-available/${GHOST_DOMAIN_NAME}
  449. echo ' location / {' >> /etc/nginx/sites-available/${GHOST_DOMAIN_NAME}
  450. function_check nginx_limits
  451. nginx_limits ${GHOST_DOMAIN_NAME} '10G'
  452. echo " proxy_pass http://localhost:${GHOST_PORT};" >> /etc/nginx/sites-available/${GHOST_DOMAIN_NAME}
  453. echo ' }' >> /etc/nginx/sites-available/${GHOST_DOMAIN_NAME}
  454. echo '' >> /etc/nginx/sites-available/${GHOST_DOMAIN_NAME}
  455. echo ' fastcgi_buffers 64 4K;' >> /etc/nginx/sites-available/${GHOST_DOMAIN_NAME}
  456. echo '' >> /etc/nginx/sites-available/${GHOST_DOMAIN_NAME}
  457. echo ' error_page 403 /core/templates/403.php;' >> /etc/nginx/sites-available/${GHOST_DOMAIN_NAME}
  458. echo ' error_page 404 /core/templates/404.php;' >> /etc/nginx/sites-available/${GHOST_DOMAIN_NAME}
  459. echo '' >> /etc/nginx/sites-available/${GHOST_DOMAIN_NAME}
  460. echo ' location = /robots.txt {' >> /etc/nginx/sites-available/${GHOST_DOMAIN_NAME}
  461. echo ' allow all;' >> /etc/nginx/sites-available/${GHOST_DOMAIN_NAME}
  462. echo ' log_not_found off;' >> /etc/nginx/sites-available/${GHOST_DOMAIN_NAME}
  463. echo ' access_log /dev/null;' >> /etc/nginx/sites-available/${GHOST_DOMAIN_NAME}
  464. echo ' }' >> /etc/nginx/sites-available/${GHOST_DOMAIN_NAME}
  465. echo '' >> /etc/nginx/sites-available/${GHOST_DOMAIN_NAME}
  466. nginx_keybase ${GHOST_DOMAIN_NAME}
  467. echo '}' >> /etc/nginx/sites-available/${GHOST_DOMAIN_NAME}
  468. function_check create_site_certificate
  469. create_site_certificate $GHOST_DOMAIN_NAME 'yes'
  470. ghost_replace_services
  471. function_check nginx_ensite
  472. nginx_ensite $GHOST_DOMAIN_NAME
  473. systemctl restart nginx
  474. ${PROJECT_NAME}-pass -u $MY_USERNAME -a ghost -p "$GHOST_ADMIN_PASSWORD"
  475. function_check add_ddns_domain
  476. add_ddns_domain $GHOST_DOMAIN_NAME
  477. chown root:root /usr/local/bin/ghost
  478. chown -R root:root /usr/local/lib
  479. chown -R ghost: /var/www/${GHOST_DOMAIN_NAME}/htdocs
  480. set_completion_param "ghost domain" "$GHOST_DOMAIN_NAME"
  481. if ! grep -q "ghost version:" ${COMPLETION_FILE}; then
  482. echo "ghost version:${GHOST_VERSION}" >> ${COMPLETION_FILE}
  483. else
  484. sed -i "s|ghost version.*|ghost version:${GHOST_VERSION}|g" ${COMPLETION_FILE}
  485. fi
  486. APP_INSTALLED=1
  487. }
  488. # NOTE: deliberately no exit 0