d92089c6269c95c0f6a9bcf46ba28e71916a4b28
[dotfiles-framework.git] / disconnect.sh
1 #!/bin/bash
2 #
3 # You're about to give your sysadmin account to some newbie, and
4 # they'd just be confused by all this efficiency.  This script freezes
5 # your dotfiles in their current state and makes everthing look
6 # normal.  Note that this will delete your ~/.dotfiles directory, and
7 # strip the .dotfiles portion from your ~/.bashrc file.
8
9 # For each file in this directory.
10 for file in _*; do
11     # Create .dotfile version.
12     dotfile=.${file/_/}
13     
14     # Replace symlinks with their target
15     if [ -h ~/$dotfile ]; then
16         echo -n ""
17         #rm -f ~/$dotfile
18         #mv $file ~/$dotfile
19     fi
20 done
21
22 # See if the bashrc file is involved with .dotfiles at all
23 if [ ! -e _bashrc ]; then
24     # No _bashrc file, so leave ~/.bashrc alone
25     exit
26 fi
27
28 # We may have a dotfiles section in ~/.bashrc.  Strip it out.
29 BC="### ---- begin .dotfiles section ---- (keep this magic comment)"
30 EC="### ---- end .dotfiles section ---- (keep this magic comment)"
31 AWKSCRIPT="BEGIN{copy=1}{"
32 AWKSCRIPT="$AWKSCRIPT if(\$0 == \"$BC\"){copy=0};"
33 AWKSCRIPT="$AWKSCRIPT if(\$0 == \"$EC\"){copy=1};"
34 AWKSCRIPT="$AWKSCRIPT if(copy==1 && \$0 != \"$EC\"){print \$0}"
35 AWKSCRIPT="$AWKSCRIPT}"
36
37 awk "$AWKSCRIPT" ~/.bashrc > bashrc_stripped
38 # see if the stripped file is any different
39 DIFF=`diff ~/.bashrc bashrc_stripped` || exit 1
40 if [ -n "$DIFF" ]
41
42 rm -f ~/.bashrc
43 cp bashrc_stripped ~/.bashrc