#!/bin/bash # # Metadot: a dotfile management system. # # Copyright (C) 2013 Silvio Rhatto - rhatto at riseup.net # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published # by the Free Software Foundation, either version 3 of the License, # or any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . # # Set real home folder if [ ! -z "$PREFIX" ]; then if [ ! -d "$PREFIX" ]; then echo "Destination folder not found: $PREFIX" else DEST="$PREFIX" fi else DEST="$HOME" fi # Parameters OPT="$1" DATE="`date +%Y%m%d%I%M%S`" BASENAME="`basename $0`" DOT="$DEST/.dotfiles" MODULES="$DOT/modules" BACKUPS="$DEST/.backups/$DATE" DEFAULT="git://git.sarava.org/rhatto/dotfiles.git" # Backup a file function metadot_backup { local file="$DEST/$1" if [ -e "$file" ] || [ -h "$file" ]; then local folder="$BACKUPS/`dirname $1`" #echo "Backing up `basename $1`..." mkdir -p $folder mv $file $folder fi } # Find contents of a module function metadot_find { local module="$1" ( cd $MODULES/$module && find -name '*.link' -or -name '*.dot.link' ) | grep -v '.git/modules' | sed -e 's|./||' } # Load a module function metadot_load { local module="$1" local destname local dirname if [ -d "$MODULES/$module" ]; then echo "Loading module $module..." for file in `metadot_find $module`; do echo "Processing $file..." # Get the dirname, replacing string.dot with .string dirname="`echo $file | sed -e 's|\([^/]*\).dot/|.\1/|g'`" dirname="`dirname $dirname`" if echo $file | grep -q '.dot.link'; then destname=".`basename $file .dot.link`" else destname="`basename $file .link`" fi if [ "$dirname" != "." ]; then #echo "Creating $DEST/$dirname..." mkdir -p $DEST/$dirname else dirname="" fi metadot_backup "$dirname/$destname" #echo "Installing symlink $dirname/$destname..." ln -s $MODULES/$module/$file $DEST/$dirname/$destname done else echo "No such module $module" fi } # Parsing. if [ -z "$OPT" ]; then echo "usage: $BASENAME