public
Description: Git mirror of the CMS Made Simple 2.0 rewrite
Homepage: http://cmsmadesimple.org
Clone URL: git://github.com/tedkulp/cmsmadesimple-2-0.git
cmsmadesimple-2-0 / scripts / CreateModuleRelease.sh
100755 150 lines (130 sloc) 3.577 kb
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#!/bin/sh
# bourne shell script to create a release archive of a cmsms module
# within a cmsms install
 
# finds the name
_this=`basename "$0"`
_configfile=${HOME}/.CreateRelease.rc
_pwd="`pwd`"
_name=`basename "$_pwd"`
_destdir=${HOME}
_version=0
_excludes="*~ #*# .svn CVS *.bak"
_tmpfile="/tmp/$_this.$$"
_yes=0
 
usage()
{
  echo "USAGE $_this [options]"
  echo "options:";
  echo " -c|--configfile <filename> : source this file for config information"
  echo " -d|--destdir <directory> : place output file in directory"
  echo " -n|--name <name> : use name for module name (use caution)"
  echo " -v|--version <version> : use version for version tag"
  echo " -v|--exclude <pattern> : exclude files matching this pattern"
  echo " from the resulting archive"
  echo " -q|--quiet : assume non interactive mode"
  echo " -h|-help|--help : this text"
  echo
echo "NOTE: This utility expects the module or the desired export directory"
  echo " to be your current working directory. It also looks for a file"
  echo " entitled <name>.module.php in the current working directory"
  echo " If this file does not exist, the script will not proceed"
  echo
}
 
# read in any default config file if it exists
if [ -r ${_configfile} ]; then
 . ${_configfile}
fi
 
# process command line arguments
while [ $# -gt 0 ]; do
case $1 in
    -c|--configfile)
      . $2
      shift 2
      continue
      ;;
 
    -d|--destdir)
      _destdir=$2
      shift 2
      continue
      ;;
 
    -n|--name)
      _name=$2
      shift
continue
      ;;
 
    -v|--version)
      _version=$2
      shift 2
      continue
      ;;
 
    -e|--exclude)
      _excludes="$_excludes $2"
      shift 2
      continue
      ;;
 
    -q|--quiet)
      _yes=1
      shift
continue
      ;;
 
    -h|--help|-help)
      usage;
      exit 0;
      ;;
  
    *)
      echo "FATAL: unrecognized option $1"
      usage
      exit 1
  esac
done
 
# validate command line arguments
if [ ! -d $_destdir -o ! -w $_destdir ]; then
echo "FATAL: $_destdir does not exist or is not writable"
  exit 1
fi
 
# find the filename
_fn=${_name}.module.php
if [ ! -r ${_fn} ]; then
echo "FATAL: Could not find ${_fn}"
  exit 1
fi
 
# find the version
# thanks to _SjG_ the perl regexp expert
_version2=`cat ${_fn} | perl -0777 -p -e 's/(.*?)function\s+GetVersion\(\)\s*\{\s*return\s*[\"\047]([^;\047\"]+)(.*)/$2/s'`
if [ ${_version2:-notset} = notset ]; then
echo "WARNING: could not auto-detect the version from the module.php file"
fi
 
#| perl -0777 -p -e 's/(.*?)function\s+GetVersion\(\)\s*\{\s*return\s*([^;]+)(.*)/$2/s' | cut -d\' -f2 | cut -d\" -f2
# asks for the veersion
while [ $_version = 0 ]; do
echo -n "Please enter a version string like x.xx.x ($_version2): "
  read _v
  if [ ${_v:-notset} = notset ]; then
_version=$_version2;
  else
_version=$_v
  fi
done
 
# Ask for confirmation
if [ $_yes = 0 ]; then
echo "Do you want to create a file named ${_name}-${_version}.tar.gz"
  echo " in ${_destdir} using the contents of "
  echo -n " $_pwd (y/n)?"
  read _ans
  if [ $_ans = 'y' -o $_ans = 'Y' -o $_ans = 'YES' -o $_ans = 'yes' ]; then
_yes=1
  fi
fi
if [ $_yes = 0 ]; then
exit 0;
fi
 
# make a temporary file of all the stuff we don't want in the archive
for i in $_excludes ; do
echo $i >> $_tmpfile
done
 
# create the archive
_destname=${_destdir}/${_name}-${_version}.tar.gz
cd ..
tar zcvXf ${_tmpfile} ${_destname} ${_name}
 
# and cleanup
rm -f $_tmpfile 2>/dev/null