Skip to content

Instantly share code, notes, and snippets.

@sadiqsalau
Last active June 12, 2025 16:55
Show Gist options
  • Save sadiqsalau/8644e414379b0a9eee8a35d527e966b4 to your computer and use it in GitHub Desktop.
Save sadiqsalau/8644e414379b0a9eee8a35d527e966b4 to your computer and use it in GitHub Desktop.
Telegram Portable Updater and Backuper
#!/usr/bin/bash
# Directory Structure
# _BACKUP
# _BASE
echo "Cleanup Previous Backup"
rm -rf _BACKUP telegram-accounts-backup.zip
echo "Setting Up Backup Directory"
mkdir _BACKUP
echo "Creating Backups..."
find . -mindepth 1 -maxdepth 1 -type d ! -name _BASE ! -name _BINARY ! -name _BACKUP \
-exec cp --parents -t _BACKUP \
{}/TelegramForcePortable/tdata/key_datas \
{}/TelegramForcePortable/tdata/D877F783D5D3EF8Cs \
{}/TelegramForcePortable/tdata/D877F783D5D3EF8C/maps \;
echo "Zipping Backup..."
zip -qr telegram-accounts-backup.zip \
_BACKUP \
_BASE \
backup.sh \
updater.sh;
import os
import glob
import sys
# Ensure current working directory is the script's own directory
script_dir = os.path.dirname(os.path.realpath(sys.argv[0]))
os.chdir(script_dir)
print("Generating Desktop Entries...")
# Get all top-level directories excluding _BASE and _BACKUP
dirs = [
d for d in glob.glob("*/")
if os.path.isdir(d) and d.rstrip("/\\") not in ["_BASE", "_BINARY", "_BACKUP"]
]
for dir_path in dirs:
dir_path = dir_path.rstrip("/\\")
work_dir = os.path.realpath(os.path.join(dir_path, "TelegramForcePortable"))
desktop_file = os.path.realpath(os.path.join(dir_path, "Telegram.desktop"))
content = f"""[Desktop Entry]
Name=Telegram
Exec=telegram-desktop -noupdate -workdir {work_dir}
Icon=telegram
Type=Application
Terminal=false
StartupWMClass=telegram-desktop
"""
with open(desktop_file, "w") as f:
f.write(content)
# Make it executable
os.chmod(desktop_file, 0o755)
print("Done.")
#!/bin/bash
echo "Generating Desktop Entries..."
find . -mindepth 1 -maxdepth 1 -type d ! -name _BASE ! -name _BINARY ! -name _BACKUP | while read -r dir; do
# Create Desktop Entry
work_dir=$(realpath "$dir/TelegramForcePortable")
desktop_file=$(realpath "$dir/Telegram.desktop")
cat > "$desktop_file" <<EOF
[Desktop Entry]
Name=Telegram
Exec=telegram-desktop -noupdate -workdir $work_dir
Icon=telegram
Type=Application
Terminal=false
StartupWMClass=telegram-desktop
EOF
chmod +x "$desktop_file"
done
import os
import glob
import shutil
import zipfile
import sys
# Ensure script is running in its own directory
script_dir = os.path.dirname(os.path.realpath(sys.argv[0]))
os.chdir(script_dir)
# Define constants
BACKUP_DIR = "_BACKUP"
BASE_DIR = "_BASE"
BINARY_DIR = "_BINARY"
ZIP_FILE = "telegram-accounts-backup.zip"
print("Cleanup Previous Backup")
# Remove previous backup
if os.path.exists(BACKUP_DIR):
shutil.rmtree(BACKUP_DIR)
if os.path.exists(ZIP_FILE):
os.remove(ZIP_FILE)
print("Setting Up Backup Directory")
os.makedirs(BACKUP_DIR, exist_ok=True)
print("Creating Backups...")
# Match all directories with TelegramForcePortable/tdata under them
tdata_dirs = glob.glob("*/TelegramForcePortable/tdata")
for tdata_path in tdata_dirs:
# Skip _BASE and _BACKUP
base_folder = tdata_path.split(os.sep)[0]
if base_folder in [BASE_DIR, BINARY_DIR, BACKUP_DIR]:
continue
targets = [
os.path.join(tdata_path, "key_datas"),
os.path.join(tdata_path, "D877F783D5D3EF8Cs"),
os.path.join(tdata_path, "D877F783D5D3EF8C", "maps")
]
for target in targets:
if os.path.exists(target):
rel_path = os.path.relpath(target, ".")
dest_path = os.path.join(BACKUP_DIR, rel_path)
os.makedirs(os.path.dirname(dest_path), exist_ok=True)
if os.path.isdir(target):
shutil.copytree(target, dest_path)
else:
shutil.copy2(target, dest_path)
print("Zipping Backup...")
def zipdir(zipf, path, arc_prefix=""):
for root, _, files in os.walk(path):
for file in files:
file_path = os.path.join(root, file)
arcname = os.path.join(arc_prefix, os.path.relpath(file_path, path))
zipf.write(file_path, arcname)
with zipfile.ZipFile(ZIP_FILE, 'w', zipfile.ZIP_DEFLATED) as zipf:
zipdir(zipf, BACKUP_DIR, "_BACKUP")
zipdir(zipf, BASE_DIR, "_BASE")
for script in ["backup.py", "updater.py"]:
if os.path.exists(script):
zipf.write(script)
print("Done.")
@echo off
set "workdir=%cd%\TelegramForcePortable"
start "Telegram Desktop" "..\_BINARY\Telegram.exe" -noupdate -workdir "%workdir%"
exit
import os
import shutil
import sys
# Ensure current working directory is the script's directory
script_dir = os.path.dirname(os.path.realpath(sys.argv[0]))
os.chdir(script_dir)
print("Copying Telegram.exe...")
# Path to the launcher executable
launcher_src = os.path.realpath(os.path.join("_BASE", "Telegram.exe"))
# Ensure the launcher exists
if not os.path.isfile(launcher_src):
print(f"Launcher not found: {launcher_src}")
sys.exit(1)
# Iterate through all top-level directories
for dir_name in os.listdir("."):
if os.path.isdir(dir_name) and dir_name not in ["_BASE", "_BINARY", "_BACKUP"]:
dest_path = os.path.join(dir_name, "Telegram.exe")
shutil.copy2(launcher_src, dest_path)
print(f"Copied to: {dest_path}")
print("Done.")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment