From f8c7528f2f6f0604c80add837f3ae0de72edb482 Mon Sep 17 00:00:00 2001 From: Renat Suleymanov Date: Fri, 27 Mar 2026 01:30:30 +0400 Subject: [PATCH] Make libsagui check non-fatal in postinst --- build-deb.sh | 10 ++++++++ debian/DEBIAN/control | 3 ++- debian/DEBIAN/postinst | 55 +++++++++++++++++++++++++++--------------- 3 files changed, 47 insertions(+), 21 deletions(-) diff --git a/build-deb.sh b/build-deb.sh index 6bad75b..c92390e 100755 --- a/build-deb.sh +++ b/build-deb.sh @@ -83,6 +83,15 @@ validate_binary() { fi } +normalize_maintainer_scripts() { + local script + for script in "${STAGING_DIR}/DEBIAN/postinst" "${STAGING_DIR}/DEBIAN/postrm"; do + if [ -f "${script}" ]; then + sed -i 's/\r$//' "${script}" + fi + done +} + # --------------------------------------------------------------------------- # Main # --------------------------------------------------------------------------- @@ -99,6 +108,7 @@ mkdir -p "${BUILD_DIR}" # Copy staging from sources in /tmp — here chmod works correctly cp -r "${SCRIPT_DIR}/debian" "${STAGING_DIR}" +normalize_maintainer_scripts # Include db_schema.sql — used by postinst to initialize the database mkdir -p "${STAGING_DIR}/usr/share/${PACKAGE_NAME}" diff --git a/debian/DEBIAN/control b/debian/DEBIAN/control index 1a5d7eb..59d328a 100644 --- a/debian/DEBIAN/control +++ b/debian/DEBIAN/control @@ -3,7 +3,8 @@ Priority: optional Maintainer: Renat Suleymanov Architecture: amd64 Section: utils -Depends: dash, libc6 (>= 2.2.5), libsagui2 | libsagui +Depends: dash, libc6 (>= 2.2.5) +Recommends: libsagui2 | libsagui Origin: https://github.com/al-Muhandis/AdminHelper Description: Telegram admin helper Telegram bot service for groups' moderation diff --git a/debian/DEBIAN/postinst b/debian/DEBIAN/postinst index c9ba7dc..2958204 100644 --- a/debian/DEBIAN/postinst +++ b/debian/DEBIAN/postinst @@ -15,6 +15,10 @@ mysql_available() { command -v mysql &>/dev/null && mysqladmin ping --silent 2>/dev/null } +libsagui_available() { + command -v ldconfig &>/dev/null && ldconfig -p 2>/dev/null | grep -q 'libsagui\.so' +} + # Read current value from JSON (return empty string if null or missing) json_get() { jq -r "$1 // empty" "${CONFIG_FILE}" 2>/dev/null || true @@ -97,6 +101,12 @@ case "$1" in fi done + if ! libsagui_available; then + echo "WARNING: libsagui shared library was not found in dynamic linker cache." >&2 + echo " The service may fail to start until libsagui is available to the loader." >&2 + echo " Install libsagui (package or from source) and run: sudo ldconfig" >&2 + fi + if [ ! -f "${CONFIG_FILE}" ]; then echo "ERROR: config file not found: ${CONFIG_FILE}" >&2 echo " Place tgadmin.json into /etc/tgadmin/ before installing." >&2 @@ -111,37 +121,42 @@ case "$1" in # Data base # ---------------------------------------------------------------- if mysql_available; then - # Take password from config if set (package update) - EXISTING_PASS="$(json_get '.AdminHelperDB.Password')" + if mysql -u root -e "SELECT 1" >/dev/null 2>&1; then + # Take password from config if set (package update) + EXISTING_PASS="$(json_get '.AdminHelperDB.Password')" - if [ -z "${EXISTING_PASS}" ]; then - DB_PASS="$(openssl rand -base64 16 | tr -d '/+=' | head -c 20)" - echo "==> Generated new database password." - else - DB_PASS="${EXISTING_PASS}" - echo "==> Using existing database password from config." - fi + if [ -z "${EXISTING_PASS}" ]; then + DB_PASS="$(openssl rand -base64 16 | tr -d '/+=' | head -c 20)" + echo "==> Generated new database password." + else + DB_PASS="${EXISTING_PASS}" + echo "==> Using existing database password from config." + fi - echo "==> Configuring MySQL/MariaDB for ${DB_NAME}..." + echo "==> Configuring MySQL/MariaDB for ${DB_NAME}..." - mysql -u root < Database configured. Credentials saved to ${CONFIG_FILE}" + echo "==> Database configured. Credentials saved to ${CONFIG_FILE}" + else + echo "WARNING: MySQL/MariaDB is running, but root access without password is denied." >&2 + echo " Database bootstrap skipped. Configure DB manually and rerun: sudo dpkg-reconfigure ${PACKAGE_NAME}" >&2 + fi else echo "WARNING: MySQL/MariaDB not found or not running." >&2 echo " Install it, then run: sudo dpkg-reconfigure ${PACKAGE_NAME}" >&2