diff --git a/README.org b/README.org index f3b2665..b8a1bbf 100644 --- a/README.org +++ b/README.org @@ -4,30 +4,30 @@ After trying several approaches and switching between different setups, this method finally met all of my requirements: - As simple as possible - - Multiple machines are managed in one repository - - Identical configurations for one program on several machines only need to be adjusted in one place - - Different configurations for one program on several machines are no problem + - Multiple hosts are managed in one repository + - Identical configurations for one program on several hosts only need to be adjusted in one place + - Different configurations for one program on several hosts are no problem - Set everything up with one command - Updating configurations shall require nothing more than =git pull= - This is a reference repository which contains a bash script (=dotlink=) and some example dotfiles for two machines (=host1= and =host2=). + This is a reference repository which contains a bash script (=dotlink=) and some example dotfiles for two hosts (=host1= and =host2=). *Warning*: If you want to try this make a backup of your dotfiles! The script doesn't overwrite existing files but you never know. ** Concept - The concept is based on symlinks and two directories, =common= and =machines=. + The concept is based on symlinks and two directories, =common= and =hosts=. - The =machines= directory contains subdirectories for all machines on which dotfiles are managed. - They need to match the /hostname/ of the machine (in this repository =host1= and =host2=) and mimic the corresponding =$HOME= directories. + The =hosts= directory contains subdirectories for all hosts on which dotfiles are managed. + They need to match the /hostname/ of the host (in this repository =host1= and =host2=) and mimic the corresponding =$HOME= directories. - The =common= directory contains configs which are present on multiple machines. + The =common= directory contains configs which are present on multiple hosts. It doesn't follow any specific structure, you can choose what suits your setup. Subdirectories with program names, followed by the configuration files (in this repository only =mpv=) make probably the most sense but its up to you. The =common= directory should never contain symlinks. - Symlinks from the =machines= directory to the =common= directory make the configs available on multiple machines and they can be adjusted in one place (see =mpv= in this repository). + Symlinks from the =hosts= directory to the =common= directory make the configs available on multiple hosts and they can be adjusted in one place (see =mpv= in this repository). Here is the tree output from this repository: @@ -37,7 +37,7 @@ │   └── mpv │   ├── input.conf │   └── mpv.conf - ├── machines + ├── hosts │   ├── host1 │   │   ├── .config │   │   │   └── mpv -> ../../../common/mpv/ @@ -52,17 +52,17 @@ The *mpv* configuration is shared between hosts, =host1= has an *OfflineIMAP* configuration in his home directory and =host2= has a *beets* configuration in his =.config= directory. - Every file from every =machines/= directory can then be linked to the corresponding path into the home directory of the machine. + Every file from every =hosts/= directory can then be linked to the corresponding path into the home directory of the host. This can be done by hand or with help of the =dotlink= script. If you updated a configuration somewhere else just call =git pull= and thats it. ** Script usage - When the =dotlink= script is executed, all files from the =machines/= directory, which matches the current /hostname/, are linked to their destination in the =$HOME= directory. + When the =dotlink= script is executed, all files from the =hosts/= directory, which matches the current /hostname/, are linked to their destination in the =$HOME= directory. Executing the script is only neccessary when new files were added which are not linked yet. - The script can be executed from everywhere, it is just important that it's stored next to a =machines= directory like in this repository. + The script can be executed from everywhere, it is just important that it's stored next to a =hosts= directory like in this repository. #+begin_example Usage: dotlink [OPTIONS] @@ -76,14 +76,14 @@ ** Add configuration files for only one host - Add the files to =machines//=. - If you want to keep all configuration files in the =common= directory and just use symlinks in the =machines= directory, you can follow the instructions below. + Add the files to =hosts//=. + If you want to keep all configuration files in the =common= directory and just use symlinks in the =hosts= directory, you can follow the instructions below. ** Add configuration files for multiple hosts - It is important that the links from the =machines= directory to the =common= directory are relative. - Follow these steps to add new configurations for multiple machines: + It is important that the links from the =hosts= directory to the =common= directory are relative. + Follow these steps to add new configurations for multiple hosts: 1. Add the files somewhere to the =common= directory - 2. Execute =ln -rs common/ machines//= for every machine on which the files should be present - 3. Execute the =dotlink= script on every modified machine + 2. Execute =ln -rs common/ hosts//= for every host on which the files should be present + 3. Execute the =dotlink= script on every modified host diff --git a/dotlink b/dotlink index c090a21..19e9d95 100755 --- a/dotlink +++ b/dotlink @@ -58,13 +58,13 @@ done # Get current dotfile directory for later linking dotfiles="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" -# Check if dotfiles for machine exist -if [ ! -d "$dotfiles/machines/$HOSTNAME" ]; then - error "No dotfiles for machine $text_bold$HOSTNAME$text_reset found, make sure the directory $text_bold$dotfiles/machines/$HOSTNAME$text_reset exists" +# Check if dotfiles for host exist +if [ ! -d "$dotfiles/hosts/$HOSTNAME" ]; then + error "No dotfiles for host $text_bold$HOSTNAME$text_reset found, make sure the directory $text_bold$dotfiles/hosts/$HOSTNAME$text_reset exists" fi -# Get dotfiles for current machine -cd "$dotfiles/machines/$HOSTNAME" +# Get dotfiles for current host +cd "$dotfiles/hosts/$HOSTNAME" files=( $(find -L -type f -printf '%P\n')) if [ "$unlink" == true ]; then @@ -78,7 +78,7 @@ for file in "${files[@]}"; do # Unlink files if [ "$unlink" == true ]; then - if [ -L "$HOME/$file" ] && [ "$(readlink $HOME/$file)" == "$dotfiles/machines/$HOSTNAME/$file" ]; then + if [ -L "$HOME/$file" ] && [ "$(readlink $HOME/$file)" == "$dotfiles/hosts/$HOSTNAME/$file" ]; then rm "$HOME/$file" log "Unlinked $text_bold$HOME/$file$text_reset" @@ -96,7 +96,7 @@ for file in "${files[@]}"; do # Check if target is a link if [ -L "$HOME/$file" ]; then - if [ "$(readlink $HOME/$file)" != "$dotfiles/machines/$HOSTNAME/$file" ]; then + if [ "$(readlink $HOME/$file)" != "$dotfiles/hosts/$HOSTNAME/$file" ]; then warning "$text_bold$HOME/$file$text_reset is a link but doesn't point to this repository, it will not be linked" continue fi @@ -114,7 +114,7 @@ for file in "${files[@]}"; do mkdir -p "$(dirname $HOME/$file)" # Link file - ln -s "$dotfiles/machines/$HOSTNAME/$file" "$HOME/$file" + ln -s "$dotfiles/hosts/$HOSTNAME/$file" "$HOME/$file" log "Linked $text_bold$dotfiles/$file$text_reset to $text_bold$HOME/$file$text_reset" fi fi diff --git a/machines/host1/.config/mpv b/hosts/host1/.config/mpv similarity index 100% rename from machines/host1/.config/mpv rename to hosts/host1/.config/mpv diff --git a/machines/host1/.offlineimaprc b/hosts/host1/.offlineimaprc similarity index 100% rename from machines/host1/.offlineimaprc rename to hosts/host1/.offlineimaprc diff --git a/machines/host2/.config/beets/config.yaml b/hosts/host2/.config/beets/config.yaml similarity index 100% rename from machines/host2/.config/beets/config.yaml rename to hosts/host2/.config/beets/config.yaml diff --git a/machines/host2/.config/mpv b/hosts/host2/.config/mpv similarity index 100% rename from machines/host2/.config/mpv rename to hosts/host2/.config/mpv