/stdhome

To get this branch, use:
bzr branch http://bzr.ed.am/stdhome

« back to all changes in this revision

Viewing changes to tools/dev-environment

  • Committer: Tim Marston
  • Date: 2016-04-10 17:42:36 UTC
  • Revision ID: tim@ed.am-20160410174236-708ckdxils6m2ndv
added tools

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#!/bin/bash
2
2
 
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
8
 
        echo "ERROR: can't determine current state: no ~/.stdhome"
9
 
        exit 1
10
 
fi
11
 
 
12
 
# current state
13
3
CURRENT=
14
4
if [ -d ~/.stdhome.orig -a ! -d ~/.stdhome.dev ]; then
15
5
        CURRENT=on
16
 
elif [ ! -d ~/.stdhome.orig ]; then
 
6
elif [ ! -d ~/.stdhome.orig -a -d ~/.stdhome.dev ]; then
17
7
        CURRENT=off
18
8
fi
 
9
 
19
10
if [ -z "$CURRENT" ]; then
20
 
        echo "ERROR: can't determine current state" >&2
 
11
        echo "Can't determine current state" >&2
21
12
        exit 1
22
13
fi
23
14
 
24
 
# target
25
15
TARGET=
26
16
if [ "$1" == "on" ]; then
27
17
        TARGET=on
31
21
 
32
22
if [ "$TARGET" == "on" ]; then
33
23
 
34
 
        # already on?
35
24
        if [ "$CURRENT" == "on" ]; then
36
25
                echo already on >& 2
37
26
                exit 0
38
27
        fi
39
28
        echo turning on
40
29
 
41
 
        # create/check rc
42
 
        if [ ! -f ~/.stdhomerc ]; then
43
 
                echo "ERROR: no ~/.stdhomerc, creating..."
44
 
                echo "[stdhome]" >> ~/.stdhomerc
45
 
                echo "#home-dir = ~/tmp/stdhome-dev" >> ~/.stdhomerc
46
 
                mkdir -p ~/tmp/stdhome-dev
47
 
        fi
48
 
        if ! grep -q '^#home-dir \?= \?~/tmp/stdhome-dev' ~/.stdhomerc; then
49
 
                echo "ERROR: no commented home-dir in ~/.stdhomerc"
50
 
                echo "Please add the following to the [stdhome] section:"
51
 
                echo "#home-dir = ~/tmp/stdhome-dev"
52
 
                exit 1
53
 
        fi
54
 
 
55
 
        # turn on
56
30
        mv ~/.stdhome{,.orig}
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
64
 
        mkdir -p ~/tmp/stdhome-dev
65
 
        DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )"/.. && pwd )"
66
 
        ln -s "$DIR"/src/stdhome ~/bin/stdhome
 
31
        mv ~/.stdhome{.dev,}
 
32
        sed -ie 's/^#\(home-dir\)/\1/' ~/.stdhomerc
67
33
 
68
34
elif [ "$TARGET" == "off" ]; then
69
35
 
70
 
        # already off?
71
36
        if [ "$CURRENT" == "off" ]; then
72
37
                echo already off >& 2
73
38
                exit 0
74
39
        fi
75
40
        echo turning off
76
41
 
77
 
        # check rc
78
 
        if ! grep -q '^home-dir \?= \?~/tmp/stdhome-dev' ~/.stdhomerc; then
79
 
                echo "ERROR: no uncommented home-dir in ~/.stdhomerc"
80
 
                exit 1
81
 
        fi
82
 
 
83
 
        # turn off
84
42
        mv ~/.stdhome{,.dev}
85
43
        mv ~/.stdhome{.orig,}
86
44
        sed -ie 's/^home-dir/#\0/' ~/.stdhomerc
87
 
        rm -f ~/bin/stdhome
88
45
 
89
46
else
90
47
        echo currently $CURRENT