72 lines
1.8 KiB
Bash
72 lines
1.8 KiB
Bash
#!/bin/sh
|
|
|
|
f_perm_err(){
|
|
printf "This script has been executed as the root user.\n"
|
|
printf "Please run it as a regular user instead.\n"
|
|
exit 1
|
|
}
|
|
|
|
f_mount_storage(){
|
|
printf "Mounting $1 storage...\n"
|
|
[ ! -d $2 ] && mkdir $2
|
|
doas mount -t tmpfs -o size=256M,mode=1777 tg-$1 $2
|
|
}
|
|
|
|
f_remove_cache(){
|
|
printf "Removing unnecessary data from $1 storage...\n"
|
|
rm -r "$2/tdata/user_data/cache/"* 2>/dev/null
|
|
rm -r "$2/tdata/user_data/media_cache/"* 2>/dev/null
|
|
rm -r "$2/tdata/user_data#?/cache/"* 2>/dev/null
|
|
rm -r "$2/tdata/user_data#?/media_cache/"* 2>/dev/null
|
|
rm -r "$2/tdata/emoji/cache"* 2>/dev/null
|
|
rm -r "$2/DebugLogs/"* 2>/dev/null
|
|
}
|
|
|
|
f_copy_data(){
|
|
printf "Copying data from $1 to $2 storage...\n"
|
|
cp -r $3/* $4
|
|
}
|
|
|
|
f_rsync_data(){
|
|
printf "Copying data from $1 to $2 storage...\n"
|
|
doas rsync -a --delete $3/ $4
|
|
}
|
|
|
|
f_umount_storage(){
|
|
printf "Removing $1 storage...\n"
|
|
doas umount tg-$1
|
|
[ ! -z $2 ] && \
|
|
printf "Deleting directory...\n" && \
|
|
rm -r $2
|
|
}
|
|
|
|
# Check whether script is executed by root
|
|
[ "$(id -u)" -eq "0" ] && f_perm_err
|
|
|
|
# Environment variables
|
|
tmp="/tmp/tg-temporary"
|
|
data="/home/$USER/.local/share/TelegramDesktop"
|
|
|
|
# Reduce permissions for written files
|
|
umask 0077
|
|
|
|
# Establish the tmpfs for Telegram
|
|
f_remove_cache internal $data
|
|
f_mount_storage transitory $tmp
|
|
f_copy_data internal transitory $data $tmp
|
|
f_mount_storage temporary $data
|
|
f_copy_data transitory temporary $tmp $data
|
|
f_umount_storage transitory $tmp
|
|
|
|
# Launch Telegram application
|
|
printf "Launching Telegram...\n"
|
|
telegram-desktop #2>/dev/null
|
|
|
|
# Tear down the tmpfs for Telegram
|
|
f_remove_cache temporary $data
|
|
f_mount_storage transitory $tmp
|
|
f_copy_data temporary transitory $data $tmp
|
|
f_umount_storage temporary
|
|
f_rsync_data transitory internal $tmp $data
|
|
f_umount_storage transitory $tmp
|