summaryrefslogtreecommitdiff
path: root/home-mrconfig
blob: 6cf2d82e4cfd32a68421ccd3ced3d96e41051a55 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
# -*- mode: conf -*-

# --- global settings

[DEFAULT]
git_gc = git gc "$@"
jobs = 5

# actions to be configured per repository
git_sync = :
git_rebase = :

# In general, I don't want merge commits to be made en masse by mr
git_update = git pull --ff-only "$@"

# --- Adam Spiers' plugin for managing dotfile symlinks with mr

include =
    if [ -e ~/lib/mr/stow ]; then
        cat ~/lib/mr/stow
    # If the stow mr library gets included on Windows then we'll get errors on
    # e.g. mr update because mr'll try to call stow but it's not installed.
    # This second if clause will find the library on Windows, so check for
    # that.  We can't do this with my win32 command because inside include= is
    # a subshell that can't access stuff defined in mr config lib= directives.
    elif [ -e ~/src/dotfiles/lib/mr/stow -a ! "$(perl -e 'print $^O')" = "msys" ]; then
        cat ~/src/dotfiles/lib/mr/stow
    elif [ -e ~/local/lib/stow ]; then
        cat ~/local/lib/stow
    fi
lib =
    # reimplement kitenet-mr stow library function which relies on mr
    # "-r" parameter which is only present in aspiers' outdated fork
    is_stowable () {
            [ -z "$MR_DISABLE_STOW" ] &&
            ( mr stowable >/dev/null 2>&1 )
    }

# --- joeyh's code for specifying what machine we're on for repo skip
# --- tests, plus my code for detecting Git-on-Windows

