freedombone-app-pelican 30KB

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