File: make-klone-project

package info (click to toggle)
webserver-package 0.3
  • links: PTS
  • area: main
  • in suites: bullseye, buster, jessie, jessie-kfreebsd, lenny, sid, squeeze, stretch, wheezy
  • size: 104 kB
  • ctags: 14
  • sloc: sh: 321; makefile: 27
file content (181 lines) | stat: -rwxr-xr-x 3,706 bytes parent folder | download
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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
#! /bin/sh
# Copyright 2006 Kari Pahula <kaol@debian.org>
# License GNU GPL version 2 or, at your option, later, as published
# by Free Software Foundation.

save_opts () {
    echo "$BINARYNAME" > debian/wsp.opt.binary
    echo "$MAINTAINER" > debian/wsp.opt.maintainer
}

check_dir () {
    until [ -e debian/wsp.opt.maintainer ] ; do
	if [ "`pwd`" = / ] || [ -z $ACTIVE_CHECKDIR ] ; then
	    echo "make-klone-package: not in project directory" >&2
	    exit 1
	fi
	cd ..
    done
}

seed_debian () {
    mkdir -p debian/
    for TEMPLATE in `cd /usr/share/webserver-package/klone/debian; ls`; do
	if [ ! -e debian/$TEMPLATE ] ; then
	    if [ -x /usr/share/webserver-package/klone/debian/$TEMPLATE ] ; then
		/usr/share/webserver-package/klone/debian/$TEMPLATE > debian/$TEMPLATE
	    else
		cp /usr/share/webserver-package/klone/debian/$TEMPLATE debian
	    fi
	fi
    done
    chmod +x debian/rules
}

clean_debian () {
    find debian -mindepth 1 -maxdepth 1 ! -name "*changelog" ! -name "*copyright" ! -wholename "debian/wsp.*" -exec rm -rf '{}' \;
}

seed_source () {
    ln -s . klone-source
    if [ -e webapp ] ; then EXCLUDE_WEBAPP="--exclude=*webapp/*" ; fi
    tar xf /usr/src/klone-source.tar.bz2 --bzip2 $EXCLUDE_WEBAPP
    rm klone-source
}

clean_source () {
    find . -mindepth 1 -maxdepth 1 ! -wholename "./debian" ! -wholename "./webapp" ! -wholename "./userdata" ! -wholename "./patches" -exec rm -rf '{}' \;
}

default_packagename () {
    if [ -z "$PACKAGE" ] ; then
	PACKAGE=customkloneapp
    fi
}

default_binaryname () {
    if [ -z "$BINARYNAME" ] ; then
	BINARYNAME=$PACKAGE
    fi
}

guess_package () {
    PACKAGE_GUESS="`pwd | grep -Eo '[^/]*-[0-9]' | grep -Eo '[^-0-9]*'`"
}

usage () {
    cat >&2 <<EOF
make-klone-project {create|refresh|clean} [options]
create creates a new project directory
refresh injects the newest KLone source in the project directory
clean removes the klone source and leaves the user files in the project dir

  -b NAME	Name the generated klone binary as NAME.  By default it is
		the same as the package name.
  -l		Search for the project root directory from parent directories
  -m NAME	Set the maintainer name as NAME.
  -p NAME	Name the generated package as NAME.  By default
		"customkloneapp".
EOF
}

export WSPVER=0.3
ACTIVE_CHECKDIR=""

if [ -e debian/wsp.opt.maintainer ] ; then
    MAINTAINER="`cat debian/wsp.opt.maintainer`"
fi

if [ -e debian/wsp.opt.binary ] ; then
    BINARYNAME="`cat debian/wsp.opt.binary`"
fi

OPTS=`getopt -o b:lm:p:r:u: -n make-klone-project -- "$@"`

if [ $? != 0 ] ; then
    usage
    exit 1
fi

eval set -- "$OPTS"

while :; do
    case "$1" in
	-b)
	BINARYNAME="$2"
	shift 2
	;;
	-l)
	ACTIVE_CHECKDIR="1"
	shift
	;;
	-m)
	MAINTAINER="$2"
	shift 2
	;;
	-p)
	PACKAGE="$2"
	shift 2
	;;
	--)
	shift
	COMMAND="$1"
	break
	;;
	*)
	echo "make-klone-project: internal error" >&2
	exit 1
	;;
    esac
done

set -e

if [ -z "$MAINTAINER" ] ; then
    MAINTAINER="Undefined Maintainer <not@set.invalid>"
fi

export PACKAGE BINARYNAME MAINTAINER

case "$COMMAND" in
    create)
    default_packagename
    default_binaryname
    mkdir "$PACKAGE-0.1"
    cd "$PACKAGE-0.1"
    seed_source
    seed_debian
    save_opts
    exit 0
    ;;

    clean)
    check_dir
    clean_source
    clean_debian
    save_opts
    exit 0
    ;;

    refresh)
    check_dir
    guess_package || true
    if [ -z "$PACKAGE" ] ; then
	PACKAGE="$PACKAGE_GUESS"
	if [ -z "$PACKAGE" ] ; then
	    echo "make-klone-project: failed to deduce package name" >&2
	    exit 1
	fi
    fi
    default_binaryname
    clean_source
    clean_debian
    seed_source
    seed_debian
    save_opts
    exit 0
    ;;
    *)
    usage
    exit 1
esac