Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # cat var.sh
- # directorys in variables
- com=/var/www/silviosiefke.com
- de=/var/www/silviosiefke.de
- fr=/var/www/silviosiefke.fr
- # files in variables
- old=site.old
- now=site.now
- cold=count.old
- cnow=count.now
- diffr=changes
- # languages
- comlang="New Article"
- delang="Neuer Artikel"
- frlang="Nouvel article"
- # cat func.sh
- #!/bin/bash
- # build website
- web() {
- pfad="$1"
- if [ -d "/var/www/silviosiefke.de/etc/python" ]; then
- cd $pfad/htdocs
- mv howto howto1
- source /var/www/silviosiefke.de/etc/python/bin/activate
- cd $pfad/etc/liquid
- liquidluck build
- deactivate
- cd $pfad/htdocs
- rm -r howto
- mv howto1 howto
- rm CNAME
- fi
- }
- # rsync run
- publish() {
- pfad="$1"
- rsync -avuz --delete $pfad/htdocs/ web:$pfad/htdocs
- }
- # count the directory
- count() {
- pfad="$1"
- find $pfad/htdocs -type d | wc -l > $pfad/etc/files/$cnow
- }
- # check new website structure
- changes() {
- pfad="$1"
- find $pfad/htdocs -mindepth 5 -type d > $pfad/etc/files/$now
- }
- # find new article
- assort() {
- pfad="$1"
- sort "$pfad/etc/files/$old" "$pfad/etc/files/$now" | uniq -u > $pfad/etc/files/$diffr
- }
- # extract title
- title() {
- pfad="$1"
- var=$(cat $(cat $pfad/etc/files/$diffr)/index.html | grep h1 | hxselect -s "\n" -c "h1")
- }
- # extract directory
- track() {
- pfad="$1"
- var=$(cat $pfad/etc/files/$diffr | cut -d / -f6,7,8,9,10)
- }
- # tweeten
- tweeten() {
- pfad="$1"
- # check directory exists
- if [ -d $pfad -a -f $pfad/etc/files/$old -a -f $pfad/etc/files/$cold ]; then
- # count the directorys
- count $pfad
- # check count files for diffrence
- if [ $(cat $pfad/etc/files/$cold) -lt $(cat $pfad/etc/files/$cnow) ]; then
- # we have change then sort the files to find the diffrence
- if [ $(changes $pfad) ]; then
- # sort the files
- assort $pfad
- # extract title
- title $pfad
- # extract path
- track $pfad
- # send tweet with article link and Headline
- /home/siefke/.bin/script/tweetshell.py "http://silviosiefke.de/$pfad - Neuer Artikel: $title..."
- # clean the directorys and files
- mv $pfad/etc/files/$now $pfad/etc/files/$old
- mv $pfad/etc/files/$cnow $pfad/etc/files/$cold
- rm $pfad/etc/files/$diffr
- fi
- else
- rm $pfad/etc/files/$cnow
- echo "Twitter Update not need"
- fi
- fi
- }
- # git commit
- control() {
- pfad="$1"
- if [ -d $pfad -a -f $pfad/etc/files/$old -a -f $pfad/etc/files/$cold ]; then
- # count the actuell directorys
- count $pfad
- # check count files for diffrence
- if [ $(cat $pfad/etc/files/$cold) -lt $(cat $pfad/etc/files/$cnow) ]; then
- # we have change then sort the files to find the diffrence
- if [ $(changes $pfad) ]; then
- # sort the files
- assort $pfad
- # extract title
- title $pfad
- if [ $pfad = $de ]; then
- 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\""
- elif [ $pfad = $fr ]; then
- 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\""
- elif [ $pfad = $com ]; then
- 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\""
- # clean the directorys and files
- mv $pfad/etc/files/$now $pfad/etc/files/$old
- mv $pfad/etc/files/$cnow $pfad/etc/files/$cold
- rm $pfad/etc/files/$diffr
- fi
- fi
- else
- rm $pfad/etc/files/$cnow
- echo "we send only commit when publish new article"
- fi
- fi
- }
- # cat website script
- #!/bin/bash
- work=/home/siefke/.bin/scripts
- source $work/var.sh
- source $work/func.sh
- case $1 in
- de)
- if [ "`type -t web`" = 'function' ]; then
- if web $de; then
- publish $de
- control $de
- tweeten $de
- echo "german website build"
- fi
- fi
- ;;
- fr)
- if [ "`type -t web`" = 'function' ]; then
- if web $fr; then
- publish $fr
- control $fr
- tweeten $fr
- echo "french website build"
- fi
- fi
- ;;
- com)
- if [ "`type -t web`" = 'function' ]; then
- if web $com; then
- publish $com
- control $com
- tweeten $com
- echo "english website build"
- fi
- fi
- ;;
- static)
- echo "static ordner benötigt update"
- rsync -avuz --delete /var/www/static.silviosiefke.com/htdocs/ web:/var/www/static.silviosiefke.com/htdocs
- ;;
- start)
- if [ -d "/etc/init.d" -a -f "/etc/init.d/nginx" -a -f "/etc/init.d/php-fpm" ]; then
- sudo /etc/init.d/php-fpm start
- sudo /etc/init.d/nginx start
- fi
- ;;
- stop)
- if [ pgrep nginx > /dev/null 2>&1 ]; then
- sudo /etc/init.d/nginx stop
- elif
- [ pgrep php-fpm > /dev/null 2>&1 ]; then
- sudo /etc/init.d/php-fpm stop
- else
- echo "Webumgebung läuft nicht"
- fi
- ;;
- *)
- printf "de > baut die Deutsche Website\n"
- printf "fr > baut die Französische Website\n"
- printf "com > baut die Englische Website\n"
- printf "static > update für statistische Inhalte\n"
- printf "start > startet die Webentwicklungsumgebung\n"
- printf "stop > stoppt die Webentwicklungsumgebung\n"
- ;;
- esac
Advertisement
Add Comment
Please, Sign In to add comment