/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

  • Committer: Tim Marston
  • Date: 2016-04-10 20:21:38 UTC
  • Revision ID: tim@ed.am-20160410202138-px3vd3r14889njtn
removed symlink previously committed

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/bin/bash
 
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 "Can't determine current state: no ~/.stdhome"
 
9
        exit 1
 
10
fi
 
11
 
 
12
# current state
 
13
CURRENT=
 
14
if [ -d ~/.stdhome.orig -a ! -d ~/.stdhome.dev ]; then
 
15
        CURRENT=on
 
16
elif [ ! -d ~/.stdhome.orig ]; then
 
17
        CURRENT=off
 
18
fi
 
19
if [ -z "$CURRENT" ]; then
 
20
        echo "Can't determine current state" >&2
 
21
        exit 1
 
22
fi
 
23
 
 
24
# target
 
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
 
 
34
        # already on?
 
35
        if [ "$CURRENT" == "on" ]; then
 
36
                echo already on >& 2
 
37
                exit 0
 
38
        fi
 
39
        echo turning on
 
40
 
 
41
        # create/check rc
 
42
        if [ ! -f ~/.stdhomerc ]; then
 
43
                echo "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 "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
        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
 
 
66
elif [ "$TARGET" == "off" ]; then
 
67
 
 
68
        # already off?
 
69
        if [ "$CURRENT" == "off" ]; then
 
70
                echo already off >& 2
 
71
                exit 0
 
72
        fi
 
73
        echo turning off
 
74
 
 
75
        # check rc
 
76
        if ! grep -q '^home-dir ?= ?~/tmp/stdhome-dev' ~/.stdhomerc; then
 
77
                echo "No uncommented home-dir in ~/.stdhomerc"
 
78
                exit 1
 
79
        fi
 
80
 
 
81
        # turn off
 
82
        mv ~/.stdhome{,.dev}
 
83
        mv ~/.stdhome{.orig,}
 
84
        sed -ie 's/^home-dir/#\0/' ~/.stdhomerc
 
85
 
 
86
else
 
87
        echo currently $CURRENT
 
88
fi