You are not logged in.

#1 2009-05-21 03:50:01

MTsoul
Member
From: Vancouver, BC
Registered: 2008-08-14
Posts: 95
Website

Trying to write a script to deploy configs

I recently saw in some thread that somebody had the brilliant idea of keeping all configs in ~/configs, and ln -s files from the home directory to ~/configs. I decided to do this, but to ease the migration and future maintenance issues, I'd like a script to update all these links.

So I want a bash script to loop through each file in ~/configs, and link it from ~/, so that ~/.vimrc points to ~/configs/.vimrc. The thing is, I am complete crap at bash, and all I came up with is:

for file in `find . -regextype posix-extended -not -regex '\./\.git|\./\.git/.*|\.'`; do cd && ln -s "`pwd`/configs/$file" "$file" && cd -; done

(The reason for all the git stuff is cause I'm storing all my configs in git and I don't want to copy the git repo to my home dir.)

and that doesn't work for directories, and it doesn't remove existing links. A little help pretty please? smile

Last edited by MTsoul (2009-05-21 03:50:35)

Offline

#2 2009-05-21 04:29:27

peets
Member
From: Montreal
Registered: 2007-01-11
Posts: 936
Website

Re: Trying to write a script to deploy configs

I did this in bash, but I'm not too sure it's what you want. It skips anything called '.git', links to the rest. I read the "Pathname Expansion" of the bash manpage.

shopt -s extglob
cd ~/configs
for file in !(.git); do ln -s configs/"$file" ~; done

Offline

#3 2009-05-21 05:49:53

MTsoul
Member
From: Vancouver, BC
Registered: 2008-08-14
Posts: 95
Website

Re: Trying to write a script to deploy configs

hey that's awesome! exactly what i wanted, but it doesn't seem to find any dotfiles. sad

Is it also possible to exclude the script itself? If that script was called deploy.sh, i wouldn't want ~/deploy.sh -> ~/configs/deploy.sh...

Thanks!

Last edited by MTsoul (2009-05-21 05:53:15)

Offline

#4 2009-05-21 06:08:23

MTsoul
Member
From: Vancouver, BC
Registered: 2008-08-14
Posts: 95
Website

Re: Trying to write a script to deploy configs

Well okaay I kind of got this:

shopt -s dotglob
cd ~/configs
for file in *; do
    if [ "$file" != ".git" -a "$file" != "deploy" ]; then 
        ln -s configs/"$file" ~
    fi
done

Ugly though.

Offline

#5 2009-05-21 12:52:26

Daenyth
Forum Fellow
From: Boston, MA
Registered: 2008-02-24
Posts: 1,244

Re: Trying to write a script to deploy configs

If you have your configs in git, why not host it (either yourself or github) and then git clone to the new machine. I use a second branch for a machine where I have to modify the configs.

Here's my configs

Offline

#6 2009-05-21 15:46:55

MTsoul
Member
From: Vancouver, BC
Registered: 2008-08-14
Posts: 95
Website

Re: Trying to write a script to deploy configs

I do smile I just want a central location of all my configs so I know which ones to keep in my repo.

Actually I'm curious, how do people keep their .msmtprc (sendmail) and other account configs with passwords? Daenyth, you don't have any in yours, so you'll need to recreate those configs each clone, and manually handle updates. On the other hand, I have a private server, but I'm not too keen on putting my passwords in their either...

Offline

#7 2009-05-21 15:49:27

Daenyth
Forum Fellow
From: Boston, MA
Registered: 2008-02-24
Posts: 1,244

Re: Trying to write a script to deploy configs

I don't store any files with passwords in my version control, but my configs change very infrequently with those, so it's not a big deal

Offline

Board footer

Powered by FluxBB