]> 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:

do not fail when .bin already exists
[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=git://git.kitenet.net/mr
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 $MR_REPO_URL $MR_CODE
59   mkdir --parent $BIN_DIR
60   ln -s ../${MR_CODE}/mr $BIN_DIR/mr
61   echo
62 fi
63
64 cat <<_eof > .mrconfig
65 [DEFAULT]
66 include = cat $MR_CODE/lib/*
67
68 [$MR_FGIT]
69 checkout = git_fake_bare_checkout $MY_MR_REPO_URL ${MR_FGIT##*/} ../../
70 _eof
71 echo I: initial .mrconfig:
72 cat .mrconfig
73 echo
74
75 echo I: cloning mr configuration...
76 $MR_CODE/mr co
77 echo
78
79 echo I: bootstrapping default .mrconfig...
80 cp $MR/templ/.mrconfig .
81
82 echo I: setting up base...
83 $MR_CODE/mr co
84
85 if ssh $MY_GIT_SERVER "test -d $MY_ACCOUNT_GIT_REPO" </dev/null; then
86   echo I: checking out local git repository...
87   dir="$(mktemp -d home.XXXXXXXX)"
88   trap "rm -rf $dir" 0
89   git clone --no-checkout $MY_ACCOUNT_REPO_URL "$dir"/co
90   mv "$dir"/co/.git .
91   git checkout-index --quiet --index --all
92   git reset HEAD
93   rm -r $dir
94   trap - 0
95   echo
96 else
97   echo I: creating remote git repository for this account...
98   ssh $MY_GIT_SERVER "
99     GIT_DIR=${MY_ACCOUNT_GIT_REPO} git --bare init
100     echo 'account setup for $MY_ACCOUNT'
101     " </dev/null
102   echo I: setting up local git repository...
103   git init
104   git remote add origin $MY_ACCOUNT_REPO_URL
105   git config branch.master.remote origin
106   git config branch.master.merge refs/heads/master
107   git add .mrconfig
108   git commit -m'initial checkin'
109   git push --all
110   echo
111 fi
112
113 echo I: spawning a shell...
114 $SHELL --interactive --login </dev/tty >/dev/tty
115
116 echo I: back from the shell.
117
118 exit 0