Initial commit

This commit is contained in:
Carlos Galindo 2018-10-04 10:48:50 +02:00
commit 7439d611ea
Signed by: kauron
GPG key ID: 83E68706DEE119A3
3 changed files with 135 additions and 0 deletions

77
README.md Normal file
View file

@ -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.

30
install_stow.sh Normal file
View file

@ -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

28
prepare_env.sh Normal file
View file

@ -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