Added dotfiles management script

This commit is contained in:
Lexi / Zoe 2018-11-01 00:34:54 +01:00
parent 62cf7af099
commit acecc996e4
Signed by: binaryDiv
GPG key ID: F8D4956E224DA232
2 changed files with 114 additions and 0 deletions

46
createlinks.sh Normal file
View file

@ -0,0 +1,46 @@
#!/bin/bash
if [ $# -ne 2 ]; then
echo "wrong argument count"
fi
# Set variables
homedir="$1"
dotfilesdir="$2"
# Change directory to home dir
cd "$homedir"
# Define a function that create a link unless it already exists
makelink() {
test $# -eq 2 || { echo "makelink: invalid function call"; exit 1; }
if [ ! -e "$1" ]; then
echo "can't create link '$2': target '$1' does not exist"
return
fi
if [ ! -e "$2" ]; then
# Create link
ln -sr "$1" "$2"
elif [ ! -L "$2" ]; then
# A file with the same name exists and it's not a link
# -> warn user!
echo "can't create link '$2': file already exists"
fi
}
makelink_simple() {
test $# -eq 1 || { echo "makelink_simple: invalid function call"; exit 1; }
makelink "$dotfilesdir/$1" "$1"
}
# -- CREATE THE LINKS HERE --
# ~/bin
makelink "$dotfiles/bin/" bin
# dotfiles
makelink_simple .bashrc