]> git.madduck.net Git - etc/mrsetup.git/blob - mrsetup

madduck's git repository

Every one of the projects in this repository is available at the canonical URL git://git.madduck.net/madduck/pub/<projectpath> — see each project's metadata for the exact URL.

All patches and comments are welcome. Please squash your changes to logical commits before using git-format-patch and git-send-email to patches@git.madduck.net. If you'd read over the Git project's submission guidelines and adhered to them, I'd be especially grateful.

SSH access, as well as push access can be individually arranged.

If you use my repositories frequently, consider adding the following snippet to ~/.gitconfig and using the third clone URL listed for each project:

[url "git://git.madduck.net/madduck/"]
  insteadOf = madduck:

a91f8032a35bdcc383b77614ddc7a494d34de558
[etc/mrsetup.git] / mrsetup
1 #!/bin/sh
2 #
3 # mrsetup - set up an account using mr
4 #
5 # Copyright © 2008 martin f. krafft <madduck@madduck.net>
6 # Released under the terms of the Artistic Licence 2.0
7 #
8 set -eu
9
10 MY_GIT_SERVER=git.madduck.net
11 MY_GIT_REPOS='~/git'
12 MY_ACCOUNT="$(whoami)@$(hostname --fqdn)"
13 MY_ACCOUNT_GIT_REPO=${MY_GIT_REPOS}/accounts/${MY_ACCOUNT}.git
14 MY_GIT_URL_BASE=ssh://$MY_GIT_SERVER
15 MY_MR_REPO_URL=$MY_GIT_URL_BASE/$MY_GIT_REPOS/pub/etc/mr.git
16 MY_ACCOUNT_REPO_URL=$MY_GIT_URL_BASE/$MY_ACCOUNT_GIT_REPO
17 MR_REPO_URL=ssh://git.madduck.net/~/git/pub/code/mr.git
18 MR_CODE=code/mr
19 MR_FGIT=.fgits/mr.git
20 MR=.mr
21 BIN_DIR=.bin
22
23 if [ -z "${SSH_AUTH_SOCK:-}" ]; then
24   echo E: '$SSH_AUTH_SOCK' is not set. >&2
25   exit 1
26 fi
27
28 if [ ! -x "$(command -v git)" ]; then
29   echo E: git is not installed. >&2
30   exit 2
31 fi
32
33 if [ -e .mrconfig ]; then
34   echo E: .mrconfig already exists. >&2
35   exit 3
36 fi
37
38 if [ -d "$MR_FGIT" ]; then
39   echo E: "$MR_FGIT" already exists. >&2
40   exit 4
41 fi
42
43 if [ -d ".git" ]; then
44   echo E: .git already exists. >&2
45   exit 5
46 fi
47
48 if [ -d code/mr ]; then
49   if [ -x code/mr/mr ]; then
50     echo W: code/mr already exists, let us hope for the best... >&2
51   else
52     echo E: code/mr already exists. >&2
53     exit 6
54   fi
55 else
56   echo I: cloning mr into ${MR_CODE}...
57   mkdir --parent ${MR_CODE%/*}
58   git clone --no-checkout $MR_REPO_URL $MR_CODE
59   (cd $MR_CODE && git checkout -b vcsh origin/vcsh)
60   mkdir --parent $BIN_DIR
61   ln -s ../${MR_CODE}/mr $BIN_DIR/mr
62   echo
63 fi
64
65 cat <<_eof > .mrconfig
66 [DEFAULT]
67 include = cat $MR_CODE/lib/*
68
69 [$MR_FGIT]
70 checkout = git_fake_bare_checkout $MY_MR_REPO_URL ${MR_FGIT##*/} ../../
71 _eof
72 echo I: initial .mrconfig:
73 cat .mrconfig
74 echo
75
76 echo I: cloning mr configuration...
77 $MR_CODE/mr co
78 echo
79
80 echo I: bootstrapping default .mrconfig...
81 cp $MR/templ/.mrconfig .
82
83 echo I: setting up base...
84 $MR_CODE/mr co
85
86 if ssh $MY_GIT_SERVER "test -d $MY_ACCOUNT_GIT_REPO" </dev/null; then
87   echo I: checking out local git repository...
88   dir="$(mktemp -d home.XXXXXXXX)"
89   trap "rm -rf $dir" 0
90   git clone --no-checkout $MY_ACCOUNT_REPO_URL "$dir"/co
91   mv "$dir"/co/.git .
92   git checkout-index --quiet --index --all
93   git reset HEAD
94   rm -r $dir
95   trap - 0
96   echo
97 else
98   echo I: creating remote git repository for this account...
99   ssh $MY_GIT_SERVER "
100     GIT_DIR=${MY_ACCOUNT_GIT_REPO} git --bare init
101     echo 'account setup for $MY_ACCOUNT'
102     " </dev/null
103   echo I: setting up local git repository...
104   git init
105   git remote add origin $MY_ACCOUNT_REPO_URL
106   git config branch.master.remote origin
107   git config branch.master.merge refs/heads/master
108   git add .mrconfig
109   git commit -m'initial checkin'
110   git push --all
111   echo
112 fi
113
114 echo I: spawning a shell...
115 $SHELL -i -l </dev/tty >/dev/tty
116
117 echo I: back from the shell.
118
119 exit 0