/stdhome

To get this branch, use:
bzr branch http://bzr.ed.am/stdhome
68 by Tim Marston
added tools
1
#!/bin/bash
2
69 by Tim Marston
fixed-up tools
3
# fix up home dir
4
if [ ! -d ~/.stdhome -a ! -d ~/.stdhome.dev -a ! -d ~/.stdhome.orig ]; then
5
	mkdir ~/.stdhome
6
fi
7
if [ ! -d ~/.stdhome ]; then
75 by Tim Marston
fixed greps in tools/dev to detect home-dir lines in stdhomerc
8
	echo "ERROR: can't determine current state: no ~/.stdhome"
69 by Tim Marston
fixed-up tools
9
	exit 1
10
fi
11
12
# current state
68 by Tim Marston
added tools
13
CURRENT=
14
if [ -d ~/.stdhome.orig -a ! -d ~/.stdhome.dev ]; then
15
	CURRENT=on
69 by Tim Marston
fixed-up tools
16
elif [ ! -d ~/.stdhome.orig ]; then
68 by Tim Marston
added tools
17
	CURRENT=off
18
fi
19
if [ -z "$CURRENT" ]; then
75 by Tim Marston
fixed greps in tools/dev to detect home-dir lines in stdhomerc
20
	echo "ERROR: can't determine current state" >&2
68 by Tim Marston
added tools
21
	exit 1
22
fi
23
69 by Tim Marston
fixed-up tools
24
# target
68 by Tim Marston
added tools
25
TARGET=
26
if [ "$1" == "on" ]; then
27
	TARGET=on
28
elif [ "$1" == "off" ]; then
29
	TARGET=off
30
fi
31
32
if [ "$TARGET" == "on" ]; then
33
69 by Tim Marston
fixed-up tools
34
	# already on?
68 by Tim Marston
added tools
35
	if [ "$CURRENT" == "on" ]; then
36
		echo already on >& 2
37
		exit 0
38
	fi
39
	echo turning on
40
69 by Tim Marston
fixed-up tools
41
	# create/check rc
42
	if [ ! -f ~/.stdhomerc ]; then
75 by Tim Marston
fixed greps in tools/dev to detect home-dir lines in stdhomerc
43
		echo "ERROR: no ~/.stdhomerc, creating..."
69 by Tim Marston
fixed-up tools
44
		echo "[stdhome]" >> ~/.stdhomerc
70 by Tim Marston
fixed tools to use ~/tmp/stdhome-dev as dev home-dir
45
		echo "#home-dir = ~/tmp/stdhome-dev" >> ~/.stdhomerc
46
		mkdir -p ~/tmp/stdhome-dev
69 by Tim Marston
fixed-up tools
47
	fi
75 by Tim Marston
fixed greps in tools/dev to detect home-dir lines in stdhomerc
48
	if ! grep -q '^#home-dir \?= \?~/tmp/stdhome-dev' ~/.stdhomerc; then
49
		echo "ERROR: no commented home-dir in ~/.stdhomerc"
69 by Tim Marston
fixed-up tools
50
		echo "Please add the following to the [stdhome] section:"
70 by Tim Marston
fixed tools to use ~/tmp/stdhome-dev as dev home-dir
51
		echo "#home-dir = ~/tmp/stdhome-dev"
69 by Tim Marston
fixed-up tools
52
		exit 1
53
	fi
54
55
	# turn on
68 by Tim Marston
added tools
56
	mv ~/.stdhome{,.orig}
69 by Tim Marston
fixed-up tools
57
	if [ -d ~/.stdhome.dev ]; then
58
		mv ~/.stdhome{.dev,}
59
	else
60
		mkdir ~/.stdhome
61
		echo new dev environment, use stdhome init
62
	fi
63
 	sed -ie 's/^#\(home-dir\)/\1/' ~/.stdhomerc
70 by Tim Marston
fixed tools to use ~/tmp/stdhome-dev as dev home-dir
64
	mkdir -p ~/tmp/stdhome-dev
80 by Tim Marston
add symlink in ~/bin to dev version in dev script
65
	DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )"/.. && pwd )"
66
	ln -s "$DIR"/src/stdhome ~/bin/stdhome
68 by Tim Marston
added tools
67
68
elif [ "$TARGET" == "off" ]; then
69
69 by Tim Marston
fixed-up tools
70
	# already off?
68 by Tim Marston
added tools
71
	if [ "$CURRENT" == "off" ]; then
72
		echo already off >& 2
73
		exit 0
74
	fi
75
	echo turning off
76
69 by Tim Marston
fixed-up tools
77
	# check rc
75 by Tim Marston
fixed greps in tools/dev to detect home-dir lines in stdhomerc
78
	if ! grep -q '^home-dir \?= \?~/tmp/stdhome-dev' ~/.stdhomerc; then
79
		echo "ERROR: no uncommented home-dir in ~/.stdhomerc"
69 by Tim Marston
fixed-up tools
80
		exit 1
81
	fi
82
83
	# turn off
68 by Tim Marston
added tools
84
	mv ~/.stdhome{,.dev}
85
	mv ~/.stdhome{.orig,}
86
	sed -ie 's/^home-dir/#\0/' ~/.stdhomerc
80 by Tim Marston
add symlink in ~/bin to dev version in dev script
87
	rm -f ~/bin/stdhome
68 by Tim Marston
added tools
88
89
else
90
	echo currently $CURRENT
91
fi