Guest User

website bash scripting

a guest
Aug 24th, 2014
281
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 5.43 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # cat var.sh
  4. # directorys in variables
  5. com=/var/www/silviosiefke.com
  6. de=/var/www/silviosiefke.de
  7. fr=/var/www/silviosiefke.fr
  8.  
  9. # files in variables
  10. old=site.old
  11. now=site.now
  12. cold=count.old
  13. cnow=count.now
  14. diffr=changes
  15.  
  16. # languages
  17. comlang="New Article"
  18. delang="Neuer Artikel"
  19. frlang="Nouvel article"
  20.  
  21. # cat func.sh
  22. #!/bin/bash
  23.  
  24. # build website
  25. web() {
  26.     pfad="$1"
  27.        
  28.         if [ -d "/var/www/silviosiefke.de/etc/python" ]; then
  29.             cd $pfad/htdocs
  30.             mv howto howto1
  31.             source /var/www/silviosiefke.de/etc/python/bin/activate
  32.             cd $pfad/etc/liquid
  33.             liquidluck build
  34.             deactivate
  35.             cd $pfad/htdocs
  36.             rm -r howto
  37.             mv howto1 howto
  38.             rm CNAME
  39.         fi
  40. }
  41.  
  42. # rsync run
  43. publish() {
  44.     pfad="$1"
  45.     rsync -avuz --delete $pfad/htdocs/ web:$pfad/htdocs
  46. }
  47.  
  48. # count the directory
  49. count() {
  50.     pfad="$1"
  51.     find $pfad/htdocs -type d | wc -l > $pfad/etc/files/$cnow
  52. }
  53.  
  54. # check new website structure
  55. changes() {
  56.     pfad="$1"
  57.     find $pfad/htdocs -mindepth 5 -type d > $pfad/etc/files/$now
  58. }
  59.  
  60. # find new article
  61. assort() {
  62.     pfad="$1"
  63.     sort "$pfad/etc/files/$old" "$pfad/etc/files/$now" | uniq -u > $pfad/etc/files/$diffr
  64. }
  65.  
  66. # extract title
  67. title() {
  68.     pfad="$1"
  69.     var=$(cat $(cat $pfad/etc/files/$diffr)/index.html | grep h1 | hxselect -s "\n" -c "h1")
  70. }
  71.  
  72. # extract directory
  73. track() {
  74.     pfad="$1"
  75.     var=$(cat $pfad/etc/files/$diffr | cut -d / -f6,7,8,9,10)
  76. }
  77.  
  78. # tweeten
  79. tweeten() {
  80.     pfad="$1"
  81.    
  82.         # check directory exists
  83.         if [ -d $pfad -a -f $pfad/etc/files/$old -a -f $pfad/etc/files/$cold ]; then
  84.            
  85.             # count the directorys
  86.             count $pfad
  87.            
  88.             # check count files for diffrence
  89.             if [ $(cat $pfad/etc/files/$cold) -lt $(cat $pfad/etc/files/$cnow) ]; then
  90.                
  91.                 # we have change then sort the files to find the diffrence
  92.                 if [ $(changes $pfad) ]; then
  93.                    
  94.                     # sort the files
  95.                     assort $pfad
  96.                    
  97.                     # extract title
  98.                     title $pfad
  99.                    
  100.                     # extract path
  101.                     track $pfad
  102.                    
  103.                     # send tweet with article link and Headline
  104.                     /home/siefke/.bin/script/tweetshell.py "http://silviosiefke.de/$pfad - Neuer Artikel: $title..."
  105.                    
  106.                     # clean the directorys and files
  107.                     mv $pfad/etc/files/$now $pfad/etc/files/$old
  108.                     mv $pfad/etc/files/$cnow $pfad/etc/files/$cold
  109.                     rm $pfad/etc/files/$diffr
  110.                 fi
  111.                
  112.             else
  113.                 rm $pfad/etc/files/$cnow
  114.                 echo "Twitter Update not need"
  115.             fi
  116.         fi
  117. }
  118.  
  119. # git commit
  120. control() {
  121.     pfad="$1"
  122.    
  123.         if [ -d $pfad -a -f $pfad/etc/files/$old -a -f $pfad/etc/files/$cold ]; then
  124.            
  125.             # count the actuell directorys
  126.             count $pfad
  127.            
  128.             # check count files for diffrence
  129.             if [ $(cat $pfad/etc/files/$cold) -lt $(cat $pfad/etc/files/$cnow) ]; then
  130.                
  131.                 # we have change then sort the files to find the diffrence
  132.                 if [ $(changes $pfad) ]; then
  133.                    
  134.                     # sort the files
  135.                     assort $pfad
  136.                    
  137.                     # extract title
  138.                     title $pfad
  139.  
  140.                     if [ $pfad = $de ]; then
  141.                         ssh web "export PATH=${PATH}:/usr/bin:/bin:/usr/sbin:/sbin; (cd $pfad && git add . && git commit -m \"$delang - $title\") && echo ERFOLGREICH || echo \"Nicht erfolgreich\""
  142.                        
  143.                     elif [ $pfad = $fr ]; then
  144.                         ssh web "export PATH=${PATH}:/usr/bin:/bin:/usr/sbin:/sbin; (cd $pfad && git add . && git commit -m \"$frlang - $title\") && echo ERFOLGREICH || echo \"Nicht erfolgreich\""
  145.                        
  146.                     elif [ $pfad = $com ]; then
  147.                         ssh web "export PATH=${PATH}:/usr/bin:/bin:/usr/sbin:/sbin; (cd $pfad && git add . && git commit -m \"$comlang - $title\") && echo ERFOLGREICH || echo \"Nicht erfolgreich\""
  148.                
  149.                     # clean the directorys and files
  150.                     mv $pfad/etc/files/$now $pfad/etc/files/$old
  151.                     mv $pfad/etc/files/$cnow $pfad/etc/files/$cold
  152.                     rm $pfad/etc/files/$diffr              
  153.                 fi
  154.             fi
  155.            
  156.             else
  157.                 rm $pfad/etc/files/$cnow
  158.                 echo "we send only commit when publish new article"
  159.         fi
  160.     fi
  161. }
  162.  
  163. # cat website script
  164. #!/bin/bash
  165.  
  166. work=/home/siefke/.bin/scripts
  167. source $work/var.sh
  168. source $work/func.sh
  169.  
  170. case $1 in
  171.     de)
  172.         if [ "`type -t web`" = 'function' ]; then
  173.                 if web $de; then
  174.                         publish $de
  175.                         control $de
  176.                         tweeten $de
  177.                        
  178.                         echo "german website build"
  179.                 fi
  180.         fi     
  181.     ;;
  182.  
  183.  
  184.     fr)
  185.         if [ "`type -t web`" = 'function' ]; then
  186.                 if web $fr; then
  187.                         publish $fr
  188.                         control $fr
  189.                         tweeten $fr
  190.                        
  191.                         echo "french website build"
  192.                 fi
  193.         fi     
  194.     ;;
  195.    
  196.     com)
  197.         if [ "`type -t web`" = 'function' ]; then
  198.                 if web $com; then
  199.                         publish $com
  200.                         control $com
  201.                         tweeten $com
  202.                        
  203.                         echo "english website build"
  204.                 fi
  205.         fi     
  206.     ;;
  207.    
  208.     static)
  209.         echo "static ordner benötigt update"
  210.         rsync -avuz --delete /var/www/static.silviosiefke.com/htdocs/ web:/var/www/static.silviosiefke.com/htdocs
  211.     ;; 
  212.  
  213.     start)
  214.         if [ -d "/etc/init.d" -a -f "/etc/init.d/nginx" -a -f "/etc/init.d/php-fpm" ]; then
  215.             sudo /etc/init.d/php-fpm start
  216.             sudo /etc/init.d/nginx start
  217.         fi
  218.     ;;
  219.    
  220.     stop)
  221.         if [ pgrep nginx > /dev/null 2>&1 ]; then
  222.              sudo /etc/init.d/nginx stop
  223.            
  224.         elif
  225.              [ pgrep php-fpm > /dev/null 2>&1 ]; then
  226.              sudo /etc/init.d/php-fpm stop
  227.        
  228.         else
  229.              echo "Webumgebung läuft nicht"
  230.         fi
  231.     ;;
  232.    
  233.     *)
  234.     printf "de     > baut die Deutsche Website\n"
  235.     printf "fr     > baut die Französische Website\n"
  236.     printf "com    > baut die Englische Website\n"
  237.     printf "static > update für statistische Inhalte\n"
  238.     printf "start  > startet die Webentwicklungsumgebung\n"
  239.     printf "stop   > stoppt die Webentwicklungsumgebung\n"
  240.     ;;
  241.    
  242. esac
Advertisement
Add Comment
Please, Sign In to add comment