2014-10-04 00:46:40 +02:00
|
|
|
#!/bin/bash
|
2014-11-18 19:20:53 +01:00
|
|
|
#
|
2014-10-04 00:46:40 +02:00
|
|
|
# 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; version 2 of the License.
|
|
|
|
#
|
|
|
|
# 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.
|
|
|
|
|
2014-10-08 13:14:28 +02:00
|
|
|
version=@version@
|
|
|
|
|
2014-11-13 16:31:15 +01:00
|
|
|
[[ -r @libdir@/util-msg.sh ]] && source @libdir@/util-msg.sh
|
|
|
|
[[ -r @libdir@/util.sh ]] && source @libdir@/util.sh
|
2014-10-04 00:46:40 +02:00
|
|
|
|
2014-11-12 02:19:58 +01:00
|
|
|
working_dir=''
|
2015-01-02 18:26:27 +01:00
|
|
|
build_locales=false
|
2014-10-04 00:46:40 +02:00
|
|
|
|
|
|
|
usage() {
|
2014-11-12 02:19:58 +01:00
|
|
|
echo "Usage: ${0##*/} [options] working-dir package-list..."
|
|
|
|
echo ' options:'
|
|
|
|
echo ' -C <file> Location of a pacman config file'
|
|
|
|
echo ' -M <file> Location of a makepkg config file'
|
|
|
|
echo ' -S <file> Location of a pacman-mirrors config file'
|
|
|
|
echo ' -c <dir> Set pacman cache'
|
2015-01-02 18:42:56 +01:00
|
|
|
echo ' -L Use build locale.gen en/de'
|
2015-01-15 06:22:42 +01:00
|
|
|
echo ' -B Use custom build mirror'
|
2014-11-12 02:19:58 +01:00
|
|
|
echo ' -h This message'
|
|
|
|
exit 1
|
2014-10-04 00:46:40 +02:00
|
|
|
}
|
|
|
|
|
2014-11-12 02:19:58 +01:00
|
|
|
orig_argv=("$@")
|
|
|
|
|
2015-06-01 01:05:04 +02:00
|
|
|
opts='hLC:M:S:c:B:'
|
2015-05-29 17:12:24 +02:00
|
|
|
|
|
|
|
while getopts ${opts} arg; do
|
|
|
|
case "${arg}" in
|
2014-11-12 02:19:58 +01:00
|
|
|
C) pac_conf="$OPTARG" ;;
|
|
|
|
M) makepkg_conf="$OPTARG" ;;
|
|
|
|
S) mirrors_conf="$OPTARG" ;;
|
|
|
|
c) cache_dir="$OPTARG" ;;
|
2015-01-15 06:22:42 +01:00
|
|
|
L) build_locales=true ;;
|
|
|
|
B) build_mirror="$OPTARG" ;;
|
2014-11-12 02:19:58 +01:00
|
|
|
h|?) usage ;;
|
|
|
|
*) error "invalid argument '$arg'"; usage ;;
|
|
|
|
esac
|
2014-10-04 00:46:40 +02:00
|
|
|
done
|
|
|
|
shift $(($OPTIND - 1))
|
|
|
|
|
2014-11-11 21:19:26 +01:00
|
|
|
(( $# < 2 )) && die 'You must specify a directory and one or more packages.'
|
2014-10-04 00:46:40 +02:00
|
|
|
|
2014-11-12 02:19:58 +01:00
|
|
|
check_root "$0" "${orig_argv[@]}"
|
2014-11-11 21:19:26 +01:00
|
|
|
|
2014-11-12 02:19:58 +01:00
|
|
|
working_dir="$(readlink -f $1)"
|
2014-11-11 21:19:26 +01:00
|
|
|
shift 1
|
2014-10-04 00:46:40 +02:00
|
|
|
|
2014-11-12 02:19:58 +01:00
|
|
|
[[ -z $working_dir ]] && die 'Please specify a working directory.'
|
2014-10-04 00:46:40 +02:00
|
|
|
|
2014-11-12 02:19:58 +01:00
|
|
|
if [[ -z $cache_dir ]]; then
|
|
|
|
cache_dirs=($(pacman -v $cache_conf 2>&1 | grep '^Cache Dirs:' | sed 's/Cache Dirs:\s*//g'))
|
|
|
|
else
|
|
|
|
cache_dirs=(${cache_dir})
|
|
|
|
fi
|
2014-10-04 00:46:40 +02:00
|
|
|
|
2014-11-12 02:19:58 +01:00
|
|
|
umask 0022
|
2014-10-04 00:46:40 +02:00
|
|
|
|
2014-12-11 03:54:02 +01:00
|
|
|
#[[ -e $working_dir ]] && die "Working directory '%s' already exists" "$working_dir"
|
2014-10-04 00:46:40 +02:00
|
|
|
|
2014-12-11 03:54:02 +01:00
|
|
|
#mkdir -p "$working_dir"
|
2015-01-15 13:23:34 +01:00
|
|
|
|
2014-12-11 03:54:02 +01:00
|
|
|
[[ ! -d $working_dir ]] && mkdir -p "$working_dir"
|
2014-10-04 00:46:40 +02:00
|
|
|
|
2014-11-12 02:19:58 +01:00
|
|
|
lock 9 "${working_dir}.lock" "Locking chroot"
|
2014-10-04 00:46:40 +02:00
|
|
|
|
2014-11-12 02:19:58 +01:00
|
|
|
if [[ $(stat -f -c %T "$working_dir") == btrfs ]]; then
|
|
|
|
rmdir "$working_dir"
|
|
|
|
if ! btrfs subvolume create "$working_dir"; then
|
|
|
|
die "Couldn't create subvolume for '%s'" "$working_dir"
|
2014-10-04 00:46:40 +02:00
|
|
|
fi
|
2014-11-12 02:19:58 +01:00
|
|
|
chmod 0755 "$working_dir"
|
|
|
|
fi
|
2014-10-04 00:46:40 +02:00
|
|
|
|
2015-06-01 01:05:04 +02:00
|
|
|
basestrap -GMcd ${pac_conf:+-C "$pac_conf"} "$working_dir" \
|
2014-11-12 02:19:58 +01:00
|
|
|
"${cache_dirs[@]/#/--cachedir=}" "$@" || die 'Failed to install all packages'
|
2015-02-13 15:17:00 +01:00
|
|
|
|
2015-01-08 16:19:30 +01:00
|
|
|
echo "$version" > "$working_dir/.manjaro-tools"
|
2014-11-12 02:19:58 +01:00
|
|
|
|
2015-01-08 17:51:39 +01:00
|
|
|
if ${build_locales};then
|
2015-02-13 15:17:00 +01:00
|
|
|
mv "$working_dir/etc/locale.gen" "$working_dir/etc/locale.gen.bak"
|
|
|
|
mv "$working_dir/etc/locale.conf" "$working_dir/etc/locale.conf.bak"
|
|
|
|
printf '%s.UTF-8 UTF-8\n' en_US de_DE > "$working_dir/etc/locale.gen"
|
|
|
|
printf 'LANG=%s.UTF-8\n' en_US > "$working_dir/etc/locale.conf"
|
|
|
|
printf 'LC_MESSAGES=C\n' >> "$working_dir/etc/locale.conf"
|
2015-01-08 17:51:39 +01:00
|
|
|
fi
|
2015-01-11 21:02:29 +01:00
|
|
|
|
|
|
|
exec chroot-run \
|
|
|
|
${pac_conf:+-C "$pac_conf"} \
|
|
|
|
${makepkg_conf:+-M "$makepkg_conf"} \
|
|
|
|
${mirrors_conf:+-S "$mirrors_conf"} \
|
2015-01-15 06:22:42 +01:00
|
|
|
${build_mirror:+-B "$build_mirror"} \
|
2015-01-11 21:02:29 +01:00
|
|
|
${cache_dir:+-c "$cache_dir"} \
|
|
|
|
"$working_dir" locale-gen
|
|
|
|
|