I want backup some config file in a git repo inside my home; earlier I've been using
work-tree=/ but i don't like this solution anymore.
Now I'm trying to create a script that take a given config file, copy it inside my backup repo, add it to git, and do a commit. My attempt is:
cp --parents $1 /home/myuser/config-BU/ chown myuser "/home/myuser/config-BU/$1" #exit sudo su myuser git --git-dir=/home/myuser/config-BU/.git/ --work-tree=/home/myuser/ add "/home/myuser/config-BU/$1" git --git-dir=/home/myuser/config-BU/.git/ --work-tree=/home/myuser/ commit -am "adding file inside BU autom" -m "$(realpath $1)"
I call it with:
sudo -u myuser -E bash "/home/myuser/cp2bu.sh /etc/apt/sources.list"
and got this:
error: XDG_RUNTIME_DIR is invalid or not set in the environment. [Line 1096] Unable to connect to the compositor. If your compositor is running, check or set the WAYLAND_DISPLAY environment variable. + Termine 253 swayidle -w timeout 300 'swaylock -f -c 000000' timeout 600 'swaymsg "output * dpms off"' resume 'swaymsg "output * dpms on"' before-sleep 'swaylock -f -c 000000'
So the big question is: How "exit" sudo after I copied config file? Or how can I re-arrange script to avoid this problem?
Should I use
But even using the above solution (with sudo bash -c "/home/myuser/cp2bu.sh /etc/apt/sources.list") I don't have the files added into git repo,and don't see the commit in git log.