forked from synesthesiam/rhasspy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
debianize.sh
executable file
·177 lines (140 loc) · 4.79 KB
/
debianize.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
174
175
176
177
#!/usr/bin/env bash
rhasspy_version="2.4.10"
this_dir="$( cd "$( dirname "$0" )" && pwd )"
# -----------------------------------------------------------------------------
# Command-line Arguments
# -----------------------------------------------------------------------------
. "${this_dir}/etc/shflags"
DEFINE_string 'architecture' '' 'Debian architecture'
DEFINE_string 'version' "${rhasspy_version}" 'Package version'
DEFINE_boolean 'package' true 'Create debian package (.deb)'
FLAGS "$@" || exit $?
eval set -- "${FLAGS_ARGV}"
# -----------------------------------------------------------------------------
# Settings
# -----------------------------------------------------------------------------
export architecture="${FLAGS_architecture}"
version="${FLAGS_version}"
debian_dir="${this_dir}/debian"
set -e
if [[ -z "${architecture}" ]]; then
# Guess architecture
architecture="$(dpkg-architecture | grep 'DEB_BUILD_ARCH=' | sed 's/^[^=]\+=//')"
fi
# -----------------------------------------------------------------------------
# Activate virtual environment
# -----------------------------------------------------------------------------
venv="${this_dir}/.venv"
if [[ ! -d "${venv}" ]]; then
echo "Missing virtual environment at ${venv}"
echo "Did you run create-venv.sh?"
exit 1
fi
cd "${this_dir}"
source "${venv}/bin/activate"
if [[ -z "$(command -v pyinstaller)" ]]; then
echo "Missing PyInstaller"
exit 1
fi
# -----------------------------------------------------------------------------
# Run PyInstaller
# -----------------------------------------------------------------------------
echo "Running PyInstaller"
package_name="rhasspy-server_${version}_${architecture}"
package_dir="${debian_dir}/${package_name}"
output_dir="${package_dir}/usr/lib/rhasspy"
share_dir="${package_dir}/usr/share/rhasspy"
pyinstaller\
-y \
--workpath "pyinstaller/build" \
--distpath "${output_dir}" \
"${this_dir}/rhasspy.spec"
# Remove all symbols (Liantian warning)
strip --strip-all "${output_dir}/rhasspy"/*.so* || true
# Remove executable bit from shared libs (Lintian warning)
chmod -x "${output_dir}/rhasspy"/*.so* || true
# -----------------------------------------------------------------------------
# Copy Rhasspy
# -----------------------------------------------------------------------------
# Profiles
mkdir -p "${output_dir}/profiles"
rsync -av \
--delete \
--exclude 'acoustic_model' \
--exclude 'download' \
--exclude 'flair' \
--exclude 'base_dictionary.txt' \
--exclude 'base_language_model.txt' \
--exclude 'g2p.fst' \
--exclude 'HCLG.fst' \
--exclude 'final.mdl' \
--exclude '*.umdl' \
"${this_dir}/profiles/" \
"${output_dir}/profiles/"
# Sounds
mkdir -p "${output_dir}/etc/wav"
rsync -av \
--delete \
"${this_dir}/etc/wav/" \
"${output_dir}/etc/wav/"
# Web
mkdir -p "${output_dir}/dist"
rsync -av \
--delete \
"${this_dir}/dist/" \
"${output_dir}/dist/"
# Documentation
mkdocs build
mkdir -p "${share_dir}/docs"
rsync -av \
--delete \
"${this_dir}/site/" \
"${share_dir}/docs/"
# Source code
mkdir -p "${share_dir}/src"
rsync -av \
--delete \
--exclude '.mypy_cache' \
--exclude '__pycache__' \
"${this_dir}/rhasspy/" \
"${share_dir}/src/rhasspy/"
cp "${this_dir}/app.py" "${share_dir}/src/"
# -----------------------------------------------------------------------------
# Copy Kaldi
# -----------------------------------------------------------------------------
echo "Copying Kaldi"
kaldi_src="${this_dir}/opt/kaldi"
if [[ ! -d "${kaldi_src}" ]]; then
echo "Missing Kaldi at ${kaldi_src}"
exit 1
fi
kaldi_dest="${output_dir}/kaldi"
mkdir -p "${kaldi_dest}"
rsync -av --delete "${kaldi_src}/" "${kaldi_dest}/"
# Avoid link recursion
rm -f "${kaldi_dest}/egs/wsj/s5/utils/utils"
# Turn duplicate .so files into symbolic links
function fix_library_links {
lib_dir="$1"
for lib in "${lib_dir}"/*.so; do
lib_base="$(basename ${lib})"
for lib_link in "${lib_dir}/${lib_base}".*; do
rm -f "${lib_link}"
ln -s "${lib_base}" "${lib_link}"
done
done
}
fix_library_links "${kaldi_dest}/tools/openfst/lib"
# -----------------------------------------------------------------------------
# Create Debian package
# -----------------------------------------------------------------------------
echo "Creating Debian package"
mkdir -p "${package_dir}/DEBIAN"
cat "${debian_dir}/DEBIAN/control" | \
envsubst > "${package_dir}/DEBIAN/control"
mkdir -p "${package_dir}/usr/bin"
cp "${debian_dir}/bin/rhasspy-server" "${package_dir}/usr/bin/"
if [[ "${FLAGS_package}" -eq "${FLAGS_TRUE}" ]]; then
# Actually build the package
cd 'debian' && fakeroot dpkg --build "${package_name}"
fi