Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can I use this to track system level files? #63

Closed
achembarpu opened this issue May 7, 2017 · 17 comments
Closed

Can I use this to track system level files? #63

achembarpu opened this issue May 7, 2017 · 17 comments
Assignees

Comments

@achembarpu
Copy link

achembarpu commented May 7, 2017

Hi,

I want to be able to track system level files, like /etc/pacman.conf .
How does yadm manage permissions and ownership of such files?

Thanks!

@TheLocehiliosan
Copy link
Owner

Managing files outside of your home directory isn't really within the standard use-case for yadm.

yadm only manages files within the configured worktree ($HOME by default). Also, yadm will use the effective user for file ownership just like Git.

However, if you wanted to bend yadm into managing system files, I could see doing something like this:

# create an alias to run yadm for system files
alias sysyadm="sudo yadm -Y /etc/yadm"

# initialize the yadm repo using the worktree of "/"
sysyadm init -w /

# continue to use sysyadm for managing system files
sysyadm add /etc/pacman.conf

sysyadm commit -m 'Add pacman.conf'

Assuming you have sudo rights, the sysyadm alias will work as if root was using yadm, having the owner be "root", with the ability to manage any file under /. If you were only interested in managing files under /etc, you could use that as the worktree instead. In the example above, the yadm configuration would be stored in /etc/yadm/config and the repo in /etc/yadm/repo.git.

@achembarpu
Copy link
Author

Thanks! That answers my query. 👍

@void-m4110c
Copy link

void-m4110c commented Aug 2, 2019

This should definitely go into the documentation. Who stores only his user dotfiles and not the system-wide ones?

@TheLocehiliosan
Copy link
Owner

This isn’t a use I would particularly endorse, as there are generally other configuration management tools for system level configurations; Ansible, Puppet, etc.

However, I have found myself using yadm to manage configs on my routers. 😬

I’ll reopen this issue, and add a version of it to the website so it is easier for others to find.

@void-m4110c
Copy link

I see your point. Still I think, more information can not harm ;-)
Thanks for your fast reply and your great project!

@TheLocehiliosan TheLocehiliosan added this to To do in Website Changes via automation Nov 16, 2019
@TheLocehiliosan TheLocehiliosan moved this from To do to In progress in Website Changes Dec 6, 2019
@TheLocehiliosan
Copy link
Owner

TheLocehiliosan commented Dec 8, 2019

This has been added to the FAQ.

Website Changes automation moved this from In progress to Done Dec 8, 2019
@eyadsibai
Copy link

when I tried to clone to a new machine with sysyadm ... it did not replace the files .

@eyadsibai
Copy link

it cloned the repo, but didn't put the files where they suppose to be.

@TheLocehiliosan
Copy link
Owner

@eyadsibai What clone command did you use? Did you specify the -w option to set the worktree (during the clone)?

@eyadsibai
Copy link

eyadsibai commented Apr 11, 2020

nope, just sysyadm clone repo_link

@TheLocehiliosan
Copy link
Owner

@eyadsibai - OK, Can you try using -w / with the clone command? I guess when I put this info into the FAQ, I mention that with the init command, but no mention of doing that for the clone command.

I'm going to re-open this issue, and have the FAQ updated.

Website Changes automation moved this from Done to In progress Apr 11, 2020
@eyadsibai
Copy link

it works now thanks!

@shadowrylander
Copy link

shadowrylander commented Apr 28, 2020

Quick note: I had an issue where the user settings, i.e. the email and username, weren't being detected by the root version, even after setting them for just the repo and globally, and thus, I couldn't commit anything. However, I solved it by using sysyadm -C / commit -m [...]; is this the proper way to solve this? In addition, should we therefore set the command sysyadm command to sudo yadm -Y /etc/yadm -C /? It would not work for the init subcommand, but the others should work just fine!

@TheLocehiliosan TheLocehiliosan moved this from In progress to Done in Website Changes Jun 30, 2020
@xeruf
Copy link

xeruf commented Oct 14, 2021

For anyone curious about permissions and stuff - I had the issue that, when using sudo, I would have had to duplicate my ssh keys to the root user.
So I created a little function that enables pushing and pulling via the local user (and allows specifying an "unignore" file):

alias sysyadm="yadm --yadm-dir /etc/yadm --yadm-data /etc/yadm"
alias sysinit="sysyadm init -b main -w /; sysyadm gitconfig include.path '$XDG_CONFIG_HOME/git/config'"
sy() {
  unignore="/etc/yadm/unignore"
  test -r "$unignore" && cat "$unignore" | envsubst | sysyadm add --intent-to-add --pathspec-from-file=-
  case "$1" in
    ("") sysyadm status;;
    (p) sysyadm push;;
    (l) sysyadm fetch && sy rebase main --onto origin/main;;
    (*) sudo -E $(alias sysyadm | cut -d\' -f2) "$@";;
  esac
  sudo chown -R $USER /etc/yadm
}

@rizzini
Copy link

rizzini commented Oct 16, 2021

Managing files outside of your home directory isn't really within the standard use-case for yadm.

yadm only manages files within the configured worktree ($HOME by default). Also, yadm will use the effective user for file ownership just like Git.

However, if you wanted to bend yadm into managing system files, I could see doing something like this:

# create an alias to run yadm for system files
alias sysyadm="sudo yadm -Y /etc/yadm"

# initialize the yadm repo using the worktree of "/"
sysyadm init -w /

# continue to use sysyadm for managing system files
sysyadm add /etc/pacman.conf

sysyadm commit -m 'Add pacman.conf'

Assuming you have sudo rights, the sysyadm alias will work as if root was using yadm, having the owner be "root", with the ability to manage any file under /. If you were only interested in managing files under /etc, you could use that as the worktree instead. In the example above, the yadm configuration would be stored in /etc/yadm/config and the repo in /etc/yadm/repo.git.

That solution works just fine. No permission issues here. I just can't encrypt anything, otherwise, I can't boot. I didn't troubleshoot why yet, so I dropped encryption for now. Here's the repository for my system dotfiles -> https://github.com/rizzini/Dotfiles.system

@Animeshz
Copy link

Btw, another way I use #407 (comment)

Another way I'm using is to use a simple script syncfiles and call that with a file/folder (incl relative path too), it'll create a absolute path structure and keep the file there at ~/.config/yadm/files. Later on at bootstrapping step we can just rsync -avP it to /.

The only thing missing is that we've to keep track if the file is changed by ourselves there's no git status.

If anybody like to automate the manually copying and directory structure hassle...

@mwoz123
Copy link

mwoz123 commented Apr 15, 2022

official FAQ method didn't work for me:

marcin@pc:/$ alias sysyadm="sudo yadm --yadm-dir /etc/yadm --yadm-data /etc/yadm/data"
marcin@pc:/$ sysyadm init -w /
ERROR: Git repo does not exist. did you forget to run 'init' or 'clone'?

neither

marcin@pc:/$ sysyadm init -b main -w /; sysyadm gitconfig include.path '$XDG_CONFIG_HOME/git/config'
ERROR: Git repo does not exist. did you forget to run 'init' or 'clone'?
ERROR: Git repo does not exist. did you forget to run 'init' or 'clone'?

this helped:

marcin@pc:/$ alias sysyadm="sudo yadm -Y /etc/yadm"
marcin@pc:/$ sysyadm init -w /
Initialized empty shared Git repository in /etc/yadm/repo.git/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Development

No branches or pull requests

9 participants