From 7439d611ea08336fe3e108c933d202a3d72d2225 Mon Sep 17 00:00:00 2001 From: Carlos Galindo Date: Thu, 4 Oct 2018 10:48:50 +0200 Subject: [PATCH] Initial commit --- README.md | 77 +++++++++++++++++++++++++++++++++++++++++++++++++ install_stow.sh | 30 +++++++++++++++++++ prepare_env.sh | 28 ++++++++++++++++++ 3 files changed, 135 insertions(+) create mode 100644 README.md create mode 100644 install_stow.sh create mode 100644 prepare_env.sh diff --git a/README.md b/README.md new file mode 100644 index 0000000..a936dd6 --- /dev/null +++ b/README.md @@ -0,0 +1,77 @@ +# Living with a temporary home + +The main problem with using virtual machines at school or work is that the home directory is sometimes made vollatile by the system administrators. Every time that you log in, all dotfiles are gone. As a solution, you can use the permanent network share or a cvs repository to store dotfiles, and `stow` to manage them and restore them in a timely manner, only needing to run one script. + +## Stow + +GNU stow can be downloaded from its [homepage](https://www.gnu.org/software/stow/), or from any of the mirrors. + +### Install stow as a user + +The best option is to download `stow-latest.tar.gz`. Then, to install it follow these steps: + +```bash +tar xf stow-latest.tar.gz +cd stow-* +./configure --prefix=$HOME/.local +make +make install +``` + +### Install stow to non-volatile storage + +Now that `stow` is installed, we can move on to move it to the user's permanent storage (identified here as `$STORAGE`): + +```bash +mkdir -p $STORAGE/stowed/stow/.local/{bin,share/{doc,info,man/man8,perl5}} + +mv $HOME/.local/bin/{stow,chkstow} $STORAGE/stowed/stow/.local/bin +mv $HOME/.local/share/doc/stow $STORAGE/stowed/stow/.local/share/doc +mv $HOME/.local/share/info/{dir,stow.info} $STORAGE/stowed/stow/.local/share/info +mv $HOME/.local/share/man/man8/stow.8 $STORAGE/stowed/stow/.local/share/man/man8 +mv $HOME/.local/share/perl5/{Stow,Stow.pm} $STORAGE/stowed/stow/.local/share/perl5 + +ln -s $STORAGE/stowed/stow/.local/bin/stow $HOME/.local/bin +ln -s $STORAGE/stowed/stow/.local/bin/chkstow $HOME/.local/bin +ln -s $STORAGE/stowed/stow/.local/share/perl5/Stow $HOME/.local/share/perl5 +ln -s $STORAGE/stowed/stow/.local/share/perl5/Stow.pm $HOME/.local/share/perl5 +``` + +Now `stow` is safely stowed away in permanent storage. All is left to do is write a small script to restore stow, such as: + +```bash +#!/bin/bash + +mkdir -p $HOME/.local/{bin,share/{doc,info,man/man8,perl5}} + +ln -s $STORAGE/stowed/stow/.local/bin/stow $HOME/.local/bin +ln -s $STORAGE/stowed/stow/.local/bin/chkstow $HOME/.local/bin +ln -s $STORAGE/stowed/stow/.local/share/perl5/Stow $HOME/.local/share/perl5 +ln -s $STORAGE/stowed/stow/.local/share/perl5/Stow.pm $HOME/.local/share/perl5 +``` + +### Using stow + +Usage of `stow` is detailed in [this article](http://brandon.invergo.net/news/2012-05-26-using-gnu-stow-to-manage-your-dotfiles.html), but the bsics are: create in a folder the tree that must be replicated, such as we have done for stow itself. An example for the bash dotfiles would look like: + +``` +bash +├── .bash_profile +└── .bashrc +``` + +It would be applied with `stow --target $HOME bash` (for the folder name, not the binary name). Some of these folders could also be imported into the cvs of your choice for easier storage and sync. + +Now it is trivially easy to restore your dotfiles: + +```bash +stow="stow --target $HOME" + +cd $STORAGE/stowed + +$stow stow +$stow bash +# And any and all others +``` + +There are examples of both scripts in the repo, one for the first time install and movement of `stow` to permanent storage and another to use once per session. diff --git a/install_stow.sh b/install_stow.sh new file mode 100644 index 0000000..efafcc0 --- /dev/null +++ b/install_stow.sh @@ -0,0 +1,30 @@ +#!/bin/bash + +if [ -z "$STORAGE" ]; then + echo "\$STORAGE is empty, please set it as a directory" + exit 1 +fi + +set -e + +# Install stow to ~/.local +curl https://ftp.gnu.org/gnu/stow/stow-latest.tar.gz | tar xz +cd stow-* +./configure --prefix=$HOME/.local +make +make install + +# Move installation to $STORAGE +mkdir -p $STORAGE/stowed/stow/.local/{bin,share/{doc,info,man/man8,perl5}} + +mv $HOME/.local/bin/{stow,chkstow} $STORAGE/stowed/stow/.local/bin +mv $HOME/.local/share/doc/stow $STORAGE/stowed/stow/.local/share/doc +mv $HOME/.local/share/info/{dir,stow.info} $STORAGE/stowed/stow/.local/share/info +mv $HOME/.local/share/man/man8/stow.8 $STORAGE/stowed/stow/.local/share/man/man8 +mv $HOME/.local/share/perl5/{Stow,Stow.pm} $STORAGE/stowed/stow/.local/share/perl5 + +ln -s $STORAGE/stowed/stow/.local/bin/stow $HOME/.local/bin +ln -s $STORAGE/stowed/stow/.local/bin/chkstow $HOME/.local/bin +ln -s $STORAGE/stowed/stow/.local/share/perl5/Stow $HOME/.local/share/perl5 +ln -s $STORAGE/stowed/stow/.local/share/perl5/Stow.pm $HOME/.local/share/perl5 + diff --git a/prepare_env.sh b/prepare_env.sh new file mode 100644 index 0000000..ed37a4f --- /dev/null +++ b/prepare_env.sh @@ -0,0 +1,28 @@ + +if [ -z "$STORAGE" ]; then + echo "\$STORAGE is empty, please set it as a directory" + exit 1 +fi + +set -e + +# Prepare stow (perl libs and binary) - if necessary +if [ ! -f "$(which stow)" ]; then + mkdir -p $HOME/.local/{bin,share/{doc,info,man/man8,perl5}} + + ln -s $STORAGE/stowed/stow/.local/bin/stow $HOME/.local/bin + ln -s $STORAGE/stowed/stow/.local/bin/chkstow $HOME/.local/bin + ln -s $STORAGE/stowed/stow/.local/share/perl5/Stow $HOME/.local/share/perl5 + ln -s $STORAGE/stowed/stow/.local/share/perl5/Stow.pm $HOME/.local/share/perl5 +fi + +stow="stow --target $HOME" +# Edit this folder to wherever you store dotfiles / stowed files +stow_dir=$STORAGE/stowed + +# Restore stowed config +cd $stow_dir + +# Copy this example, changing the folder to be restored +# $stow bash +