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

5af48336b22f769cd0c369dc398a83ddb0b14b3c
[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_GIT_REPO=$MY_GIT_REPOS/accounts/$(whoami)@$(hostname --fqdn).git
13 MY_GIT_URL_BASE=ssh://$MY_GIT_SERVER
14 MY_MR_REPO_URL=$MY_GIT_URL_BASE/$MY_GIT_REPOS/pub/etc/mr.git
15 MY_ACCOUNT_REPO_URL=$MY_GIT_URL_BASE/$MY_ACCOUNT_GIT_REPO
16 MR_REPO_URL=git://git.kitenet.net/mr
17 MR_CODE=code/mr
18 MR_FGIT=.fgits/mr.git
19 MR=.mr
20 BIN_DIR=.bin
21
22 if [ ! -x "$(command -v git)" ]; then
23   echo E: git is not installed. >&2
24   exit 1
25 fi
26
27 if [ -e .mrconfig ]; then
28   echo E: .mrconfig already exists. >&2
29   exit 2
30 fi
31
32 if [ -d "$MR_FGIT" ]; then
33   echo E: "$MR_FGIT" already exists. >&2
34   exit 3
35 fi
36
37 if [ -d ".git" ]; then
38   echo E: .git already exists. >&2
39   exit 3
40 fi
41
42 if [ -d code/mr ]; then
43   if [ -x code/mr/mr ]; then
44     echo W: code/mr already exists, let us hope for the best... >&2
45   else
46     echo E: code/mr already exists. >&2
47     exit 4
48   fi
49 else
50   echo I: cloning mr into ${MR_CODE}...
51   mkdir --parent ${MR_CODE%/*}
52   git clone $MR_REPO_URL $MR_CODE
53   mkdir .bin
54   ln -s ../${MR_CODE}/mr $BIN_DIR/mr
55   echo
56 fi
57
58 cat <<_eof > .mrconfig
59 [DEFAULT]
60 include = cat $MR_CODE/lib/*
61
62 [$MR_FGIT]
63 checkout = git_fake_bare_checkout $MY_MR_REPO_URL ${MR_FGIT##*/} ../../
64 _eof
65 echo I: initial .mrconfig:
66 cat .mrconfig
67 echo
68
69 echo I: cloning mr configuration...
70 $MR_CODE/mr co
71 echo
72
73 echo I: bootstrapping default .mrconfig...
74 cp $MR/templ/.mrconfig .
75
76 echo I: setting up base...
77 $MR_CODE/mr co
78
79 if ssh $MY_GIT_SERVER "test -d $MY_ACCOUNT_GIT_REPO"; then
80   echo I: checking out local git repository...
81   dir="$(mktemp -d home.XXXXXXXX)"
82   trap "rm -rf $dir" 0
83   git clone --no-checkout $MY_ACCOUNT_REPO_URL "$dir"/co
84   mv "$dir"/co/.git .
85   git checkout-index --quiet --index --all
86   git reset HEAD
87   echo
88 else
89   echo I: creating remote git repository for this account...
90   ssh $MY_GIT_SERVER "GIT_DIR=${MY_ACCOUNT_GIT_REPO} git --bare init"
91   echo I: setting up local git repository...
92   git init
93   git remote add origin $MY_ACCOUNT_REPO_URL
94   git config branch.master.remote origin
95   git config branch.master.merge refs/heads/master
96   git add .mrconfig
97   git commit -m'initial checkin'
98   git push --all
99 fi
100
101 exit 0