78 lines
1.8 KiB
Bash
78 lines
1.8 KiB
Bash
|
#!/bin/env bash
|
||
|
|
||
|
function die() { echo "$*" >&2; exit 1; }
|
||
|
|
||
|
function check_preconditions() {
|
||
|
test -d /secrets || die "no /secrets directory"
|
||
|
test -d /depot || die "no /depot directory"
|
||
|
}
|
||
|
|
||
|
function clone_depot() {
|
||
|
echo Cloning depot to /depot/depot >&2
|
||
|
hg clone ssh://hg/lukegb/depot /depot/depot
|
||
|
cd /depot/depot
|
||
|
}
|
||
|
|
||
|
function update_depot() {
|
||
|
echo Updating depot checkout in /depot/depot >&2
|
||
|
cd /depot/depot
|
||
|
hg revert -a
|
||
|
hg pull
|
||
|
hg update -r default -C
|
||
|
hg purge --all
|
||
|
hg strip --no-backup 'roots(outgoing())' || true
|
||
|
}
|
||
|
|
||
|
function make_depot_fresh() {
|
||
|
if test -d /depot/depot; then
|
||
|
update_depot
|
||
|
else
|
||
|
clone_depot
|
||
|
fi
|
||
|
}
|
||
|
|
||
|
function clone_nixpkgs() {
|
||
|
echo Cloning nixpkgs to /depot/nixpkgs >&2
|
||
|
git clone --bare https://github.com/NixOS/nixpkgs.git /depot/nixpkgs
|
||
|
}
|
||
|
|
||
|
function update_nixpkgs() {
|
||
|
echo Updating nixpkgs checkout in /depot/nixpkgs >&2
|
||
|
pushd /depot/nixpkgs
|
||
|
git fetch origin nixos-unstable
|
||
|
git branch -f master FETCH_HEAD
|
||
|
popd
|
||
|
}
|
||
|
|
||
|
function make_nixpkgs_fresh() {
|
||
|
if test -d /depot/nixpkgs; then
|
||
|
update_nixpkgs
|
||
|
else
|
||
|
clone_nixpkgs
|
||
|
fi
|
||
|
}
|
||
|
|
||
|
function main() {
|
||
|
set -euxo pipefail
|
||
|
check_preconditions
|
||
|
make_depot_fresh
|
||
|
make_nixpkgs_fresh
|
||
|
|
||
|
# Pre-seed the copybara cache directory, so it doesn't try to do the clone itself.
|
||
|
mkdir -p $HOME/copybara/cache/{git_repos,hg_repos}
|
||
|
hg clone --noupdate /depot/depot $HOME/copybara/cache/hg_repos/file%3A%2F%2F%2Fdepot%2Fdepot
|
||
|
git clone --mirror /depot/nixpkgs $HOME/copybara/cache/git_repos/https%3A%2F%2Fgithub%2Ecom%2FNixOS%2Fnixpkgs%2Egit
|
||
|
|
||
|
sed -i 's,file:///home/lukegb/depot,file:///depot/depot,g' ./third_party/nixpkgs/copy.bara.sky
|
||
|
copybara migrate --verbose ./third_party/nixpkgs/copy.bara.sky || exit 0
|
||
|
|
||
|
# Reset to a clean state.
|
||
|
hg update -r default -C
|
||
|
hg purge --all
|
||
|
|
||
|
# And push, if it that worked.
|
||
|
hg push -r .
|
||
|
}
|
||
|
|
||
|
main
|