freedombone-app-pelican 30KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860
  1. #!/bin/bash
  2. # _____ _ _
  3. # | __|___ ___ ___ _| |___ _____| |_ ___ ___ ___
  4. # | __| _| -_| -_| . | . | | . | . | | -_|
  5. # |__| |_| |___|___|___|___|_|_|_|___|___|_|_|___|
  6. #
  7. # Freedom in the Cloud
  8. #
  9. # Pelican static blog
  10. #
  11. # License
  12. # =======
  13. #
  14. # Copyright (C) 2014-2018 Bob Mottram <bob@freedombone.net>
  15. #
  16. # This program is free software: you can redistribute it and/or modify
  17. # it under the terms of the GNU Affero General Public License as published by
  18. # the Free Software Foundation, either version 3 of the License, or
  19. # (at your option) any later version.
  20. #
  21. # This program is distributed in the hope that it will be useful,
  22. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  23. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  24. # GNU Affero General Public License for more details.
  25. #
  26. # You should have received a copy of the GNU Affero General Public License
  27. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  28. VARIANTS="full full-vim writer"
  29. IN_DEFAULT_INSTALL=0
  30. SHOW_ON_ABOUT=1
  31. PELICAN_DOMAIN_NAME=
  32. PELICAN_BLOG_CODE=
  33. PELICAN_ONION_PORT=8113
  34. PELICAN_THEMES_REPO="https://github.com/getpelican/pelican-themes"
  35. PELICAN_PLUGINS_REPO="https://github.com/getpelican/pelican-plugins"
  36. DEFAULT_BLOG_TITLE=$"Freedombone Blog"
  37. PELICAN_BLOG_INSTALL_DIR=/etc/blog
  38. PELICAN_CURRENT_BLOG_INDEX=$PELICAN_BLOG_INSTALL_DIR/.blog-index
  39. pelican_variables=(MY_USERNAME
  40. ONION_ONLY
  41. PELICAN_DOMAIN_NAME
  42. PELICAN_BLOG_CODE)
  43. function pelican_remove_bad_blog_links {
  44. find ./ -type f -name "*.css" -exec sed -i -e '/googleapi/d' {} \;
  45. find ./ -type f -name "*.scss" -exec sed -i -e '/googleapi/d' {} \;
  46. find ./ -type f -name "*.html" -exec sed -i -e '/googleapi/d' {} \;
  47. find ./ -type f -name "*.css" -exec sed -i -e '/bootstrapcdn/d' {} \;
  48. find ./ -type f -name "*.scss" -exec sed -i -e '/bootstrapcdn/d' {} \;
  49. find ./ -type f -name "*.html" -exec sed -i -e '/bootstrapcdn/d' {} \;
  50. }
  51. function logging_on_pelican {
  52. echo -n ''
  53. }
  54. function logging_off_pelican {
  55. echo -n ''
  56. }
  57. function install_pelican_website {
  58. if [[ $ONION_ONLY != 'no' ]]; then
  59. echo -n '' > /etc/nginx/sites-available/$PELICAN_DOMAIN_NAME
  60. return
  61. fi
  62. function_check nginx_http_redirect
  63. nginx_http_redirect $PELICAN_DOMAIN_NAME
  64. { echo 'server {';
  65. echo ' listen 443 ssl;';
  66. echo ' #listen [::]:443 ssl;';
  67. echo " root /var/www/${PELICAN_DOMAIN_NAME}/htdocs;";
  68. echo " server_name ${PELICAN_DOMAIN_NAME};";
  69. echo ' access_log /dev/null;';
  70. echo " error_log /dev/null;";
  71. echo ' index index.html;';
  72. echo ' charset utf-8;'; } >> "/etc/nginx/sites-available/$PELICAN_DOMAIN_NAME"
  73. function_check nginx_ssl
  74. nginx_ssl "$PELICAN_DOMAIN_NAME"
  75. function_check nginx_security_options
  76. nginx_security_options "$PELICAN_DOMAIN_NAME"
  77. { echo ' add_header Strict-Transport-Security "max-age=0;";';
  78. echo '';
  79. echo ' location / {'; } >> "/etc/nginx/sites-available/$PELICAN_DOMAIN_NAME"
  80. function_check nginx_limits
  81. nginx_limits "$PELICAN_DOMAIN_NAME"
  82. { echo ' }';
  83. echo '';
  84. echo ' # block these file types';
  85. echo ' location ~* \.(tpl|md|tgz|log|out)$ {';
  86. echo ' deny all;';
  87. echo ' }';
  88. echo '';
  89. echo ' # deny access to all dot files';
  90. echo ' location ~ /\. {';
  91. echo ' deny all;';
  92. echo ' }';
  93. echo '';
  94. echo ' location ~ /(data|conf|bin|inc)/ {';
  95. echo ' deny all;';
  96. echo ' }';
  97. echo ' location ~ /\.ht {';
  98. echo ' deny all;';
  99. echo ' }';
  100. echo '}';
  101. echo ''; } >> "/etc/nginx/sites-available/$PELICAN_DOMAIN_NAME"
  102. function_check create_site_certificate
  103. create_site_certificate "$PELICAN_DOMAIN_NAME" 'yes'
  104. }
  105. function install_pelican_website_onion {
  106. { echo 'server {';
  107. echo " listen 127.0.0.1:${PELICAN_ONION_PORT} default_server;";
  108. echo " root /var/www/${PELICAN_DOMAIN_NAME}/htdocs;";
  109. echo " server_name ${PELICAN_DOMAIN_NAME};";
  110. echo ' access_log /dev/null;';
  111. echo " error_log /dev/null;";
  112. echo ' index index.html;';
  113. echo ' charset utf-8;'; } >> "/etc/nginx/sites-available/$PELICAN_DOMAIN_NAME"
  114. function_check nginx_security_options
  115. nginx_security_options "$PELICAN_DOMAIN_NAME"
  116. { echo ' add_header Strict-Transport-Security "max-age=0;";';
  117. echo '';
  118. echo ' location / {'; } >> "/etc/nginx/sites-available/$PELICAN_DOMAIN_NAME"
  119. function_check nginx_limits
  120. nginx_limits "$PELICAN_DOMAIN_NAME"
  121. { echo ' }';
  122. echo '';
  123. echo ' # block these file types';
  124. echo ' location ~* \.(tpl|md|tgz|log|out)$ {';
  125. echo ' deny all;';
  126. echo ' }';
  127. echo '';
  128. echo ' # deny access to all dot files';
  129. echo ' location ~ /\. {';
  130. echo ' deny all;';
  131. echo ' }';
  132. echo '';
  133. echo ' location ~ /(data|conf|bin|inc)/ {';
  134. echo ' deny all;';
  135. echo ' }';
  136. echo ' location ~ /\.ht {';
  137. echo ' deny all;';
  138. echo ' }';
  139. echo '}'; } >> "/etc/nginx/sites-available/$PELICAN_DOMAIN_NAME"
  140. }
  141. function pelican_editor_config {
  142. if [ ! -f $PELICAN_BLOG_INSTALL_DIR/.emacs-pelican ]; then
  143. { echo "(add-hook 'before-save-hook 'delete-trailing-whitespace)";
  144. echo '(setq org-support-shift-select t)';
  145. echo '(setq standard-indent 4)';
  146. echo '(setq-default tab-width 4)';
  147. echo '(setq c-basic-offset 4)';
  148. echo '(mouse-wheel-mode t)';
  149. echo '(setq make-backup-files t)';
  150. echo '(setq version-control t)';
  151. echo '(setq backup-directory-alist (quote ((".*" . "~/.emacs_backups/"))))';
  152. echo "(setq default-major-mode 'text-mode)";
  153. echo "(dolist (hook '(text-mode-hook))";
  154. echo ' (add-hook hook (lambda () (flyspell-mode 1))))';
  155. echo '(setq-default fill-column 72)';
  156. echo '(setq auto-fill-mode 0)';
  157. echo "(add-hook 'text-mode-hook 'turn-on-auto-fill)";
  158. echo "(setq-default auto-fill-function 'do-auto-fill)"; } > "$PELICAN_BLOG_INSTALL_DIR/.emacs-pelican"
  159. fi
  160. }
  161. function pelican_regenerate_blog {
  162. clear
  163. echo ''
  164. echo $'Regenerating blog...'
  165. cd "$PELICAN_BLOG_INSTALL_DIR" || exit 463856348
  166. make html
  167. cp -r $PELICAN_BLOG_INSTALL_DIR/output/* /var/www/$PELICAN_DOMAIN_NAME/htdocs/
  168. chown -R www-data:www-data /var/www/$PELICAN_DOMAIN_NAME/htdocs
  169. }
  170. function pelican_new_blog {
  171. DATESTR=$(date "+%Y-%m-%d %H:%M:%S")
  172. if [ ! -f $PELICAN_BLOG_INSTALL_DIR/.new-blog-entry ]; then
  173. { echo $'Title: Blog Post Title';
  174. echo $"Date: ${DATESTR}";
  175. echo $"Author: $(toxid --showuser)";
  176. echo $'Category: default';
  177. echo $'Tags: blog, tag';
  178. echo '';
  179. echo $'Add your text here';
  180. echo '';
  181. echo -n $'To include an image copy it into the /etc/blog/content/images directory, ';
  182. echo $'then link to it with:';
  183. echo '';
  184. echo $'![My image]({filename}images/myimage.jpg)';
  185. echo ''; } > $PELICAN_BLOG_INSTALL_DIR/.new-blog-entry
  186. fi
  187. if [ -f /usr/bin/emacs ]; then
  188. emacs -q --load $PELICAN_BLOG_INSTALL_DIR/.emacs-pelican $PELICAN_BLOG_INSTALL_DIR/.new-blog-entry
  189. else
  190. editor $PELICAN_BLOG_INSTALL_DIR/.new-blog-entry
  191. fi
  192. if grep -q $"Add your text here" $PELICAN_BLOG_INSTALL_DIR/.new-blog-entry; then
  193. return
  194. fi
  195. if grep -q $"Blog Post Title" $PELICAN_BLOG_INSTALL_DIR/.new-blog-entry; then
  196. return
  197. fi
  198. if [ ! -f $PELICAN_CURRENT_BLOG_INDEX ]; then
  199. echo '0' > $PELICAN_CURRENT_BLOG_INDEX
  200. fi
  201. # move to the content directory
  202. CURRENT_INDEX=$(cat $PELICAN_CURRENT_BLOG_INDEX)
  203. # shellcheck disable=SC2086
  204. mv $PELICAN_BLOG_INSTALL_DIR/.new-blog-entry $BLOG_CONTENT_PATH/${CURRENT_INDEX}_post.md
  205. # increment the index
  206. CURRENT_INDEX=$((CURRENT_INDEX + 1))
  207. echo "$CURRENT_INDEX" > $PELICAN_CURRENT_BLOG_INDEX
  208. pelican_regenerate_blog
  209. }
  210. function pelican_edit_blog {
  211. if [ ! -f $PELICAN_CURRENT_BLOG_INDEX ]; then
  212. return
  213. fi
  214. CURRENT_INDEX=$(cat $PELICAN_CURRENT_BLOG_INDEX)
  215. PREVIOUS_INDEX=$((CURRENT_INDEX - 1))
  216. LAST_BLOG_ENTRY=$BLOG_CONTENT_PATH/${PREVIOUS_INDEX}_post.md
  217. if [ ! -f "$LAST_BLOG_ENTRY" ]; then
  218. return
  219. fi
  220. if [ -f /usr/bin/emacs ]; then
  221. emacs -q --load "$PELICAN_BLOG_INSTALL_DIR/.emacs-pelican" "$LAST_BLOG_ENTRY"
  222. else
  223. editor "$LAST_BLOG_ENTRY"
  224. fi
  225. pelican_regenerate_blog
  226. }
  227. function pelican_delete_blog {
  228. if [ ! -f $PELICAN_CURRENT_BLOG_INDEX ]; then
  229. return
  230. fi
  231. CURRENT_INDEX=$(cat $PELICAN_CURRENT_BLOG_INDEX)
  232. PREVIOUS_INDEX=$((CURRENT_INDEX - 1))
  233. LAST_BLOG_ENTRY=$BLOG_CONTENT_PATH/${PREVIOUS_INDEX}_post.md
  234. if [ ! -f "$LAST_BLOG_ENTRY" ]; then
  235. return
  236. fi
  237. dialog --title $"Delete the previous blog entry" \
  238. --backtitle $"Freedombone Mesh" \
  239. --defaultno \
  240. --yesno $"\\nAre you sure that you wish to delete the previous blog entry?" 8 60
  241. sel=$?
  242. case $sel in
  243. 0) rm "$LAST_BLOG_ENTRY"
  244. if [ "$CURRENT_INDEX" -gt 0 ]; then
  245. CURRENT_INDEX=$PREVIOUS_INDEX
  246. echo "$CURRENT_INDEX" > $PELICAN_CURRENT_BLOG_INDEX
  247. else
  248. rm -f $PELICAN_CURRENT_BLOG_INDEX
  249. fi
  250. pelican_regenerate_blog
  251. ;;
  252. esac
  253. }
  254. function pelican_change_theme {
  255. THEMES=()
  256. for d in $PELICAN_BLOG_INSTALL_DIR/themes/*/ ; do
  257. THEME_NAME=$(echo "$d" | awk -F '/' '{print $6}')
  258. THEMES+=("$THEME_NAME")
  259. done
  260. themelist=""
  261. n=1
  262. theme_index=0
  263. curr_theme_index=
  264. if [ -f $PELICAN_BLOG_INSTALL_DIR/.blog-theme-index ]; then
  265. curr_theme_index=$(cat $PELICAN_BLOG_INSTALL_DIR/.blog-theme-index)
  266. fi
  267. # shellcheck disable=SC2068
  268. for a in ${THEMES[@]}
  269. do
  270. is_selected='off'
  271. if [ "$curr_theme_index" ]; then
  272. if [ $n -eq "$curr_theme_index" ]; then
  273. is_selected='on'
  274. fi
  275. else
  276. if [[ "$a" == 'nice-blog' ]]; then
  277. is_selected='on'
  278. fi
  279. fi
  280. themelist="$themelist $n $a $is_selected"
  281. n=$((n+1))
  282. theme_index=$((theme_index+1))
  283. done
  284. data=$(mktemp 2>/dev/null)
  285. dialog --backtitle $"Freedombone Mesh" \
  286. --title $"Select Blog Theme" \
  287. --radiolist $'Choose:' \
  288. 80 40 20 "$themelist" 2> "$data"
  289. sel=$?
  290. case $sel in
  291. 1) rm -f "$data"
  292. return;;
  293. 255) rm -f "$data"
  294. return;;
  295. esac
  296. CHOSEN_THEME_INDEX=$(cat "$data")
  297. rm -f "$data"
  298. echo "$CHOSEN_THEME_INDEX" > $PELICAN_BLOG_INSTALL_DIR/.blog-theme-index
  299. CHOSEN_THEME_INDEX=$((CHOSEN_THEME_INDEX - 1))
  300. CHOSEN_THEME=${THEMES[$CHOSEN_THEME_INDEX]}
  301. cd "$PELICAN_BLOG_INSTALL_DIR/themes/$CHOSEN_THEME" || exit 2648268284
  302. pelican_remove_bad_blog_links
  303. if grep -q "THEME=" $PELICAN_BLOG_INSTALL_DIR/pelicanconf.py; then
  304. sed -i "s|THEME=.*|THEME='themes/${CHOSEN_THEME}'|g" $PELICAN_BLOG_INSTALL_DIR/pelicanconf.py
  305. else
  306. echo "THEME='themes/${CHOSEN_THEME}'" >> $PELICAN_BLOG_INSTALL_DIR/pelicanconf.py
  307. fi
  308. pelican_regenerate_blog
  309. }
  310. function configure_interactive_pelican {
  311. data=$(mktemp 2>/dev/null)
  312. dialog --backtitle $"Freedombone Configuration" \
  313. --title $"Pelican Blogging" \
  314. --radiolist $"Choose an operation:" 18 50 11 \
  315. 1 $"New blog entry" off \
  316. 2 $"Edit the previous blog entry" off \
  317. 3 $"Delete the previous blog entry" off \
  318. 4 $"Change theme" off \
  319. 5 $"Exit" off 2> "$data"
  320. sel=$?
  321. case $sel in
  322. 1) rm -f "$data"
  323. return;;
  324. 255) rm -f "$data"
  325. return;;
  326. esac
  327. case $(cat "$data") in
  328. 1) pelican_new_blog;;
  329. 2) pelican_edit_blog;;
  330. 3) pelican_delete_blog;;
  331. 4) pelican_change_theme;;
  332. esac
  333. rm -f "$data"
  334. }
  335. function install_interactive_pelican {
  336. if [ ! "$ONION_ONLY" ]; then
  337. ONION_ONLY='no'
  338. fi
  339. if [[ $ONION_ONLY != "no" ]]; then
  340. PELICAN_DOMAIN_NAME='pelican.local'
  341. else
  342. PELICAN_DETAILS_COMPLETE=
  343. while [ ! $PELICAN_DETAILS_COMPLETE ]
  344. do
  345. data=$(mktemp 2>/dev/null)
  346. if [[ "$DDNS_PROVIDER" == *"freedns"* ]]; then
  347. dialog --backtitle $"Freedombone Configuration" \
  348. --title $"Pelican Blog Configuration" \
  349. --form $"\\nPlease enter your blog details.\\n\\nIMPORTANT: This should be a domain name which is supported by Let's Encrypt:" 14 65 2 \
  350. $"Domain:" 1 1 "$(grep 'PELICAN_DOMAIN_NAME' temp.cfg | awk -F '=' '{print $2}')" 1 25 33 40 \
  351. $"Code:" 2 1 "$(grep 'PELICAN_BLOG_CODE' temp.cfg | awk -F '=' '{print $2}')" 2 25 33 255 \
  352. 2> "$data"
  353. else
  354. dialog --backtitle $"Freedombone Configuration" \
  355. --title $"Pelican Blog Configuration" \
  356. --form $"\\nPlease enter your GNU Social details. The background image URL can be left blank.\\n\\nIMPORTANT: This should be a domain name which is supported by Let's Encrypt:" 14 65 2 \
  357. $"Domain:" 1 1 "$(grep 'PELICAN_DOMAIN_NAME' temp.cfg | awk -F '=' '{print $2}')" 1 25 33 40 \
  358. 2> "$data"
  359. fi
  360. sel=$?
  361. case $sel in
  362. 1) rm -f "$data"
  363. exit 1;;
  364. 255) rm -f "$data"
  365. exit 1;;
  366. esac
  367. PELICAN_DOMAIN_NAME=$(sed -n 1p < "$data")
  368. if [ "$PELICAN_DOMAIN_NAME" ]; then
  369. if [[ $PELICAN_DOMAIN_NAME == "$HUBZILLA_DOMAIN_NAME" ]]; then
  370. PELICAN_DOMAIN_NAME=""
  371. fi
  372. TEST_DOMAIN_NAME=$PELICAN_DOMAIN_NAME
  373. validate_domain_name
  374. if [[ "$TEST_DOMAIN_NAME" != "$PELICAN_DOMAIN_NAME" ]]; then
  375. PELICAN_DOMAIN_NAME=
  376. dialog --title $"Domain name validation" --msgbox "$TEST_DOMAIN_NAME" 15 50
  377. else
  378. if [[ "$DDNS_PROVIDER" == *"freedns"* ]]; then
  379. PELICAN_BLOG_CODE=$(sed -n 2p < "$data")
  380. validate_freedns_code "$PELICAN_BLOG_CODE"
  381. if [ ! "$VALID_CODE" ]; then
  382. PELICAN_DOMAIN_NAME=
  383. fi
  384. fi
  385. fi
  386. fi
  387. if [ $PELICAN_DOMAIN_NAME ]; then
  388. PELICAN_DETAILS_COMPLETE="yes"
  389. fi
  390. rm -f "$data"
  391. done
  392. # save the results in the config file
  393. write_config_param "PELICAN_BLOG_CODE" "$PELICAN_BLOG_CODE"
  394. fi
  395. write_config_param "PELICAN_DOMAIN_NAME" "$PELICAN_DOMAIN_NAME"
  396. APP_INSTALLED=1
  397. }
  398. function reconfigure_pelican {
  399. echo -n ''
  400. }
  401. function upgrade_pelican {
  402. echo -n ''
  403. }
  404. function backup_local_pelican {
  405. source_directory=/etc/blog
  406. if [ -d $source_directory ]; then
  407. dest_directory=pelican
  408. function_check backup_directory_to_usb
  409. backup_directory_to_usb $source_directory $dest_directory
  410. fi
  411. source_directory=/var/www/$PELICAN_DOMAIN_NAME/htdocs
  412. if [ -d $source_directory ]; then
  413. dest_directory=pelican-site
  414. function_check backup_directory_to_usb
  415. backup_directory_to_usb $source_directory $dest_directory
  416. fi
  417. }
  418. function restore_local_pelican {
  419. if [ -d /etc/blog ]; then
  420. if [ -d "$USB_MOUNT_DLNA/backup/pelican" ]; then
  421. temp_restore_dir=/root/temppelican
  422. function_check restore_directory_from_usb
  423. restore_directory_from_usb $temp_restore_dir pelican
  424. if [ -d $temp_restore_dir/etc/blog ]; then
  425. cp -r $temp_restore_dir/etc/blog/* /etc/blog/
  426. else
  427. cp -r $temp_restore_dir/* /etc/blog/
  428. fi
  429. # shellcheck disable=SC2181
  430. if [ ! "$?" = "0" ]; then
  431. rm -rf $temp_restore_dir
  432. function_check set_user_permissions
  433. set_user_permissions
  434. function_check backup_unmount_drive
  435. backup_unmount_drive
  436. exit 527942
  437. fi
  438. rm -rf $temp_restore_dir
  439. fi
  440. fi
  441. if [ -d /var/www/$PELICAN_DOMAIN_NAME/htdocs ]; then
  442. if [ -d "$USB_MOUNT_DLNA/backup/pelican-site" ]; then
  443. temp_restore_dir=/root/temppelican-site
  444. function_check restore_directory_from_usb
  445. restore_directory_from_usb $temp_restore_dir pelican-site
  446. if [ -d $temp_restore_dir/var/www/$PELICAN_DOMAIN_NAME/htdocs ]; then
  447. cp -r $temp_restore_dir/var/www/$PELICAN_DOMAIN_NAME/htdocs/* /var/www/$PELICAN_DOMAIN_NAME/htdocs/
  448. else
  449. cp -r $temp_restore_dir/* /var/www/$PELICAN_DOMAIN_NAME/htdocs/
  450. fi
  451. # shellcheck disable=SC2181
  452. if [ ! "$?" = "0" ]; then
  453. rm -rf $temp_restore_dir
  454. function_check set_user_permissions
  455. set_user_permissions
  456. function_check backup_unmount_drive
  457. backup_unmount_drive
  458. exit 2946282
  459. fi
  460. rm -rf $temp_restore_dir
  461. fi
  462. fi
  463. }
  464. function backup_remote_pelican {
  465. if [ -d /etc/blog ]; then
  466. backup_directory_to_friend /etc/blog pelican
  467. fi
  468. if [ -d /var/www/$PELICAN_DOMAIN_NAME/htdocs ]; then
  469. backup_directory_to_friend /var/www/$PELICAN_DOMAIN_NAME/htdocs pelican-site
  470. fi
  471. }
  472. function restore_remote_pelican {
  473. if [ -d /etc/blog ]; then
  474. if [ -d "$SERVER_DIRECTORY/backup/pelican" ]; then
  475. temp_restore_dir=/root/temppelican
  476. function_check restore_directory_from_friend
  477. restore_directory_from_friend $temp_restore_dir pelican
  478. if [ -d $temp_restore_dir/etc/blog ]; then
  479. cp -r $temp_restore_dir/etc/blog/* /etc/blog/
  480. else
  481. cp -r $temp_restore_dir/* /etc/blog/
  482. fi
  483. # shellcheck disable=SC2181
  484. if [ ! "$?" = "0" ]; then
  485. exit 782352
  486. fi
  487. rm -rf $temp_restore_dir
  488. fi
  489. fi
  490. if [ -d /var/www/$PELICAN_DOMAIN_NAME/htdocs ]; then
  491. if [ -d "$SERVER_DIRECTORY/backup/pelican-site" ]; then
  492. temp_restore_dir=/root/temppelican-site
  493. function_check restore_directory_from_friend
  494. restore_directory_from_friend $temp_restore_dir pelican-site
  495. if [ -d $temp_restore_dir/var/www/$PELICAN_DOMAIN_NAME/htdocs ]; then
  496. cp -r $temp_restore_dir/var/www/$PELICAN_DOMAIN_NAME/htdocs/* /var/www/$PELICAN_DOMAIN_NAME/htdocs/
  497. else
  498. cp -r $temp_restore_dir/* /var/www/$PELICAN_DOMAIN_NAME/htdocs/
  499. fi
  500. # shellcheck disable=SC2181
  501. if [ ! "$?" = "0" ]; then
  502. exit 76382562
  503. fi
  504. rm -rf $temp_restore_dir
  505. fi
  506. fi
  507. }
  508. function remove_pelican {
  509. if [ -f /etc/nginx/sites-available/$PELICAN_DOMAIN_NAME ]; then
  510. nginx_dissite pelican
  511. rm /etc/nginx/sites-available/$PELICAN_DOMAIN_NAME
  512. if [ -d /var/www/$PELICAN_DOMAIN_NAME ]; then
  513. rm -rf /var/www/$PELICAN_DOMAIN_NAME
  514. fi
  515. systemctl reload nginx
  516. fi
  517. pip uninstall pelican
  518. remove_certs $PELICAN_DOMAIN_NAME
  519. function_check remove_onion_service
  520. remove_onion_service pelican ${PELICAN_ONION_PORT}
  521. remove_app pelican
  522. systemctl restart tor
  523. }
  524. function create_pelican_conf {
  525. STATIC_BLOG_FILE="$1"
  526. { echo '#!/usr/bin/env python';
  527. echo '# -*- coding: utf-8 -*- #';
  528. echo 'from __future__ import unicode_literals';
  529. echo '';
  530. echo "AUTHOR=u\"$MY_USERNAME\"";
  531. echo "SITENAME=u'$DEFAULT_BLOG_TITLE'";
  532. echo "SITEURL=''";
  533. echo "PATH='content'";
  534. echo 'TIMEZONE=u"Europe/London"';
  535. echo "DEFAULT_LANG=u'en'";
  536. echo '';
  537. echo 'FEED_ALL_ATOM=None';
  538. echo 'CATEGORY_FEED_ATOM=None';
  539. echo 'TRANSLATION_FEED_ATOM=None';
  540. echo 'AUTHOR_FEED_ATOM=None';
  541. echo 'AUTHOR_FEED_RSS=None';
  542. echo '';
  543. echo 'DEFAULT_PAGINATION=False';
  544. echo 'RELATIVE_URLS=True';
  545. echo "THEME='themes/nice-blog'"; } > "$STATIC_BLOG_FILE"
  546. }
  547. function create_pelican_makefile {
  548. STATIC_BLOG_FILE="$1"
  549. { echo 'PY?=python';
  550. echo 'PELICAN?=pelican';
  551. echo 'PELICANOPTS=';
  552. echo '';
  553. echo "BASEDIR=\$(CURDIR)";
  554. echo "INPUTDIR=\$(BASEDIR)/content";
  555. echo "OUTPUTDIR=$PELICAN_BLOG_PATH";
  556. echo "CONFFILE=\$(BASEDIR)/pelicanconf.py";
  557. echo "PUBLISHCONF=\$(BASEDIR)/publishconf.py";
  558. echo '';
  559. echo 'DEBUG ?= 0';
  560. echo "ifeq (\$(DEBUG), 1)";
  561. echo -e '\tPELICANOPTS += -D';
  562. echo 'endif';
  563. echo '';
  564. echo 'RELATIVE ?= 0';
  565. echo "ifeq (\$(RELATIVE), 1)";
  566. echo -e '\tPELICANOPTS += --relative-urls';
  567. echo 'endif';
  568. echo '';
  569. echo 'html:';
  570. echo -e "\\t\$(PELICAN) \$(INPUTDIR) -o \$(OUTPUTDIR) -s \$(CONFFILE) \$(PELICANOPTS)";
  571. echo '';
  572. echo 'clean:';
  573. echo -e "\\t[ ! -d \$(OUTPUTDIR) ] || rm -rf \$(OUTPUTDIR)";
  574. echo '';
  575. echo 'regenerate:';
  576. echo -e "\\t\$(PELICAN) -r \$(INPUTDIR) -o \$(OUTPUTDIR) -s \$(CONFFILE) \$(PELICANOPTS)";
  577. echo '';
  578. echo 'serve:';
  579. echo 'ifdef PORT';
  580. echo -e "\\tcd \$(OUTPUTDIR) && \$(PY) -m pelican.server \$(PORT)";
  581. echo 'else';
  582. echo -e "\\tcd \$(OUTPUTDIR) && \$(PY) -m pelican.server";
  583. echo 'endif';
  584. echo '';
  585. echo 'serve-global:';
  586. echo 'ifdef SERVER';
  587. echo -e "\\tcd \$(OUTPUTDIR) && \$(PY) -m pelican.server 80 \$(SERVER)";
  588. echo 'else';
  589. echo -e "\\tcd \$(OUTPUTDIR) && \$(PY) -m pelican.server 80 0.0.0.0";
  590. echo 'endif';
  591. echo '';
  592. echo 'devserver:';
  593. echo 'ifdef PORT';
  594. echo -e "\\t\$(BASEDIR)/develop_server.sh restart \$(PORT)";
  595. echo 'else';
  596. echo -e "\\t\$(BASEDIR)/develop_server.sh restart";
  597. echo 'endif';
  598. echo '';
  599. echo 'stopserver:';
  600. echo -e "\\t\$(BASEDIR)/develop_server.sh stop";
  601. echo -e '\t@echo "Stopped Pelican and SimpleHTTPServer processes running in background."';
  602. echo '';
  603. echo 'publish:';
  604. echo -e "\\t\$(PELICAN) \$(INPUTDIR) -o \$(OUTPUTDIR) -s \$(PUBLISHCONF) \$(PELICANOPTS)";
  605. echo '';
  606. echo '.PHONY: html clean regenerate serve serve-global devserver publish'; } > "$STATIC_BLOG_FILE"
  607. }
  608. function create_pelican_publish_conf {
  609. STATIC_BLOG_FILE=$1
  610. { echo '#!/usr/bin/env python';
  611. echo '# -*- coding: utf-8 -*- #';
  612. echo 'from __future__ import unicode_literals';
  613. echo '';
  614. echo 'import os';
  615. echo 'import sys';
  616. echo 'sys.path.append(os.curdir)';
  617. echo 'from pelicanconf import *';
  618. echo '';
  619. echo "SITEURL = ''";
  620. echo 'RELATIVE_URLS = True';
  621. echo '';
  622. echo "FEED_ALL_ATOM = 'feeds/all.atom.xml'";
  623. echo "CATEGORY_FEED_ATOM = 'feeds/%s.atom.xml'";
  624. echo '';
  625. echo 'DELETE_OUTPUT_DIRECTORY = True'; } > "$STATIC_BLOG_FILE"
  626. }
  627. function pelican_themes {
  628. # Clone themes separately because the themes repo sometimes has bad refs
  629. git clone https://github.com/KenMercusLai/BT3-Flat
  630. git clone https://github.com/abr4xas/Casper2Pelican
  631. git clone https://github.com/alexandrevicenzi/Flex
  632. git clone https://github.com/allenskd/Nuja
  633. git clone https://github.com/ir193/Responsive-Pelican
  634. git clone https://github.com/nairobilug/pelican-alchemy
  635. git clone https://github.com/livibetter-backup/apricot
  636. git clone https://github.com/jody-frankowski/blue-penguin
  637. git clone https://github.com/gregseth/pelican-bgh
  638. git clone https://github.com/blueicefield/pelican-blueidea
  639. git clone https://github.com/demianbrecht/pelican-bold
  640. git clone https://github.com/fly/burrito
  641. git clone https://github.com/yuex/pelican-iliork
  642. git clone https://github.com/tbunnyman/pelican-chunk
  643. git clone https://github.com/hdra/Pelican-Cid
  644. git clone https://github.com/gilsondev/pelican-clean-blog
  645. git clone https://github.com/porterjamesj/crowsfoot
  646. git clone https://github.com/22decembre/dev-random3.git
  647. git clone https://github.com/kura/eevee
  648. git clone https://github.com/talha131/pelican-elegant.git
  649. git clone https://github.com/callmefish/pelican-free-agent
  650. git clone https://github.com/jsliang/pelican-fresh
  651. git clone https://github.com/vaiski/genus
  652. git clone https://github.com/PierrePaul/html5-dopetrope
  653. git clone https://github.com/jvanz/pelican-hyde
  654. git clone https://github.com/erfaan/pelican-theme-irfan
  655. git clone https://github.com/slok/iris
  656. git clone https://github.com/badele/pelican-theme-jesuislibre
  657. git clone https://github.com/mothsART/pelican-lab
  658. git clone https://github.com/siovene/lannisport
  659. git clone https://github.com/lazycoder-ru/lazystrap
  660. git clone https://github.com/chdoig/pelican-bootstrap3-lovers
  661. git clone https://github.com/kplaube/maggner-pelican
  662. git clone https://github.com/cpaulik/martin-pelican
  663. git clone https://github.com/greizgh/pelican-material
  664. git clone https://github.com/eswarm/materialistic-pelican
  665. git clone https://github.com/cprieto/pelican-mediumfox
  666. git clone https://github.com/onuraslan/medius
  667. git clone https://github.com/lucachr/pelican-mg
  668. git clone https://github.com/BYK/pelican-neat
  669. git clone https://github.com/molivier/nest
  670. git clone https://github.com/guilherme-toti/nice-blog
  671. git clone https://github.com/gunchu/nikhil-theme
  672. git clone https://github.com/wilbur-ma/niu-x2
  673. git clone https://github.com/duilio/pelican-octopress-theme
  674. git clone https://github.com/Parbhat/pelican-blue
  675. git clone https://github.com/hdra/pelican-cait
  676. git clone https://github.com/laughk/pelican-hss
  677. git clone https://github.com/wrl/pelican-mockingbird
  678. git clone https://github.com/fle/pelican-simplegrey
  679. git clone https://github.com/fle/pelican-sober
  680. git clone https://github.com/ingwinlu/pelican-twitchy
  681. git clone https://github.com/badele/pelicanthemes-generator
  682. git clone https://github.com/jjimenezlopez/pelipress
  683. git clone https://github.com/xm3ron/pjport
  684. git clone https://github.com/kdeldycke/plumage
  685. git clone https://github.com/habibillah/pujangga
  686. git clone https://github.com/danclaudiupop/pure
  687. git clone https://github.com/wamonite/relapse
  688. git clone https://github.com/ellisonleao/pelican-semantic-ui
  689. git clone https://github.com/kdheepak89/pelican-smoothie
  690. git clone https://github.com/if1live/pelican-sora
  691. git clone https://github.com/redVi/storm
  692. git clone https://github.com/keningle/pelican-sundown
  693. git clone https://github.com/giulivo/pelican-svbhack
  694. git clone https://github.com/wting/pelican-svbtle
  695. git clone https://github.com/frankV/twenty-pelican-html5up
  696. git clone https://github.com/robulouski/voidy-bootstrap
  697. git clone https://github.com/samael500/w3-personal-blog
  698. git clone https://github.com/jarv/water-iris
  699. git clone https://github.com/kplaube/yapeme
  700. pelican_remove_bad_blog_links
  701. }
  702. function mesh_install_pelican {
  703. # shellcheck disable=SC2153
  704. if [[ "$VARIANT" != "meshclient" && "$VARIANT" != "meshusb" && "$VARIANT" != "usb" ]]; then
  705. return
  706. fi
  707. # shellcheck disable=SC2154
  708. chroot "$rootdir" apt-get -yq install python-pip
  709. chroot "$rootdir" pip install ipython
  710. chroot "$rootdir" pip install Markdown
  711. chroot "$rootdir" pip install typogrify
  712. chroot "$rootdir" pip install pelican
  713. PELICAN_BLOG_INSTALL_DIR=/home/$MY_USERNAME/CreateBlog
  714. PELICAN_BLOG_PATH=/home/$MY_USERNAME/Public/Blog
  715. if [ ! -d "$rootdir$PELICAN_BLOG_INSTALL_DIR" ]; then
  716. mkdir -p "$rootdir$PELICAN_BLOG_INSTALL_DIR"
  717. fi
  718. if [ ! -d "$rootdir$PELICAN_BLOG_PATH" ]; then
  719. mkdir -p "$rootdir$PELICAN_BLOG_PATH"
  720. fi
  721. if [ ! -d "$rootdir$PELICAN_BLOG_INSTALL_DIR/content/images" ]; then
  722. mkdir -p "$rootdir$PELICAN_BLOG_INSTALL_DIR/content/images"
  723. fi
  724. create_pelican_conf "$rootdir$PELICAN_BLOG_INSTALL_DIR/pelicanconf.py"
  725. create_pelican_makefile "$rootdir$PELICAN_BLOG_INSTALL_DIR/Makefile"
  726. create_pelican_publish_conf "$rootdir$PELICAN_BLOG_INSTALL_DIR/publishconf.py"
  727. mkdir -p "$rootdir$PELICAN_BLOG_INSTALL_DIR/themes"
  728. cd "$rootdir$PELICAN_BLOG_INSTALL_DIR/themes" || exit 74624524
  729. pelican_themes
  730. #git clone --recursive $PELICAN_PLUGINS_REPO $rootdir$PELICAN_BLOG_INSTALL_DIR/plugins
  731. chroot "$rootdir" chown -R "$MY_USERNAME":"$MY_USERNAME" "$PELICAN_BLOG_INSTALL_DIR"
  732. chroot "$rootdir" chown -R "$MY_USERNAME":"$MY_USERNAME" "/home/$MY_USERNAME/Public"
  733. }
  734. function install_pelican {
  735. if [ "$INSTALLING_MESH" ]; then
  736. mesh_install_pelican
  737. return
  738. fi
  739. apt-get -yq install python-pip
  740. pip install ipython
  741. pip install Markdown
  742. pip install typogrify
  743. pip install pelican
  744. PELICAN_BLOG_PATH=/var/www/$PELICAN_DOMAIN_NAME/htdocs
  745. if [ ! -d "$PELICAN_BLOG_INSTALL_DIR" ]; then
  746. mkdir -p "$PELICAN_BLOG_INSTALL_DIR"
  747. fi
  748. if [ ! -d $PELICAN_BLOG_PATH ]; then
  749. mkdir -p $PELICAN_BLOG_PATH
  750. fi
  751. if [ ! -d "$PELICAN_BLOG_INSTALL_DIR/content" ]; then
  752. mkdir -p "$PELICAN_BLOG_INSTALL_DIR/content"
  753. fi
  754. create_pelican_conf "$PELICAN_BLOG_INSTALL_DIR/pelicanconf.py"
  755. create_pelican_makefile "$PELICAN_BLOG_INSTALL_DIR/Makefile"
  756. create_pelican_publish_conf "$PELICAN_BLOG_INSTALL_DIR/publishconf.py"
  757. mkdir -p "$PELICAN_THEMES_REPO" "$PELICAN_BLOG_INSTALL_DIR/themes"
  758. cd "$PELICAN_BLOG_INSTALL_DIR/themes" || exit 45357282883
  759. pelican_themes
  760. #git clone --recursive $PELICAN_PLUGINS_REPO $PELICAN_BLOG_INSTALL_DIR/plugins
  761. chown -R "$MY_USERNAME":"$MY_USERNAME" "$PELICAN_BLOG_INSTALL_DIR"
  762. chown -R www-data:www-data $PELICAN_BLOG_PATH
  763. pelican_editor_config
  764. PELICAN_ONION_HOSTNAME=$(add_onion_service pelican 80 ${PELICAN_ONION_PORT})
  765. set_completion_param "pelican onion domain" "$PELICAN_ONION_HOSTNAME"
  766. install_pelican_website
  767. install_pelican_website_onion
  768. pelican_regenerate_blog
  769. if [ ! -d "$PELICAN_BLOG_INSTALL_DIR/output" ]; then
  770. echo $'Failed to generate pelican blog'
  771. exit 521892
  772. fi
  773. function_check nginx_ensite
  774. nginx_ensite $PELICAN_DOMAIN_NAME
  775. systemctl restart nginx
  776. APP_INSTALLED=1
  777. }
  778. # NOTE: deliberately no exit 0