freedombone-app-ghost 21KB

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