Skip to content

Commit 620e1fb

Browse files
authored
Merge pull request #17 from Al-Muhandis/codex/fix-post-installation-script-for-tgadmin
Debian packaging: strip CRLF in maintainer scripts and relax libsagui dependency
2 parents 1507344 + 48960de commit 620e1fb

4 files changed

Lines changed: 70 additions & 51 deletions

File tree

build-deb.sh

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,15 @@ validate_binary() {
8383
fi
8484
}
8585

86+
normalize_maintainer_scripts() {
87+
local script
88+
for script in "${STAGING_DIR}/DEBIAN/postinst" "${STAGING_DIR}/DEBIAN/postrm"; do
89+
if [ -f "${script}" ]; then
90+
sed -i 's/\r$//' "${script}"
91+
fi
92+
done
93+
}
94+
8695
# ---------------------------------------------------------------------------
8796
# Main
8897
# ---------------------------------------------------------------------------
@@ -99,6 +108,7 @@ mkdir -p "${BUILD_DIR}"
99108

100109
# Copy staging from sources in /tmp — here chmod works correctly
101110
cp -r "${SCRIPT_DIR}/debian" "${STAGING_DIR}"
111+
normalize_maintainer_scripts
102112

103113
# Include db_schema.sql — used by postinst to initialize the database
104114
mkdir -p "${STAGING_DIR}/usr/share/${PACKAGE_NAME}"
@@ -143,7 +153,7 @@ dpkg-deb --root-owner-group --build "${STAGING_DIR}" "${OUTPUT_DEB}"
143153

144154
echo "==> Package built: ${OUTPUT_DEB}"
145155

146-
# Copy ready .deb to needed place
156+
# Copy ready .DEB to needed place
147157
mkdir -p "${COPY_TARGET}"
148158
cp "${OUTPUT_DEB}" "${COPY_TARGET}/"
149159
echo "==> Copied to: ${COPY_TARGET}/${DEB_NAME}"

debian/DEBIAN/control

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ Priority: optional
33
Maintainer: Renat Suleymanov <mail@Renat.Su>
44
Architecture: amd64
55
Section: utils
6-
Depends: dash, libc6 (>= 2.2.5), libsagui2 | libsagui
6+
Depends: dash, libc6 (>= 2.2.5)
7+
Recommends: libsagui2 | libsagui
78
Origin: https://github.com/al-Muhandis/AdminHelper
89
Description: Telegram admin helper
910
Telegram bot service for groups' moderation

debian/DEBIAN/postinst

Lines changed: 35 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ mysql_available() {
1515
command -v mysql &>/dev/null && mysqladmin ping --silent 2>/dev/null
1616
}
1717

