termux_run.sh 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. #!/bin/bash
  2. cd "$(dirname "$0")";
  3. . src/ask.sh #import the ask()
  4. . i/template/tor.html.sh #import tor template page | tor.html()
  5. . i/template/standalone.sh #import standalone html page | print_standalone()
  6. . bin/config.sh &> /dev/null #import config
  7. chmod 770 bin/*
  8. chmod 770 i/template/*
  9. chmod 770 src/*
  10. #help page
  11. function purge_guide() {
  12. cat <<EOF
  13. -p
  14. --delete (it does not include the static contents)
  15. --delete-all (purge all files, it does include the static contents)
  16. EOF
  17. }
  18. function guide() {
  19. echo "usage: ./`basename $0` [-h] [-b|-c] [-g] [-t] | [ -p --delete | --delete-all ]"
  20. echo "-h help page"
  21. echo "-b build html."
  22. echo "-c create static contents (as image etc.)"
  23. echo "-g generate the web site as use created files"
  24. echo "-t view tor adress"
  25. purge_guide;
  26. }
  27. #build html files [-b] option
  28. function build() {
  29. rm -rf i/out/*;
  30. mkdir -p i/out/{copy,pdf,rss};
  31. mkdir -p .tmp/;
  32. bin/generate_author_pages.sh -gl
  33. bin/generate_copy_files.sh -egl
  34. bin/generate_websites_index.sh && echo "websites index page generated"
  35. }
  36. #create static contents [-c] option
  37. function create() {
  38. mkdir -p i/listen/copy
  39. bin/generate_pdf_files.sh -iem #-c option is delete already created files
  40. }
  41. #generate the web site as use created files [-g option]
  42. function main() {
  43. mkdir -p public/;
  44. chmod 0755 public/;
  45. find public/free -type l -exec unlink {} \; &> /dev/null && echo "symbolic links removed"
  46. rm -rf public/* &> /dev/null && echo "pages deleted"
  47. mkdir public/free &> /dev/null && echo "pdf raw dir created"
  48. cp -r i/out/* public/ && echo "i/out/* files are copied."
  49. cp -r i/listen/copy/ public/ && echo "i/listen/copy/ dir copied"
  50. cp -r i/contents/* public/ && echo "i/contents/* are copied"
  51. ln -s $pdf_dir/* public/free && echo "/var/pdf/ symbolic link created"
  52. tor.html > public/tor.html && echo "tor.html created"
  53. print_standalone > public/print.html && echo "print.html created"
  54. mkdir public/index && echo "index page creating.."
  55. nohup bash src/index.sh > public/index/index.html &
  56. find public/ -type f -exec chmod 0644 {} \; &> /dev/null && echo "files permissions setted"
  57. find public/ -type d -exec chmod 0755 {} \; &> /dev/null && echo "directory permissions setted"
  58. }
  59. #purge everything [-p] option
  60. function purge() {
  61. function delete_default() {
  62. rm -rf i/out/* && echo "i/out/* are deleted";
  63. rm -rf public/* && echo "public/* are deleted";
  64. rm -rf .tmp/* && echo ".tmp/* are deleted";
  65. find -path '.tmp/.*' -delete && echo ".tmp/.* are deleted";
  66. }
  67. function delete_static() {
  68. rm -rf i/listen/copy/* && echo "i/listen/* are deleted";
  69. }
  70. case $purge_arg in
  71. --delete)
  72. delete_default
  73. ;;
  74. --delete-all)
  75. delete_default
  76. if ask "do you want the delete static files?" N; then
  77. delete_static;
  78. else
  79. echo "--delete-all option is bypassed"
  80. fi
  81. ;;
  82. *)
  83. echo "unknown option: $purge_arg"
  84. purge_guide;
  85. ;;
  86. esac
  87. }
  88. while getopts ":hbcgtp:" opt; do
  89. case ${opt} in
  90. h ) guide;
  91. ;;
  92. b ) build;
  93. ;;
  94. c ) create;
  95. ;;
  96. g ) main;
  97. ;;
  98. t ) cat web/hostname 2>/dev/null || echo "tor address not defined in web/hostname";
  99. ;;
  100. p )
  101. purge_arg=${OPTARG}
  102. purge
  103. ;;
  104. : )
  105. echo "Missing option argument for -$OPTARG [ --default | --all ]"
  106. purge_guide
  107. ;;
  108. esac
  109. done
  110. if [ "$#" -lt 1 ]; then
  111. guide;
  112. fi