mirror of
https://github.com/anten-ka/gotelegram_pro.git
synced 2026-05-19 17:56:07 +00:00
v2.5.0: add legacy state migration
This commit is contained in:
@@ -184,6 +184,72 @@ get_config_value() {
|
||||
esac
|
||||
}
|
||||
|
||||
get_telemt_users_block() {
|
||||
local config="${1:-$TELEMT_CONFIG}"
|
||||
[ -f "$config" ] || return 1
|
||||
awk '
|
||||
/^\[access\.users\]/ { in_users=1; next }
|
||||
/^\[/ && in_users { exit }
|
||||
in_users && /^[[:space:]]*[^#[:space:]][^=]*=/ { print }
|
||||
' "$config"
|
||||
}
|
||||
|
||||
first_telemt_user_secret() {
|
||||
local config="${1:-$TELEMT_CONFIG}"
|
||||
get_telemt_users_block "$config" | head -1 | sed 's/^[^=]*=[[:space:]]*//; s/^"//; s/".*$//' | tr -d ' '
|
||||
}
|
||||
|
||||
replace_telemt_users_block() {
|
||||
local users_block="$1"
|
||||
local config="${2:-$TELEMT_CONFIG}"
|
||||
[ -f "$config" ] || return 1
|
||||
[ -n "$users_block" ] || return 0
|
||||
|
||||
local tmp
|
||||
tmp=$(mktemp) || return 1
|
||||
awk -v users="$users_block" '
|
||||
BEGIN { split(users, lines, "\n") }
|
||||
/^\[access\.users\]/ {
|
||||
found=1
|
||||
print
|
||||
for (i = 1; i in lines; i++) {
|
||||
if (lines[i] != "") print lines[i]
|
||||
}
|
||||
in_users=1
|
||||
next
|
||||
}
|
||||
/^\[/ && in_users { in_users=0 }
|
||||
in_users { next }
|
||||
{ print }
|
||||
END {
|
||||
if (!found) {
|
||||
print ""
|
||||
print "[access.users]"
|
||||
for (i = 1; i in lines; i++) {
|
||||
if (lines[i] != "") print lines[i]
|
||||
}
|
||||
}
|
||||
}
|
||||
' "$config" > "$tmp" && mv "$tmp" "$config"
|
||||
chmod 600 "$config"
|
||||
}
|
||||
|
||||
toml_bool_value() {
|
||||
local table="$1"
|
||||
local key="$2"
|
||||
local config="${3:-$TELEMT_CONFIG}"
|
||||
awk -v table="$table" -v key="$key" '
|
||||
$0 == "[" table "]" { in_table=1; next }
|
||||
/^\[/ && in_table { exit }
|
||||
in_table && $1 == key {
|
||||
sub(/^[^=]*=[[:space:]]*/, "")
|
||||
gsub(/[[:space:]]/, "")
|
||||
print
|
||||
exit
|
||||
}
|
||||
' "$config"
|
||||
}
|
||||
|
||||
# ── Валидация конфига ────────────────────────────────────────────────────────
|
||||
validate_telemt_config() {
|
||||
local config="${1:-$TELEMT_CONFIG}"
|
||||
|
||||
Reference in New Issue
Block a user