18+
libsagui_available() {
19+
command -v ldconfig &>/dev/null && ldconfig -p 2>/dev/null | grep -q 'libsagui\.so'
20+
}
21+
1822
# Read current value from JSON (return empty string if null or missing)
1923
json_get() {
2024
jq -r "$1 // empty" "${CONFIG_FILE}" 2>/dev/null || true
@@ -97,6 +101,12 @@ case "$1" in
97101
fi
98102
done
99103

104+
if ! libsagui_available; then
105+
echo "ERROR: libsagui shared library was not found in dynamic linker cache." >&2
106+
echo " Install libsagui (package or from source) and run: sudo ldconfig" >&2
107+
exit 1
108+
fi
109+
100110
if [ ! -f "${CONFIG_FILE}" ]; then
101111
echo "ERROR: config file not found: ${CONFIG_FILE}" >&2
102112
echo " Place tgadmin.json into /etc/tgadmin/ before installing." >&2
@@ -111,37 +121,42 @@ case "$1" in
111121
# Data base
112122
# ----------------------------------------------------------------
113123
if mysql_available; then
114-
# Take password from config if set (package update)
115-
EXISTING_PASS="$(json_get '.AdminHelperDB.Password')"
124+
if mysql -u root -e "SELECT 1" >/dev/null 2>&1; then
125+
# Take password from config if set (package update)
126+
EXISTING_PASS="$(json_get '.AdminHelperDB.Password')"
116127

117-
if [ -z "${EXISTING_PASS}" ]; then
118-
DB_PASS="$(openssl rand -base64 16 | tr -d '/+=' | head -c 20)"
119-
echo "==> Generated new database password."
120-
else
121-
DB_PASS="${EXISTING_PASS}"
122-
echo "==> Using existing database password from config."
123-
fi
128+
if [ -z "${EXISTING_PASS}" ]; then
129+
DB_PASS="$(openssl rand -base64 16 | tr -d '/+=' | head -c 20)"
130+
echo "==> Generated new database password."
131+
else
132+
DB_PASS="${EXISTING_PASS}"
133+
echo "==> Using existing database password from config."
134+
fi
124135

125-
echo "==> Configuring MySQL/MariaDB for ${DB_NAME}..."
136+
echo "==> Configuring MySQL/MariaDB for ${DB_NAME}..."
126137

127-
mysql -u root <<SQL
138+
mysql -u root <<SQL
128139
CREATE DATABASE IF NOT EXISTS \`${DB_NAME}\` CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
129140
CREATE USER IF NOT EXISTS '${DB_USER}'@'localhost' IDENTIFIED BY '${DB_PASS}';
130141
GRANT ALL PRIVILEGES ON \`${DB_NAME}\`.* TO '${DB_USER}'@'localhost';
131142
FLUSH PRIVILEGES;
132143
SQL
133144

134-
# Rolling out the scheme (IF NOT EXISTS — safe when updating)
135-
mysql -u root "${DB_NAME}" < "${SCHEMA_FILE}"
145+
# Rolling out the scheme (IF NOT EXISTS — safe when updating)
146+
mysql -u root "${DB_NAME}" < "${SCHEMA_FILE}"
136147

137-
# Write credentials to tgadmin.json
138-
json_set \
139-
--arg user "${DB_USER}" \
140-
--arg pass "${DB_PASS}" \
141-
--arg db "${DB_NAME}" \
142-
'.AdminHelperDB.User = $user | .AdminHelperDB.Password = $pass | .AdminHelperDB.Database = $db'
148+
# Write credentials to tgadmin.json
149+
json_set \
150+
--arg user "${DB_USER}" \
151+
--arg pass "${DB_PASS}" \
152+
--arg db "${DB_NAME}" \
153+
'.AdminHelperDB.User = $user | .AdminHelperDB.Password = $pass | .AdminHelperDB.Database = $db'
143154

144-
echo "==> Database configured. Credentials saved to ${CONFIG_FILE}"
155+
echo "==> Database configured. Credentials saved to ${CONFIG_FILE}"
156+
else
157+
echo "WARNING: MySQL/MariaDB is running, but root access without password is denied." >&2
158+
echo " Database bootstrap skipped. Configure DB manually and rerun: sudo dpkg-reconfigure ${PACKAGE_NAME}" >&2
159+
fi
145160
else
146161
echo "WARNING: MySQL/MariaDB not found or not running." >&2
147162
echo " Install it, then run: sudo dpkg-reconfigure ${PACKAGE_NAME}" >&2

src/adminhelperd.lpi

Lines changed: 22 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
<AutoIncrementBuild Value="True"/>
2424
<MinorVersionNr Value="1"/>
2525
<RevisionNr Value="1"/>
26-
<BuildNr Value="43"/>
26+
<BuildNr Value="44"/>
2727
</VersionInfo>
2828
<BuildModes Count="4" Active="Linux">
2929
<Item1 Name="Default" Default="True"/>
@@ -189,7 +189,7 @@
189189
<MinVersion Release="10" Valid="True"/>
190190
</Item7>
191191
</RequiredPackages>
192-
<Units Count="27">
192+
<Units Count="26">
193193
<Unit0>
194194
<Filename Value="adminhelperd.lpr"/>
195195
<IsPartOfProject Value="True"/>
@@ -203,70 +203,70 @@
203203
<EditorIndex Value="-1"/>
204204
<TopLine Value="4"/>
205205
<CursorPos X="76" Y="10"/>
206-
<UsageCount Value="24"/>
206+
<UsageCount Value="21"/>
207207
</Unit1>
208208
<Unit2>
209209
<Filename Value="..\brook-telegram\brooktelegramaction.pas"/>
210210
<EditorIndex Value="-1"/>
211211
<CursorPos X="3" Y="61"/>
212-
<UsageCount Value="47"/>
212+
<UsageCount Value="44"/>
213213
</Unit2>
214214
<Unit3>
215215
<Filename Value="C:\lazarus-stable\ccr\brookfreepascal\brokers\Tardigrade\brooktardigradebroker.pas"/>
216216
<UnitName Value="BrookTardigradeBroker"/>
217217
<EditorIndex Value="-1"/>
218218
<TopLine Value="28"/>
219219
<CursorPos X="14" Y="41"/>
220-
<UsageCount Value="98"/>
220+
<UsageCount Value="95"/>
221221
</Unit3>
222222
<Unit4>
223223
<Filename Value="..\HelperBots\proxyutils.pas"/>
224224
<EditorIndex Value="-1"/>
225225
<TopLine Value="50"/>
226226
<CursorPos X="3" Y="101"/>
227-
<UsageCount Value="28"/>
227+
<UsageCount Value="25"/>
228228
</Unit4>
229229
<Unit5>
230230
<Filename Value="..\taskworker\taskworker.pas"/>
231231
<EditorIndex Value="-1"/>
232232
<TopLine Value="24"/>
233233
<CursorPos X="15" Y="36"/>
234-
<UsageCount Value="52"/>
234+
<UsageCount Value="49"/>
235235
</Unit5>
236236
<Unit6>
237237
<Filename Value="..\HelperBots\actionalgebric.pas"/>
238238
<EditorIndex Value="-1"/>
239239
<TopLine Value="715"/>
240240
<CursorPos X="24" Y="722"/>
241-
<UsageCount Value="9"/>
241+
<UsageCount Value="6"/>
242242
</Unit6>
243243
<Unit7>
244244
<Filename Value="..\brook-telegram\brk_tg_config.pas"/>
245245
<EditorIndex Value="-1"/>
246246
<TopLine Value="103"/>
247247
<CursorPos X="11" Y="116"/>
248-
<UsageCount Value="82"/>
248+
<UsageCount Value="79"/>
249249
</Unit7>
250250
<Unit8>
251251
<Filename Value="..\CurrencyRates\cbrvalutes.pas"/>
252252
<EditorIndex Value="-1"/>
253253
<TopLine Value="208"/>
254254
<CursorPos X="3" Y="92"/>
255-
<UsageCount Value="19"/>
255+
<UsageCount Value="16"/>
256256
</Unit8>
257257
<Unit9>
258258
<Filename Value="..\CurrencyRates\cryptocompare.pas"/>
259259
<EditorIndex Value="-1"/>
260260
<TopLine Value="32"/>
261261
<CursorPos X="3" Y="104"/>
262-
<UsageCount Value="19"/>
262+
<UsageCount Value="16"/>
263263
</Unit9>
264264
<Unit10>
265265
<Filename Value="..\HelperBots\amanex_orm.pas"/>
266266
<EditorIndex Value="-1"/>
267267
<TopLine Value="70"/>
268268
<CursorPos Y="94"/>
269-
<UsageCount Value="4"/>
269+
<UsageCount Value="1"/>
270270
</Unit10>
271271
<Unit11>
272272
<Filename Value="adminhelper_orm.pas"/>
@@ -281,14 +281,14 @@
281281
<Filename Value="..\HelperBots\config_loader.pas"/>
282282
<EditorIndex Value="-1"/>
283283
<CursorPos Y="10"/>
284-
<UsageCount Value="150"/>
284+
<UsageCount Value="147"/>
285285
</Unit12>
286286
<Unit13>
287287
<Filename Value="actionadminhelper.pas"/>
288288
<IsPartOfProject Value="True"/>
289289
<IsVisibleTab Value="True"/>
290290
<TopLine Value="259"/>
291-
<CursorPos X="31" Y="270"/>
291+
<CursorPos X="43" Y="275"/>
292292
<UsageCount Value="257"/>
293293
<Loaded Value="True"/>
294294
</Unit13>
@@ -314,7 +314,7 @@
314314
<EditorIndex Value="-1"/>
315315
<TopLine Value="107"/>
316316
<CursorPos X="43" Y="122"/>
317-
<UsageCount Value="29"/>
317+
<UsageCount Value="26"/>
318318
</Unit16>
319319
<Unit17>
320320
<Filename Value="NaiveBayesClassifier\spamfilter.pas"/>
@@ -366,39 +366,32 @@
366366
<EditorIndex Value="-1"/>
367367
<TopLine Value="1470"/>
368368
<CursorPos X="20" Y="1481"/>
369-
<UsageCount Value="9"/>
369+
<UsageCount Value="6"/>
370370
</Unit22>
371371
<Unit23>
372372
<Filename Value="..\..\pascal-libs\dopf\brokers\dsqldbbroker.pas"/>
373373
<EditorIndex Value="-1"/>
374374
<TopLine Value="138"/>
375375
<CursorPos X="28" Y="151"/>
376-
<UsageCount Value="104"/>
376+
<UsageCount Value="101"/>
377377
</Unit23>
378378
<Unit24>
379-
<Filename Value="..\..\brook-telegram\use\brooktelegramaction.pas"/>
380-
<EditorIndex Value="-1"/>
381-
<TopLine Value="7"/>
382-
<CursorPos X="20" Y="24"/>
383-
<UsageCount Value="1"/>
384-
</Unit24>
385-
<Unit25>
386379
<Filename Value="global.pas"/>
387380
<IsPartOfProject Value="True"/>
388381
<EditorIndex Value="1"/>
389382
<TopLine Value="10"/>
390383
<CursorPos X="11" Y="23"/>
391-
<UsageCount Value="111"/>
384+
<UsageCount Value="138"/>
392385
<Loaded Value="True"/>
393-
</Unit25>
394-
<Unit26>
386+
</Unit24>
387+
<Unit25>
395388
<Filename Value="..\..\brook-telegram\use\brk_tg_config.pas"/>
396389
<EditorIndex Value="9"/>
397390
<TopLine Value="240"/>
398391
<CursorPos X="3" Y="99"/>
399-
<UsageCount Value="56"/>
392+
<UsageCount Value="69"/>
400393
<Loaded Value="True"/>
401-
</Unit26>
394+
</Unit25>
402395
</Units>
403396
<OtherDefines Count="2">
404397
<Define0 Value="UseCThreads"/>

0 commit comments

Comments
 (0)