summaryrefslogtreecommitdiff
path: root/enter-baserock
blob: d1333642c3119d760cf8ef106f6717a39e1e56a2 (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
#!/bin/bash

# enter-baserock -- Tool to enter a Baserock chroot using schroot

# Copyright (C) 2014  Codethink Ltd
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

SCHROOT_BASE="${SCHROOT_BASE:-/etc/schroot}"
SCHROOT_CONF="${SCHROOT_CONF:-${SCHROOT_BASE}/schroot.conf}"
BASEROCK_BASE="${BASEROCK_BASE:-/opt/baserock/chroots}"

baserock_default () {
    (cd "${BASEROCK_BASE}" && ls -d */default) 2>/dev/null | sed -e's@/default$@@' | head -1
}

CHOSEN="$1"

if test "x$CHOSEN" = "x"; then
    CHOSEN=$(baserock_default)
fi

if test "x$CHOSEN" = "x"; then
    echo "No default found, cannot enter baserock without a tag"
    exit 1
fi

cd /
exec sudo -H schroot -c "baserock-$CHOSEN"