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