1
0
Fork 0
mirror of https://github.com/SinTan1729/random.git synced 2024-12-25 20:58:37 -06:00
random/OneDriveBk

26 lines
901 B
Bash

#!/bin/sh
# For backing up files with OneDrive
# Assumes that the backup target is set up as OneDrive in rclone
if [ $(id -u) -eq 0 ]; then
exec sudo -H -u sintan $0 "$@"
fi
notify() {
#Detect the name of the display in use
local display=":$(ls /tmp/.X11-unix/* | sed 's#/tmp/.X11-unix/X##' | head -n 1)"
#Detect the user using such display
local user=$(who | grep '('$display')' | awk '{print $1}' | head -n 1)
#Detect the id of the user
local uid=$(id -u $user)
sudo -u $user DISPLAY=$display DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/$uid/bus notify-send -a rclone -h string:desktop-entry:alacritty "$@"
}
notify "OneDriveBk" "Backup started..."
flock -n /tmp/onedrivesync.lock rclone sync -c -L --log-file="/home/sintan/TempStorage/OneDriveBk.log" --log-level INFO "/home/sintan/TempStorage/OneDrive/" OneDrive:Backup
notify "OneDriveBk" "Backup finished!"