-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate-deb-pkg.sh
executable file
·174 lines (138 loc) · 3.75 KB
/
generate-deb-pkg.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
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
#!/bin/sh
usage() {
cat <<EOF
Usage: $0 <control-file>
Creates a debian package from a specially crafted debian control file. See
README.org for details.
EOF
exit 1
}
deinit() {
rm -fr $TMPDIR
}
die() { echo "Error: $@"; exit 1; }
# Generate include clauses inside the xkb configuration
generate_include() {
for inc; do
echo " include \"$inc\""
done
}
# Parse headings of control-formatted file
parse_heading() {
sed -n -e "/^$1:/{s/^[^:]*: //; p}" < "$CTRLFILE"
}
generate_files_block() {
local files=$(parse_heading XKL-files)
}
# Generate the default layout block of the xkb configuration
generate_layout_block() {
local name="$(parse_heading XKL-name)"
local includes="$(parse_heading XKL-layouts)"
cat <<EOF
default partial alphanumeric_keys
xkb_symbols "$PKGNAME" {
name[Group1]="$name";
EOF
generate_include $includes
echo "};"
}
install_layout() {
test -f "$SYMBOLSFILE" -a -r "$SYMBOLSFILE" || \
die "Symbols file $SYMBOLSFILE not readable."
BASECTRLFILE=$(basename "$CTRLFILE")
OUTSYMBOLSFILE=usr/share/X11/xkb/symbols/$BASECTRLFILE
OUTRULESFILE=usr/share/X11/xkb/rules/evdev.xml.d/$BASECTRLFILE.xml
LAYOUT=$(generate_layout_block)
(
set -e
cd $TMPDIR
mkdir -p $(dirname "$OUTSYMBOLSFILE") $(dirname "$OUTRULESFILE")
cat <<EOF > $OUTSYMBOLSFILE
// Generated with $CMDLINE
// URL: https://github.com/kopoli/keyboard
// Version: $VERSION
EOF
cat <<EOF > $OUTRULESFILE
<!-- Generator: $CMDLINE
Version: $VERSION
Package: $PKGNAME
-->
EOF
# The following might need a second expansion
SHORTDESC=$(parse_heading XKL-shortDescription)
DESC=$(parse_heading XKL-name)
LANGID=$(parse_heading XKL-langiso639Id)
export OUTSYMBOLSFILE PKGNAME OUTRULESFILE SHORTDESC DESC LANGID
/bin/sh -c "
cat <<EOF >> $OUTSYMBOLSFILE
// The main layout
$LAYOUT
// Layout data:
EOF
cat <<EOF >> $OUTRULESFILE
<layout>
<configItem>
<name>$BASECTRLFILE</name>
<shortDescription>$SHORTDESC</shortDescription>
<description>$DESC</description>
<languageList>
<iso639Id>$LANGID</iso639Id>
</languageList>
</configItem>
<variantList/>
</layout>
<!-- End package $PKGNAME -->
EOF
"
# Copy the XKL-data to the end of the layout file
sed -n -e '/IGNORE-FOLLOWING-XKL-DATA/q; p' < $SYMBOLSFILE >> $OUTSYMBOLSFILE
)
PACKAGE_HAS_CONTENTS=t
}
install_files() {
FILEDIR=${CTRLFILE}-files
for file in $INSTALLFILES; do
fname=${file%%|*}
dname=${file##*|}
install -D ${FILEDIR}/$fname $TMPDIR/$dname/$fname || \
die "Copying file $fname to package failed."
done
PACKAGE_HAS_CONTENTS=t
}
create_package() {
(
set -e
cd $TMPDIR
mkdir -p DEBIAN
export CURDIR TMPDIR PKGNAME CMDLINE VERSION
fakeroot /bin/sh -ec "
cd $TMPDIR
cat <<EOF > DEBIAN/control
$(sed -e '/^XKL/d' < $CTRLFILE)
EOF
chown -R root.root *
cd $CURDIR
dpkg-deb -b $TMPDIR .
"
) || die "Creating the package failed."
}
# main script
CTRLFILE=$1
CURDIR=$PWD
TMPDIR=$(mktemp -d)
trap deinit INT TERM EXIT
test -z "$CTRLFILE" && usage
if ! test -f "$CTRLFILE"; then
die "The control file is required for generating a package."
fi
CTRLFILE=$(readlink -f "$CTRLFILE")
PKGNAME=$(basename "$CTRLFILE")
test -f "$CTRLFILE" || die "$CTRLFILE must be a file."
SYMBOLSFILE=$CURDIR/$(parse_heading "XKL-data")
INSTALLFILES=$(parse_heading "XKL-files")
CMDLINE="$0 $@"
VERSION=$(git describe --always)
PACKAGE_HAS_CONTENTS=
test -f "$SYMBOLSFILE" && install_layout
test -n "$INSTALLFILES" && install_files
test -n "$PACKAGE_HAS_CONTENTS" && create_package