lib =
    fast() {
        if [ "${MR_FAST}" = "true" ]; then
            return 0
        else
            return 1
        fi
    }
    win32() {
        if [ "$(perl -e 'print $^O')" = "msys" ]; then
            return 0
        else
            return 1
        fi
    }
    if win32; then
       hostname=$(hostname)
    else
       hostname=$(hostname -s)
    fi
    whoami="$(whoami)"
    # cut off the machine name from whoami on Windows
    if win32; then
        whoami=${whoami##*\\}
    fi
    on() {
        for host in $@; do
            if [ "${host%@*}" != "${host#*@}" ]; then
                if [ "$whoami" != "${host%@*}" ]; then
                    continue
                fi
                host="${host#*@}"
            fi
            if [ "$hostname" = "$host" ]; then
                return 0
            fi
        done
        return 1
    }
    mine() {
        on swhitton@artemis || on swhitton@zephyr || on swhitton@SPWHITTON
    }
    gcrypt() {
        which git-remote-gcrypt >/dev/null 2>/dev/null
    }

# --- A function for enabling Emacs mode for calling `git wip' on file
# --- save.  Warning: removes any other magit extensions enabled.  So
# --- be sure to add those to this function somehow if I ever start
# --- using any.
lib =
    wip() {
        git config --remove-section magit
        git config --add magit.extension wip-save
    }

# --- primary dotfiles repository

[src/dotfiles]
lib =
        # manually set a variable that aspiers' outdated fork of mr
        # sets, that his kitenet-mr stow library needs
        MR_NAME=dotfiles

stowable = true
checkout = git clone git://github.com/spwhitton/dotfiles.git dotfiles
update =
    # always make a go of updating master
    branch="$(git rev-parse --abbrev-ref HEAD)"
    git checkout master
    git pull --ff-only
    git checkout $branch
push =
    # always make a go of pushing master
    git push origin master
rebase =
    # common rebasing patterns
    branch="$(git rev-parse --abbrev-ref HEAD)"
    if [ "$branch" = "win32" ]; then
        git checkout win32
        git rebase master
    # fallback elif to still do something automatic in the simplest case
    elif [ "$branch" = "$hostname" ]; then
        # Determine nearest parent branch by
        # <https://stackoverflow.com/questions/3161204/find-the-parent-branch-of-a-branch#comment35666518_17843908>.
        # This should always be master per README, but check just in
        # case.
        parent="$(git show-branch -a | grep '*' | egrep -v "\[${branch}[0-9^~]*\]" | head -n1 | sed 's/.*\[\(.*\)\].*/\1/' | sed 's/[\^~].*//')"
        if [ "$parent" = "master" ]; then
            git checkout $branch
            git rebase master
        fi
    fi
# sync = git push origin master

# skip this repository if stow is not installed, and we're not on
# Windows where we don't use stow.  This should be a prompt to
# download a tarball, and do
#       ./configure --prefix=$HOME/local && make install
skip = ! which stow >/dev/null && ! win32

# stow won't overwrite a real ~/.mrconfig with a symlink to the
# version in my dotfiles repository.  Cannot just delete .mrconfig
# before a stow, because then mr can't tell stow what to do.  So just
# do it with manual fixup and have stow ignore this file.  Name is
# different to avoid mr trying to chain load it at any point

# similarly for .stow-global-ignore
fixups =
    if ! win32; then
        ln -sf $HOME/src/dotfiles/home-mrconfig $HOME/.mrconfig
        ln -sf $HOME/src/dotfiles/.stow-global-ignore $HOME
        mkdir -p $HOME/local/mutt $HOME/.ssh
        mkdir -p $HOME/tmp $HOME/src $HOME/local/src $HOME/local/bin $HOME/local/big $HOME/local/lib $HOME/local/pub
        # set up auth info folder: the "|| true" is because if the
        # folder is empty the final recursive chmod will fail
        mkdir -p $HOME/local/auth && chmod 700 $HOME/local/auth && chmod -R 600 $HOME/local/auth/* 2>/dev/null || true
        touch $HOME/local/big/.duplicity-ignore
        touch $HOME/.ssh/known_hosts
        chmod 600 $HOME/.msmtprc
    fi
    # we don't want git doing any automated merges of master, or other
    # intermediate branches.  mr is configured not to do this (see
    # redefinition of git_update at top of this file) but I often run
    # git pull in this repo myself
    git config branch.master.rebase true
    git config branch.autosetuprebase always
    # update crontab
    if ! win32; then
        # use absolute path because maybe we only just stowed so this
        # shell doesn't have $PATH setup by .shenv
        $HOME/bin/loadcron
        $HOME/bin/mkcabalc
    fi
    if win32; then
        cd ~/src/dotfiles/bin
	cmd "/C win32setup.bat"
    fi

# Empty out /etc/skel junk (must use full path to this script because
# it's pre stow!), and create ~/.emacs.d/ before stowing so that the
# files inside are symlinks, rather than the whole dir being a
# symlink.  That way Emacs junk that gets dumped in ~/.emacs.d doesn't
# have to be put into .gitignore.  Similarly the XDG autostart folder,
# .ssh and lib and more
pre_stow = $HOME/src/dotfiles/bin/unskel; mkdir -p ~/.emacs.d ~/.config/autostart ~/.ssh ~/lib ~/.cabal
pre_checkout = mkdir -p ~/.emacs.d  ~/.config/autostart ~/.ssh ~/lib ~/.cabal

# GTK insists on replacing the symlink to its bookmarks file with the
# actual file even if the bookmarks in that file don't change (XFCE
# only replaces symlinks to its config files if its changed them).
# Fix this situation in the simplest case to avoid mr restow giving an
# error.  Don't try anything fancy if the files are different; let the
# restow command give an error and the user fix it.
lib =
    fix_gtk_bookmarks () {
        if ! win32; then
            if ! [ -L ~/.gtk-bookmarks ]; then
                # file in home directory is not a link
                if diff -q ~/src/dotfiles/.gtk-bookmarks ~/.gtk-bookmarks > /dev/null; then
                    rm ~/.gtk-bookmarks
                fi
            fi
        fi
    }
pre_unstow = fix_gtk_bookmarks
pre_restow = fix_gtk_bookmarks
pre_update = fix_gtk_bookmarks

# --- private dotfiles repository

[src/priv]
lib =
        # manually set a variable that aspiers' outdated fork of mr
        # sets, that his kitenet-mr stow library needs
        MR_NAME=priv
stowable = true
checkout = git clone gcrypt::ssh://ma/~/local/git/priv.git priv

# this repository can't be checked out until we install
# git-remote-gcrypt.  And thanks to gcrypt being slow, skip if I run
# via fmr.
skip = (! gcrypt) || lazy || fast

# convenience automatic permission setting and checking in of
# frequently changed files
fixups = chmod 600 .passwddb.pet .s3ql/authinfo2; git config gcrypt.publish-participants true
pre_update =
        git add .passwddb.pet .labbook.gpg
        git commit -a -m "auto passwddb and labbook commit on $(hostname -s)" || true
autoci =
        git add .passwddb.pet .labbook.gpg
        git commit -a -m "auto passwddb and labbook commit on $(hostname -s)" || true

# --- hosts configuration

[src/propellor]
checkout = git clone git://github.com/spwhitton/propellor.git propellor --branch spwconf

# Get a sandbox going and get the dependencies of propellor installed
# in that sandbox, so that propellor can build itself during a spin.
# Then install propellor globally if we need to.  This is the
# propellor we will call when we type `propellor --spin x.y.z', which
# will go into the sandbox we just made and build and deploy.
post_checkout =
    cd propellor
    git remote add -f upstream git://github.com/joeyh/propellor.git
    cabal sandbox init
    cabal install --only-dependencies
    if ! which propellor > /dev/null && [ -d "/nix" ]; then
        cd && nix-env -iA nixpkgs.haskellngPackages.propellor
    fi
post_update = git fetch upstream
# check that the link isn't already in place before making the link
# because otherwise we get an infinite loop of links that breaks propellor
fixups = if ! [ -L ~/.propellor ]; then ln -sf ~/src/propellor ~/.propellor; fi

# Skip if we're not on my personal machine, or I haven't got GHC and
# friends up and running yet (see comproc.org for how to do that).
skip = (! (on swhitton@artemis || on swhitton@zephyr)) || (! which cabal >/dev/null)

# --- primary git annex

[lib/annex]
order = 8
# It's best to get a copy of this repo from e.g. my laptop.  The
# gcrypt repo can then be activated as a special remote.  This makes
# more sense because the gcrypt repo on the metaarray is a transitive
# repo rather than an authoritative upstream as the other repositories
# on ma are.
checkout = :
post_checkout = git remote rm origin

# basic commands
status = git annex status --fast
update = git annex sync ma
push = git annex sync ma
fixups =
    git config push.default matching
    git config gcrypt.publish-participants true
    git config annex.startupscan false
    git config annex.autocommit false

# copy everything to other places
sync =
    if [ -d /media/m3/annex/.git/annex ]; then
        git annex sync --content ma m3
        m3gitbk
    else
        git annex sync --content ma
    fi

# manual checkouts only, and skip when we're in a hurry and used 'fmr'
# instead of 'mr'
skip = lazy || fast

# --- git annex for use with rtorrent

[lib/rt]
order = 9
checkout = :
post_checkout = git remote rm origin
status = git annex status --fast
update = git annex sync ma
push = git annex sync ma
autoci = (git annex add . && git commit -m "auto commit on $(hostname -s)") || true
fixups =
    git config push.default matching
    git config gcrypt.publish-participants true
    git config annex.startupscan false
    git config annex.autocommit false
    if [ -d "$(hostname -s)" ]; then
        mkdir -p $HOME/local/rt
        cd $HOME/local/rt
        touch .duplicity-ignore
        mkdir -p session incomplete
        if ! [ -e "complete" ]; then
            ln -s $HOME/lib/rt/complete complete
        fi
        if ! [ -e "watch" ]; then
            ln -s $HOME/lib/rt/$(hostname -s) watch
        fi
    fi

# manual checkouts only, and skip when we're in a hurry and used 'fmr'
# instead of 'mr'
skip = lazy || fast

# --- source code repositories registered to their own mr config file

[src]

# Chain load unless we invoked mr via fmr alias.
chain = if [ "${MR_FAST}" = "true" ]; then return 1 else return 0; fi

# Always skip, since this is a dummy repository entry in order to
# chainload.
skip = ! [ "$MR_ACTION" = "stowable" ]

[src/srem]
checkout = git clone github:spwhitton/srem.git srem
post_checkout = ln -s $HOME/src/srem/dist/build/srem/srem $HOME/local/bin/srem
skip = lazy

# --- my personal documents, website and blog.  Override my global
# --- update command back to the myrepos default so that git
# --- automatically pulls and merges.  Skipped on non-local hosts

[doc]
order = 4
checkout = git clone 'ssh://ma/~/local/git/doc.git' 'doc'
update = git pull "$@"
skip = ! ( mine || on spw@ma )

# set file modification times to last commit
fixups = git-utime

# automatically commit in the same way that my cron job does before pulling
pre_update = if ! win32; then doccheckin; fi
# ... and let me do it manually
autoci = doccheckin || true

# quick syncs
sync =
    if win32; then
        cmd "/C doccheckin.bat" && git pull && git push
    else
        doccheckin && git pull && git push
    fi

# after pulling, update the online copy of my Org-mode agenda
# currently disabled because it's slow and with a computer at work I've not been checking this online copy
# post_update = echo -n "Updating web calendar... ";emacs -batch -l ~/.emacs.d/init.el -eval "(org-batch-store-agenda-views)" >/dev/null 2>/dev/null;echo "hopefully done."

[doc/www]
order = 5
checkout = git clone 'ssh://ma/~/local/git/doc.www.git' 'www'
update = git pull "$@"
skip = ! ( mine || on spw@ma ) || win32

[doc/www/blog]
order = 6
checkout = git clone 'ssh://ma/~/local/git/doc.www.blog.git' 'blog'
update = git pull "$@"
skip = ! ( mine || on spw@ma ) || win32

# --- my offline e-mail (& machine's postfix queue)

[.fmail]
order = 10
sync = movemail
update = mbsync --quiet fastmail
push = movemail

# Don't do anything if I don't use mbsync on this machine, or I
# didn't run one of the sync or update commands.
skip = ! [ -d "$HOME/.fmail" ] || ! ( [ "$MR_ACTION" = "stowable" ] || [ "$MR_ACTION" = "push" ] || [ "$MR_ACTION" = "sync" ] || [ "$MR_ACTION" = "update" ] )