0

I have a scenario where I have a git repository that I do a git pull every x minutes, in the following dir: /opt/repo/

In this repository I have some directories like:

  • /opt/repo/dir1
  • /opt/repo/dir2
  • /opt/repo/dir3

that are created on the repo dinamycally and retrieved in every git pull.

What I need to do is, after every git pull, create a symlink for those directories (only the new ones) on another path:

/var/www/themes/

Manually, what I do is the following:

$ cd /var/www/themes
$ ln -s /opt/repo/dir1 . 
$ ln -s /opt/repo/dir2 . 
$ ln -s /opt/repo/dir3 . 

Is there a way to do that in every call? I don't want to recreate the existing symlinks, just create for the ones that doesn't exist yet.

====

SYN solution works, I just had to invert -maxdepth and type order (I was running it over Ubuntu 16 it that matters).

1
  • have you looked at commit hooks?
    – SYN
    Commented Oct 14, 2017 at 13:15

1 Answer 1

0

In your repository root, you would have a .git subdir. In there, you should be able to install a post-update hook:

$ cd /opt/repo
$ test -d .git/hooks || mkdir .git/hooks
$ cat <<EOF >.git/hooks/post-update
#!/bin/sh

cd /opt/repo
find . -maxdepth 1 -type d | while read dir
    do
        test "$dir" = .git && continue
        test -e "/var/www/themes/$dir" && continue
        ln -sf "/opt/repo/$dir" /var/www/themes
    done
EOF
$ chmod +x .git/hooks/post-update

This assuming the user pulling from git also has permissions to create those links, ...

5
  • Thanks, it seems the right way! But I get this: find: warning: you have specified the -maxdepth option after a non-option argument -type, but options are not positional (-maxdepth affects tests specified before it as well as those specified after it). Please specify options before other arguments.
    – Tzn
    Commented Oct 14, 2017 at 14:36
  • I've updated my code with the debug. Thanks for your help!
    – Tzn
    Commented Oct 14, 2017 at 14:38
  • Aparently if you invert the -maxdepth and type, it works! Thanks again, accepting answer, but if you could "fix" it. Maybe it's related to Ubuntu syntax somehow. Weird, right? :-)
    – Tzn
    Commented Oct 14, 2017 at 14:46
  • Weird though, I'm positive setting type then maxdepth works (GNU findutils, debian 8).
    – SYN
    Commented Oct 15, 2017 at 3:40
  • I know Syn, didn't expect that as well (that's why I didn't try to invert its order at first... but well, you know how things work in IT: Murphy's law apply all the time! )
    – Tzn
    Commented Oct 15, 2017 at 12:53

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .