summaryrefslogtreecommitdiff
path: root/newroot
blob: 64f0704bacd1bbd4faf5e97fbda037e72a0795a3 (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
#!/bin/bash
# Copyleft 2012 - Nicolás Reynolds <fauno@parabola.nu>
# Bootstraps a Parabola root, useful for base systems, build chroots, etc.
# Note: this is a very basic script that let's you do whatever you want, so
# it's not foolproof ;)

# Attempt to provide some help
if [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
    echo "Installs a Parabola root on the current dir"
    echo "Usage: newroot [custom package1 ...]"
    echo ""
    echo "Environment variables:"
    echo -e "WORKDIR \tThe install dir"
    echo -e "LOGFILE \tAn alternate logfile ($PWD/pacman.log)"
    echo -e "PACCACHE\tThe pacman cache (guessed)"
    exit
fi

# Fail at any error
set -E

if [ ! -w / ]; then echo "Run as root."; exit 1; fi

# Should work unless you have a messy pacman.conf
function find_cache() {
    grep "CacheDir\s*=\s*" /etc/pacman.conf | tail -n1 | cut -d"=" -f2 | tr -d " "
}

# Build on the current dir or WORKDIR env var
WORKDIR="${WORKDIR:-${PWD}}"
LOGFILE="${LOGFILE:-${WORKDIR}/pacman.log}"
PACCACHE="${PACCACHE:-$(find_cache)}"
# Do a last attempt to have a pacman cache
PACCACHE="${PACCACHE:-/var/cache/pacman/pkg}"

export WORKDIR LOGFILE PACCACHE

pacman() {
    /usr/bin/pacman -r "${WORKDIR}" \
                    --dbpath "${WORKDIR}"/var/lib/pacman \
                    --logfile "${LOGFILE}" \
                    --noconfirm \
                    --cachedir "${PACCACHE}" \
                    --config /etc/pacman.conf $@
}

#trap_exit() {
#    for _k in dev proc sys; do
#        umount "${WORKDIR}"/$_k
#    done
#}

#for _t in EXIT INT TERM HUP QUIT ERR; do
#    trap trap_exit $_t
#done

# Bootstrap!
mkdir -p "${WORKDIR}"/{var/lib/pacman,dev,proc,sys}

#for _k in dev proc sys; do
#    mount --bind /$_k "${WORKDIR}"/$_k
#done

# We need to do this twice or the install won't find the databases
pacman -Sy
pacman -S $@