Add .fluxbox/keys.
[dotfiles-framework.git] / bin / 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 if [ -z "${DOTFILES_DIR}" ]; then
10     echo 'DOTFILES_DIR is not set.  Bailing out.'
11     exit 1
12 fi
13
14 # See if we've constructed any patched source files that might be
15 # possible link targets
16 if [ ! -d "${DOTFILES_DIR}/patched-src" ]; then
17     echo 'no installed dotfiles to disconnect'
18     exit
19 fi
20
21 DOTFILES_SRC="${DOTFILES_DIR}/patched-src"
22 cd "${DOTFILES_SRC}" || exit 1
23
24 # See if the bashrc file is involved with dotfiles at all
25 if [ -e '.bashrc' ]; then
26     BASHRC='yes'
27 else
28     BASHRC='no'
29 fi
30
31 while read FILE; do
32     if [ "${FILE}" = '.' ]; then
33         continue
34     fi
35     FILE="${FILE:2}"  # strip the leading './'
36     if [ "${DOTFILES_SRC}/${FILE}" -ef ~/"${FILE}" ] && \
37         [ -h ~/"${FILE}" ]; then
38         # break simlink
39         echo "de-symlink ~/${FILE}"
40         rm -f ~/"${FILE}"
41         mv "${FILE}" ~/"${FILE}"
42     fi
43 done < <(find .)
44
45 if [ "${BASHRC}" == 'yes' ]; then
46     echo 'strip dotfiles section from ~/.bashrc'
47     sed '/DOTFILES_DIR/d' ~/.bashrc > bashrc_stripped
48
49     # see if the stripped file is any different
50     DIFF=$(diff ~/.bashrc bashrc_stripped)
51     DIFF_RC="$?"
52     if [ ${DIFF_RC} -eq 0 ]; then
53         echo "no dotfiles section found in ~/.bashrc"
54         rm -f bashrc_stripped
55     elif [ ${DIFF_RC} -eq 1 ]; then
56         echo "replace ~/.bashrc with stripped version"
57         rm -f ~/.bashrc
58         mv bashrc_stripped ~/.bashrc
59     else
60         exit 1  # diff failed, bail
61     fi
62 fi
63
64 #if [ -d "${DOTFILES_DIR}" ]; then
65 #    cd
66 #    echo "remove the dotfiles dir ${DOTFILES_DIR}"
67 #    rm -rf "${DOTFILES_DIR}"
68 #fi