• R/O
  • SSH
  • HTTPS

zerochplus: Commit


Commit MetaInfo

Revisão545 (tree)
Hora2017-12-06 00:45:59
Autoriroiro

Mensagem de Log

Packaging Script

Mudança Sumário

Diff

--- codes/package.sh (nonexistent)
+++ codes/package.sh (revision 545)
@@ -0,0 +1,248 @@
1+#!/bin/sh
2+
3+main() {
4+ init "$1"
5+
6+ setting
7+
8+ packaging
9+}
10+
11+init() {
12+ echo "## Check and Initialize"
13+
14+ task "check commands"
15+ if ! which mktemp > /dev/null 2> /dev/null; then
16+ fail "mktemp command is not available."
17+ elif ! which grep > /dev/null 2> /dev/null; then
18+ fail "grep command is not available."
19+ elif ! which sed > /dev/null 2> /dev/null; then
20+ fail "sed command is not available."
21+ elif ! which perl > /dev/null 2> /dev/null; then
22+ fail "perl command is not available."
23+ elif ! which zip > /dev/null 2> /dev/null; then
24+ fail "zip command is not available."
25+ elif ! which find > /dev/null 2> /dev/null; then
26+ fail "find command is not available."
27+ elif ! which tar > /dev/null 2> /dev/null; then
28+ fail "tar command is not available."
29+ elif ! which gzip > /dev/null 2> /dev/null; then
30+ fail "gzip command is not available."
31+ elif ! which sed > /dev/null 2> /dev/null; then
32+ fail "sed command is not available."
33+ else
34+ succ
35+ fi
36+ result
37+
38+ task "source directory"
39+ SRCDIR="$1"
40+ if [ -z "$SRCDIR" ]; then
41+ fail "source directory is not specified."
42+ elif [ ! -d "$SRCDIR" ]; then
43+ fail "specified directory is not a directory."
44+ elif [ ! -d "$SRCDIR/test" ]; then
45+ fail "specified directory may not be a zerochplus directory."
46+ else
47+ succ
48+ fi
49+ result
50+ debug "SRCDIR=\"$SRCDIR\""
51+
52+ task "output directory"
53+ OUTDIR="."
54+ if [ ! -w "$SRCDIR" ]; then
55+ fail "output directory is not writable."
56+ else
57+ succ
58+ fi
59+ result
60+ debug "OUTDIR=\"$OUTDIR\""
61+
62+ task "temporary directory"
63+ TMPDIR=`mktemp -d`
64+ if [ $? -ne 0 ]; then
65+ fail "failed to make temporary directory."
66+ else
67+ succ
68+ fi
69+ result
70+ debug "TMPDIR=\"$TMPDIR\""
71+
72+ echo
73+}
74+
75+setting() {
76+ echo "## Package Configuration"
77+
78+ task "package version"
79+ while true; do
80+ read -p "specify package version (X.Y.Z or dev-rNNN)> " PKGVER
81+ if echo -n "$PKGVER" | grep -q '^[0-9]\+\.[0-9]\+\.[0-9]\+$'; then
82+ break
83+ elif echo -n "$PKGVER" | grep -q '^dev-r[0-9]\+$'; then
84+ break
85+ fi
86+ done
87+
88+ task "release date"
89+ while true; do
90+ suggest=`date +%Y%m%d`
91+ read -p "specify release date (YYYYMMDD) [$suggest]> " PKGDATE
92+ if [ -z "$PKGDATE" ]; then
93+ PKGDATE="$suggest"
94+ break
95+ elif echo -n "$PKGDATE" | grep -q '^20[0-9][0-9]\(0[1-9]\|1[0-2]\)\([0-2][1-9]\|3[01]\)$'; then
96+ break
97+ fi
98+ done
99+
100+ task "package name"
101+ while true; do
102+ suggest="zerochplus_$PKGVER"
103+ read -p "specify package name [$suggest]> " PKGNAME
104+ if [ -z "$PKGNAME" ]; then
105+ PKGNAME="$suggest"
106+ break
107+ elif echo -n "$PKGNAME" | grep -q '^[a-zA-Z0-9]\([a-zA-Z0-9_\.\-]*[a-zA-Z0-9]\)\?$'; then
108+ break
109+ fi
110+ done
111+
112+ echo
113+}
114+
115+packaging() {
116+ echo '## Preprocessing and Packaging'
117+
118+ task "clean output directory"
119+ rm -f "$OUTDIR/$PKGNAME.zip"
120+ rm -f "$OUTDIR/$PKGNAME.tar.gz"
121+ result
122+
123+ task "copy source directory"
124+ cp -r "$SRCDIR" "$TMPDIR/$PKGNAME"
125+ if [ $? -ne 0 ]; then
126+ fail "failed to copy source directory."
127+ else
128+ succ
129+ fi
130+ result
131+
132+ task "comment out debug code"
133+ scr="$TMPDIR/cmout.sed"
134+ echo 's/use CGI::Carp/#&/' >> "$scr"
135+ echo 's/use warnings/#&/' >> "$scr"
136+ echo '/#PERLPATH/c#!/usr/bin/perl --' >> "$scr"
137+ echo '/#DEBUGLINE/d' >> "$scr"
138+ echo '/#DEBUGBEGIN/,/#DEBUGEND/d' >> "$scr"
139+ for FILE in "$TMPDIR/$PKGNAME"/test/*.cgi \
140+ "$TMPDIR/$PKGNAME"/test/module/*.pl \
141+ "$TMPDIR/$PKGNAME"/test/mordor/*.pl; do
142+ sed -f "$scr" -i "$FILE" # in-place
143+ done
144+ result
145+
146+ task "replace placeholder"
147+ scr="$TMPDIR/replace.sed"
148+ rm -f "$scr"
149+ echo "s/{=0ch+ver=}/$PKGVER/g" >> "$scr"
150+ echo "s/{=0ch+date=}/$PKGDATE/g" >> "$scr"
151+ echo "s/{=0ch+year=}/${PKGDATE:0:4}/g" >> "$scr"
152+ for FILE in "$TMPDIR/$PKGNAME"/Readme/Readme.txt \
153+ "$TMPDIR/$PKGNAME"/test/module/melkor.pl \
154+ "$TMPDIR/$PKGNAME"/test/mordor/login.pl \
155+ "$TMPDIR/$PKGNAME"/test/mordor/sauron.pl; do
156+ sed -f "$scr" -i "$FILE" # in-place
157+ done
158+ result
159+
160+ task "compress to zip"
161+ tmp="$TMPDIR/$PKGNAME.zip"
162+ pushd "$TMPDIR/" > /dev/null
163+ zip -qr "$tmp" "$PKGNAME"
164+ popd > /dev/null
165+ mv "$tmp" "$OUTDIR/"
166+ result
167+
168+ task "strip carriage return"
169+ for FILE in "$TMPDIR/$PKGNAME"/test/*.cgi \
170+ "$TMPDIR/$PKGNAME"/test/module/*.pl \
171+ "$TMPDIR/$PKGNAME"/test/mordor/*.pl \
172+ "$TMPDIR/$PKGNAME"/test/plugin/*.pl; do
173+ perl -pe 's/\r//' -i "$FILE" # in-place
174+ done
175+ result
176+
177+ task "compress to tar.gz"
178+ tmp="$TMPDIR/$PKGNAME.tar"
179+ pushd "$TMPDIR/" > /dev/null
180+ find $PKGNAME/ -type d -exec tar -cf "$tmp" --mode=0777 --numeric-owner --owner=0 --group=0 --no-recursion {} \+
181+ find $PKGNAME/ -type f -name '*.cgi' -exec tar -rf "$tmp" --mode=0755 --numeric-owner --owner=0 --group=0 --no-recursion {} \+
182+ find $PKGNAME/ -type f -not -name '*.cgi' -exec tar -rf "$tmp" --mode=0644 --numeric-owner --owner=0 --group=0 --no-recursion {} \+
183+ popd > /dev/null
184+ gzip "$tmp"
185+ mv "$tmp.gz" "$OUTDIR/"
186+ result
187+
188+ task "clean temporary directory"
189+ rm -rf "$TMPDIR"
190+ result
191+
192+ echo
193+}
194+
195+
196+####
197+
198+sample_task() {
199+ # begin task
200+ task "task name"
201+
202+ # do some task
203+ if true; then
204+ # success
205+ succ
206+ else
207+ # failure
208+ fail "error message"
209+ fi
210+
211+ # end task & show result (& exit if failed)
212+ result
213+}
214+task() {
215+ TASK="$1"
216+ STATUS=1
217+ ERRMSG="unknown error."
218+}
219+succ() {
220+ STATUS=2
221+}
222+fail() {
223+ STATUS=0
224+ ERRMSG="$1"
225+}
226+result() {
227+ if [ $STATUS -eq 0 ]; then
228+ echo "[x] $TASK"
229+ elif [ $STATUS -eq 1 ]; then
230+ echo "[+] $TASK"
231+ elif [ $STATUS -eq 2 ]; then
232+ echo "[o] $TASK"
233+ fi
234+ if [ $STATUS -eq 0 ]; then
235+ error "$ERRMSG"
236+ fi
237+}
238+error() {
239+ echo "$1"
240+ exit 1
241+}
242+debug() {
243+ : #echo "$1"
244+}
245+
246+####
247+
248+main "$@"
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Show on old repository browser