Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion build-deb.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
# ---------------------------------------------------------------------------
Expand All @@ -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}"
Expand Down Expand Up @@ -143,7 +153,7 @@ dpkg-deb --root-owner-group --build "${STAGING_DIR}" "${OUTPUT_DEB}"

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

# Copy ready .deb to needed place
# Copy ready .DEB to needed place
mkdir -p "${COPY_TARGET}"
cp "${OUTPUT_DEB}" "${COPY_TARGET}/"
echo "==> Copied to: ${COPY_TARGET}/${DEB_NAME}"
Expand Down
3 changes: 2 additions & 1 deletion debian/DEBIAN/control
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ Priority: optional
Maintainer: Renat Suleymanov <mail@Renat.Su>
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
55 changes: 35 additions & 20 deletions debian/DEBIAN/postinst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -97,6 +101,12 @@ case "$1" in
fi
done

if ! libsagui_available; then
echo "ERROR: libsagui shared library was not found in dynamic linker cache." >&2
echo " Install libsagui (package or from source) and run: sudo ldconfig" >&2
exit 1
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
Expand All @@ -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 <<SQL
mysql -u root <<SQL
CREATE DATABASE IF NOT EXISTS \`${DB_NAME}\` CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
CREATE USER IF NOT EXISTS '${DB_USER}'@'localhost' IDENTIFIED BY '${DB_PASS}';
GRANT ALL PRIVILEGES ON \`${DB_NAME}\`.* TO '${DB_USER}'@'localhost';
FLUSH PRIVILEGES;
SQL

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

# Write credentials to tgadmin.json
json_set \
--arg user "${DB_USER}" \
--arg pass "${DB_PASS}" \
--arg db "${DB_NAME}" \
'.AdminHelperDB.User = $user | .AdminHelperDB.Password = $pass | .AdminHelperDB.Database = $db'
# Write credentials to tgadmin.json
json_set \
--arg user "${DB_USER}" \
--arg pass "${DB_PASS}" \
--arg db "${DB_NAME}" \
'.AdminHelperDB.User = $user | .AdminHelperDB.Password = $pass | .AdminHelperDB.Database = $db'

echo "==> 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
Expand Down
51 changes: 22 additions & 29 deletions src/adminhelperd.lpi
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<AutoIncrementBuild Value="True"/>
<MinorVersionNr Value="1"/>
<RevisionNr Value="1"/>
<BuildNr Value="43"/>
<BuildNr Value="44"/>
</VersionInfo>
<BuildModes Count="4" Active="Linux">
<Item1 Name="Default" Default="True"/>
Expand Down Expand Up @@ -189,7 +189,7 @@
<MinVersion Release="10" Valid="True"/>
</Item7>
</RequiredPackages>
<Units Count="27">
<Units Count="26">
<Unit0>
<Filename Value="adminhelperd.lpr"/>
<IsPartOfProject Value="True"/>
Expand All @@ -203,70 +203,70 @@
<EditorIndex Value="-1"/>
<TopLine Value="4"/>
<CursorPos X="76" Y="10"/>
<UsageCount Value="24"/>
<UsageCount Value="21"/>
</Unit1>
<Unit2>
<Filename Value="..\brook-telegram\brooktelegramaction.pas"/>
<EditorIndex Value="-1"/>
<CursorPos X="3" Y="61"/>
<UsageCount Value="47"/>
<UsageCount Value="44"/>
</Unit2>
<Unit3>
<Filename Value="C:\lazarus-stable\ccr\brookfreepascal\brokers\Tardigrade\brooktardigradebroker.pas"/>
<UnitName Value="BrookTardigradeBroker"/>
<EditorIndex Value="-1"/>
<TopLine Value="28"/>
<CursorPos X="14" Y="41"/>
<UsageCount Value="98"/>
<UsageCount Value="95"/>
</Unit3>
<Unit4>
<Filename Value="..\HelperBots\proxyutils.pas"/>
<EditorIndex Value="-1"/>
<TopLine Value="50"/>
<CursorPos X="3" Y="101"/>
<UsageCount Value="28"/>
<UsageCount Value="25"/>
</Unit4>
<Unit5>
<Filename Value="..\taskworker\taskworker.pas"/>
<EditorIndex Value="-1"/>
<TopLine Value="24"/>
<CursorPos X="15" Y="36"/>
<UsageCount Value="52"/>
<UsageCount Value="49"/>
</Unit5>
<Unit6>
<Filename Value="..\HelperBots\actionalgebric.pas"/>
<EditorIndex Value="-1"/>
<TopLine Value="715"/>
<CursorPos X="24" Y="722"/>
<UsageCount Value="9"/>
<UsageCount Value="6"/>
</Unit6>
<Unit7>
<Filename Value="..\brook-telegram\brk_tg_config.pas"/>
<EditorIndex Value="-1"/>
<TopLine Value="103"/>
<CursorPos X="11" Y="116"/>
<UsageCount Value="82"/>
<UsageCount Value="79"/>
</Unit7>
<Unit8>
<Filename Value="..\CurrencyRates\cbrvalutes.pas"/>
<EditorIndex Value="-1"/>
<TopLine Value="208"/>
<CursorPos X="3" Y="92"/>
<UsageCount Value="19"/>
<UsageCount Value="16"/>
</Unit8>
<Unit9>
<Filename Value="..\CurrencyRates\cryptocompare.pas"/>
<EditorIndex Value="-1"/>
<TopLine Value="32"/>
<CursorPos X="3" Y="104"/>
<UsageCount Value="19"/>
<UsageCount Value="16"/>
</Unit9>
<Unit10>
<Filename Value="..\HelperBots\amanex_orm.pas"/>
<EditorIndex Value="-1"/>
<TopLine Value="70"/>
<CursorPos Y="94"/>
<UsageCount Value="4"/>
<UsageCount Value="1"/>
</Unit10>
<Unit11>
<Filename Value="adminhelper_orm.pas"/>
Expand All @@ -281,14 +281,14 @@
<Filename Value="..\HelperBots\config_loader.pas"/>
<EditorIndex Value="-1"/>
<CursorPos Y="10"/>
<UsageCount Value="150"/>
<UsageCount Value="147"/>
</Unit12>
<Unit13>
<Filename Value="actionadminhelper.pas"/>
<IsPartOfProject Value="True"/>
<IsVisibleTab Value="True"/>
<TopLine Value="259"/>
<CursorPos X="31" Y="270"/>
<CursorPos X="43" Y="275"/>
<UsageCount Value="257"/>
<Loaded Value="True"/>
</Unit13>
Expand All @@ -314,7 +314,7 @@
<EditorIndex Value="-1"/>
<TopLine Value="107"/>
<CursorPos X="43" Y="122"/>
<UsageCount Value="29"/>
<UsageCount Value="26"/>
</Unit16>
<Unit17>
<Filename Value="NaiveBayesClassifier\spamfilter.pas"/>
Expand Down Expand Up @@ -366,39 +366,32 @@
<EditorIndex Value="-1"/>
<TopLine Value="1470"/>
<CursorPos X="20" Y="1481"/>
<UsageCount Value="9"/>
<UsageCount Value="6"/>
</Unit22>
<Unit23>
<Filename Value="..\..\pascal-libs\dopf\brokers\dsqldbbroker.pas"/>
<EditorIndex Value="-1"/>
<TopLine Value="138"/>
<CursorPos X="28" Y="151"/>
<UsageCount Value="104"/>
<UsageCount Value="101"/>
</Unit23>
<Unit24>
<Filename Value="..\..\brook-telegram\use\brooktelegramaction.pas"/>
<EditorIndex Value="-1"/>
<TopLine Value="7"/>
<CursorPos X="20" Y="24"/>
<UsageCount Value="1"/>
</Unit24>
<Unit25>
<Filename Value="global.pas"/>
<IsPartOfProject Value="True"/>
<EditorIndex Value="1"/>
<TopLine Value="10"/>
<CursorPos X="11" Y="23"/>
<UsageCount Value="111"/>
<UsageCount Value="138"/>
<Loaded Value="True"/>
</Unit25>
<Unit26>
</Unit24>
<Unit25>
<Filename Value="..\..\brook-telegram\use\brk_tg_config.pas"/>
<EditorIndex Value="9"/>
<TopLine Value="240"/>
<CursorPos X="3" Y="99"/>
<UsageCount Value="56"/>
<UsageCount Value="69"/>
<Loaded Value="True"/>
</Unit26>
</Unit25>
</Units>
<OtherDefines Count="2">
<Define0 Value="UseCThreads"/>
Expand Down
Loading