-
Notifications
You must be signed in to change notification settings - Fork 5
/
make-zpkg
executable file
·133 lines (105 loc) · 4.04 KB
/
make-zpkg
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
#!/bin/bash
# This script creates a ZPKG file from a definition script.
error() { echo >&2 "$@"; exit 1; }
set -e
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
usage()
{
cat <<EOF
Usage: make-zpkg [options] package.list <version>
Options can be any of:
-b: System build path, used for b options in list file.
-t: Source top path, used for t options in list file.
-d: Destination directory
The above three options default to the current directory if not
specified.
-w: Workspace for building package. Defaults to temporary directory if not
specified.
-n: Package name. If not specified the name is extracted from the
package.list filename.
-a: Filename will have __at__ in instead of @ character
-h Show this help text
The package.list file specifies all of the files that will be placed in the
generated zpkg. Each line consists of three fields:
option target source
The target specifies the location in the zpkg where the file will be installed,
while the option and source together specify where the file comes from,
according to the following options:
d target directory is created, source is ignored
t source is relative to the directory specified by -t
T source is relative to the directory specified by -t, entire directory
tree is copied
b source is relative to the directory specified by -b
B source is relative to the directory specified by -b, entire directory
tree is copied
r same as B, for backwards compatibility
l source is a soft link path, a soft link is created in target
EOF
exit 0
}
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Argument processing.
# Path to build directory, used for b options, defaults to current directory
BUILD_DIR="$PWD"
# Top directory, used for t options, defaults to current directory
TOP_DIR="$PWD"
# Work directory for building intermedate files, will default to temporary dir
WORK_DIR=
# Destination directory for result, defaults to current directory
DEST_DIR="$PWD"
# Package name, by default is computed from file list name
PKG_NAME=
# Separator for output zpkg filename, defaults to @ character
SEP=@
while getopts 'b:t:w:d:n:ah' option; do
case "$option" in
b) BUILD_DIR="$OPTARG" ;;
t) TOP_DIR="$OPTARG" ;;
w) WORK_DIR="$OPTARG" ;;
d) DEST_DIR="$OPTARG" ;;
n) PKG_NAME="$OPTARG" ;;
a) SEP="__at__" ;;
h) usage ;;
*) error 'Invalid option: try -h for help' ;;
esac
done
shift $((OPTIND-1))
(( $# == 2 )) || error 'Missing arguments: try -h for help'
FILE_LIST="$1"
VERSION="$2"
[ -r "$FILE_LIST" ] || error 'Package definition file not found'
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Now sort out the defaults.
# If no workspace specified, use a temporary directory.
if [[ -z $WORK_DIR ]]; then
WORK_DIR="$(mktemp -d)"
trap 'rm -rf "$WORK_DIR"' EXIT
fi
# If no package name specified, extract it from the FILE_LIST name.
if [[ -z $PKG_NAME ]]; then
PKG_NAME="$(basename "$FILE_LIST")"
PKG_NAME="${PKG_NAME%.list}"
fi
# Ensure our workspace is clean
ZPKG_DIR="$WORK_DIR/zpkg-$PKG_NAME"
rm -rf "$ZPKG_DIR"
# Configure final package to build
ZPKG="$DEST_DIR/$PKG_NAME$SEP$VERSION.zpg"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Assemble all the components as required and build target package.
# Process the file list
while read action target source; do
[ -z "$action" ] ||
case $action in
\#) ;;
d) mkdir -p "$ZPKG_DIR"/$target ;;
t) cp "$TOP_DIR"/$source "$ZPKG_DIR"/$target ;;
T) cp -a "$TOP_DIR"/$source "$ZPKG_DIR"/$target ;;
b) cp "$BUILD_DIR"/$source "$ZPKG_DIR"/$target ;;
B|r) cp -a "$BUILD_DIR"/$source "$ZPKG_DIR"/$target ;;
l) ln -s $source "$ZPKG_DIR"/$target ;;
*) error Invalid action ;;
esac
done <"$FILE_LIST"
# Assemble final package
tar czf "$ZPKG" -C "$ZPKG_DIR" $(cd "$ZPKG_DIR"; echo *) --owner=0 --group=0