diff options
author | Daniel Friesel <derf@derf.homelinux.org> | 2010-03-27 19:43:25 +0100 |
---|---|---|
committer | Daniel Friesel <derf@derf.homelinux.org> | 2010-03-27 19:43:25 +0100 |
commit | 06e95a7635c559a631515683a9dbfaeee8cda0c7 (patch) | |
tree | 7f2e6490d382e59e1b72202629a3150438542491 | |
parent | 5eab75f69c3a816489e0ee3bbd60e0b53d833bb3 (diff) |
Treat etc/ special: automatically "install" the dotfiles in it
-rwxr-xr-x | bin/checklinks | 29 | ||||
-rwxr-xr-x | bin/ct | 37 | ||||
-rw-r--r-- | man/5/caretaker.conf.pod | 4 | ||||
-rw-r--r-- | man/7/caretaker-setup.pod | 1 | ||||
-rw-r--r-- | man/7/caretaker.pod | 14 |
5 files changed, 58 insertions, 27 deletions
diff --git a/bin/checklinks b/bin/checklinks index 358b3e1..af0357c 100755 --- a/bin/checklinks +++ b/bin/checklinks @@ -14,6 +14,7 @@ my $remove = 0; my %substitute; my $linkfile; my $exit = 0; +my $ct_auto = 0; sub mkdirs { @@ -146,12 +147,15 @@ sub loop_links { my $dir; my $cwd = cwd(); - if (-e 'etc') { + if (-d 'etc') { $dir = 'etc'; } - else { + elsif (!$ct_auto) { $dir = '.'; } + else { + return; + } foreach my $entry (dir_content($dir)) { my $source = $entry; @@ -166,9 +170,18 @@ sub loop_links { check_symlink($source, "$cwd/$dir/$entry"); } } + return; } +GetOptions( + 'ct-auto' => \$ct_auto, + 'm|msglevel=i' => \$msglevel, + 'p|parameter=s' => \%substitute, + 'q|quiet' => sub {$msglevel = 1}, + 'r|remove' => \$remove, +); + if (-f '.links') { $linkfile = '.links'; } @@ -176,16 +189,12 @@ elsif (-f 'links') { $linkfile = 'links'; } else { + if ($ct_auto) { + loop_links(); + } exit(0); } -GetOptions( - 'm|msglevel=i' => \$msglevel, - 'p|parameter=s' => \%substitute, - 'q|quiet' => sub {$msglevel = 1}, - 'r|remove' => \$remove, -); - open(my $links, '<', $linkfile) or die("Can't open $linkfile: $!"); while (my $line = <$links>) { chomp($line); @@ -199,7 +208,7 @@ while (my $line = <$links>) { next unless ($type ~~ ['soft', 'hard', 'auto']); if ($type eq 'auto') { - loop_links($src, $dst); + loop_links(); } else { if ($remove) { @@ -56,14 +56,16 @@ if [[ -r $XDG_CONFIG_HOME/caretaker/caretaker.conf ]] { # Parse commandline options while [[ $1 == --* ]] { case $1 in - --auto-update) (( AUTOUPDATE = 1)) ;; - --no-auto-update) (( AUTOUPDATE = 0)) ;; - --coluors) (( COLOURS = 1 )) ;; - --no-colours) (( COLOURS = 0 )) ;; - --progress) (( PROGRESS = 1 )) ;; - --no-progress) (( PROGRESS = 0 )) ;; - --quiet) (( SILENT = 1 )) ;; - --no-quiiet) (( SILENT = 0 )) ;; + --auto-update) (( AUTOUPDATE = 1 )) ;; + --no-auto-update) (( AUTOUPDATE = 0 )) ;; + --coluors) (( COLOURS = 1 )) ;; + --no-colours) (( COLOURS = 0 )) ;; + --magic-etc) (( MAGIC_ETC = 1 )) ;; + --no-magic-etc) (( MAGIC_ETC = 0 )) ;; + --progress) (( PROGRESS = 1 )) ;; + --no-progress) (( PROGRESS = 0 )) ;; + --quiet) (( SILENT = 1 )) ;; + --no-quiiet) (( SILENT = 0 )) ;; --version) die "see '$0 version'\n" ;; --help) die "see '$0 help'\n" ;; @@ -96,6 +98,7 @@ if (( $#PKG_ROOTS == 0 )) { : ${AUTOUPDATE=1} : ${GIT_USE_ORIGIN=1} : ${COLOURS=1} +: ${MAGIC_ETC=1} : ${PROGRESS=1} export PKG_DIR export PKG_ROOT @@ -416,6 +419,17 @@ function priority_name { esac } +function run_checklinks { + if [[ -e links ]] { + checklinks $* $CL_OPTIONS \ + --parameter package=${${PWD#$HOME}#/##} \ + --parameter etc=${${PWD#$HOME}#/##}/etc + } elif [[ -d etc && $MAGIC_ETC == 1 ]] { + checklinks --ct-auto $CL_OPTIONS $* + } +} + + function exec_hook { typeset package=$1 typeset hook=$2 @@ -444,9 +458,7 @@ function global_hook { info "$1: Running make\n" make } - checklinks $CL_OPTIONS \ - --parameter package=${${PWD#$HOME}#/##} \ - --parameter etc=${${PWD#$HOME}#/##}/etc + run_checklinks update_collected $1 update_provides $1 list_package_update $1 @@ -454,7 +466,7 @@ function global_hook { pre-remove) exec_hook $1 pre-remove genocide_collected $1 - checklinks $CL_OPTIONS --remove + run_checklinks --remove list_package_remove $1 update_provides $1 ;; @@ -740,6 +752,7 @@ function pkg_debug { echo " COLOURS $COLOURS" echo " PROGRESS $PROGRESS" echo " AUTOUPDATE $AUTOUPDATE" + echo " MAGIC_ETC $MAGIC_ETC" echo " GIT_USE_ORIGIN $GIT_USE_ORIGIN" } diff --git a/man/5/caretaker.conf.pod b/man/5/caretaker.conf.pod index 40b58fc..0e7b285 100644 --- a/man/5/caretaker.conf.pod +++ b/man/5/caretaker.conf.pod @@ -48,6 +48,10 @@ path for the local package tree Options to invoke L<checklinks>(1) with +=item B<MAGIC_ETC>=I<boolean> (--magic-etc) [1] + +Automatically run checklinks on files (or, if present, dotfiles) in F<etc/> + =item B<COLOURS>=I<boolean> (--colours) [1] Colorize the output (cyan for info messages, red for errors/warnings) diff --git a/man/7/caretaker-setup.pod b/man/7/caretaker-setup.pod index 4e64b4b..75554cd 100644 --- a/man/7/caretaker-setup.pod +++ b/man/7/caretaker-setup.pod @@ -31,7 +31,6 @@ this in the package root itself, since it's recommended to have bare git repos t Initialized empty Git repository in /tmp/vim/.git/ client /tmp/vim > mkdir etc client /tmp/vim > cp $your_fancy_vimrc etc/vimrc - client /tmp/vim > echo 'soft .vimrc $etc/vimrc' > links client /tmp/vim > git add . client /tmp/vim > git commit -m 'initial commit. Now with extra cake' [master (root-commit) 4359548] initial commit. Now with extra cake diff --git a/man/7/caretaker.pod b/man/7/caretaker.pod index 488a870..95b03ab 100644 --- a/man/7/caretaker.pod +++ b/man/7/caretaker.pod @@ -105,7 +105,13 @@ a manual will be generated out of it (see L</"COLLECTED PACKAGE FILES">) =item etc/ -Configuration files, not treated specially though +Configuration files. Unless your package contains a links file, all files in +this directory (or, if it contains dotfiles, only the dotfiles) will +automatically symlinked as dotfiles from your home using checklinks(1). +So, for example F<etc/vimrc> will be installed as F<~/.vimrc>. + +If you do not want this behaviour, create an empty links file. +To disable it for all packages, set MAGIC_ETC=0. =item hooks/ @@ -117,11 +123,11 @@ Manual files, separated by section (like man/7/caretaker.pod). Files with valid POD will be processed with pod2man, all other files which do not have a .pod suffix are assumed to be *roff source and directly put into the manual directory (with a symlink). -See also L</"COLLECTED PACKAGE FILES">. +See also L</"COLLECTED PACKAGE FILES"> =item provides/ -Files for inclusion into other packages. See L</"PROVIDES"> +Files for inclusion into other packages. See L</"PROVIDES"> =item description @@ -129,7 +135,7 @@ Package description for B<ct info> =item links -Sym- and hardlink descriptions. See checklinks(1) +Manual sym- and hardlink definitions. See checklinks(1) =item Makefile |