-
Notifications
You must be signed in to change notification settings - Fork 0
/
mt-gitpub.sh
executable file
·96 lines (70 loc) · 1.83 KB
/
mt-gitpub.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#!/bin/bash
# MT-GitPub
# Copyright 2009 Al Shaw <[email protected]> http://www.shhhaw.com
# GPL v3 http://www.gnu.org/copyleft/gpl.html
#####
# requires mt-rebuild http://appnel.com/code/mt-rebuild
# Create & fill out config.sh (or rename and modify config-sample.sh) before running this script.
######
#initialize config file. customize config.sh
configfile=$(dirname $0)/config.sh
source $configfile
trackmode=committed
setup=off
# OPTIONS
# alternate config file -c altconfigfilename
# use modified instead of committed -m
# setup mode -s newconfigfilename
while getopts "c:s:m" OPTION
do
case $OPTION in
c)
configfile=$(dirname $0)/$OPTARG
source $configfile
;;
m) trackmode=modified
;;
s)
setup=on
configfilename=$OPTARG
;;
esac
done
#if we're in setup mode, run setup.sh and then quit
if [ $setup = on ];
then
source setup.sh
exit
fi
# get our mt files
files=$(awk '/indextmpl/ {print $2}' $configfile)
mtfilesarr=( `echo $files` )
# get our changed files on last commit, and store in an array
CURDIR=`pwd`
cd $GITDIR
#use modified or committed files?
if [ $trackmode = modified ];
then
changedfiles=$(git status | grep modified)
else
if [ $trackmode = committed ];
then
changedfiles=$(git log -n 1 --name-only --pretty=format:)
fi
fi
changedfilesarr=( `echo $changedfiles` )
# change back to curdir
cd $CURDIR
#check to see if we want to publish any index templates
for file in ${changedfilesarr[@]}
do
for mtfile in ${mtfilesarr[@]}
do
filename=`awk '/'"$mtfile"'/ {for(i=3;i<=(NF-1);i++){printf("%s ", $i)}print($NF)}' "$configfile"`
if [ "X$mtfile" = "X$file" ]
then
echo "i will publish $file ($filename) (index template) ($trackmode)"
perl $mtrebuild -mode="index" -blog_id="$blog_id" -template="$filename"
fi
done
done