Compare commits

...

21 commits

Author SHA1 Message Date
udeved
551cea0835 mkchrootpkg: fix namcap, should go upstream 2017-04-19 08:50:40 +02:00
udeved
f3bbc3b96f lib: nove lock functions to util-msg 2017-04-19 08:50:08 +02:00
udeved
c6bd1d3a5e chroot-run: remove commented code
mkchrootpkg: update help
2017-04-19 01:19:31 +02:00
udeved
d2bb99ff1a fix args 2017-04-19 01:09:57 +02:00
udeved
6518825280 initial arch backport 2017-04-19 00:01:00 +02:00
udeved
bf2ddc1e1d util-iso-boot: fix param 2017-04-02 17:56:23 +02:00
udeved
d455564eb6 util-iso-boot: make the copy paths more structured 2017-04-02 16:56:52 +02:00
Philip
a4fc8325df [util-iso-boot] really proper last commit 2017-04-02 15:00:12 +02:00
Philip
b121fe7490 [util-iso-boot] proper last commit 2017-04-02 14:53:35 +02:00
Philip
518992d723 [util-iso-boot] fix issue with i686 build on x86_64 host 2017-04-02 14:47:21 +02:00
udeved
a1492e8d1e util-iso: set the grub theme by $iso_name 2017-03-31 17:45:16 +02:00
udeved
25ddeb1593 doc: remove obsolete entry from deployiso
util-yaml: formating fix
2017-03-30 23:21:17 +02:00
udeved
37b9feb061 util-iso: clean up assemble_iso() 2017-03-30 23:07:09 +02:00
udeved
93626731c7 util-iso-boot: remove grub video dir 2017-03-30 15:51:44 +02:00
Philip
9533b8ce93 [util-iso] try to fix issue with efi.img 2017-03-30 00:34:24 +02:00
udeved
ed95e249a2 util-iso: don't create mod_dte file for now 2017-03-29 22:19:44 +02:00
udeved
8a5fc4e0b0 util-iso: fox mod_date length 2017-03-29 21:53:47 +02:00
udeved
734ea24b57 util-iso: readd xorriso args 2017-03-29 21:48:38 +02:00
udeved
d477c42ecb util-iso-boot: reduce efi.img size 2017-03-29 21:48:00 +02:00
udeved
92aaea7694 util-iso-*: put grub-theme in livefs 2017-03-29 20:47:17 +02:00
udeved
187aac2a35 util-iso: try to fix uefi usb boot 2017-03-29 19:03:29 +02:00
15 changed files with 410 additions and 341 deletions

View file

@ -48,8 +48,7 @@ usage() {
# exit $(( $# ? 0 : 1 )) # exit $(( $# ? 0 : 1 ))
# fi # fi
# #
orig_argv=("$0" "$@")
orig_argv=("$@")
opts=':C:cdGiM' opts=':C:cdGiM'
@ -67,7 +66,7 @@ while getopts ${opts} arg; do
done done
shift $(( OPTIND - 1 )) shift $(( OPTIND - 1 ))
check_root "$0" "${orig_argv[@]}" check_root
(( $# )) || die "No root directory specified" (( $# )) || die "No root directory specified"
newroot=$1; shift newroot=$1; shift
@ -97,7 +96,7 @@ if ! pacman -r "$newroot" -Sy "${pacman_args[@]}"; then
fi fi
# kill chroot process if needed (TODO: check if needed at all) # kill chroot process if needed (TODO: check if needed at all)
kill_chroot_process "$newroot" # kill_chroot_process "$newroot"
if ${copykeyring};then if ${copykeyring};then
copy_keyring "$newroot" copy_keyring "$newroot"

View file

@ -135,7 +135,7 @@ usage() {
exit $1 exit $1
} }
orig_argv=("$@") orig_argv=("$0" "$@")
opts='p:a:b:r:t:k:i:g:czxmvqh' opts='p:a:b:r:t:k:i:g:czxmvqh'
@ -164,7 +164,7 @@ shift $(($OPTIND - 1))
timer_start=$(get_timer) timer_start=$(get_timer)
check_root "$0" "${orig_argv[@]}" check_root
prepare_dir "${log_dir}" prepare_dir "${log_dir}"

View file

@ -103,7 +103,7 @@ usage() {
exit $1 exit $1
} }
orig_argv=("$@") orig_argv=("$0" "$@")
opts='p:a:b:r:i:cwnsuqh' opts='p:a:b:r:i:cwnsuqh'
@ -127,7 +127,7 @@ done
shift $(($OPTIND - 1)) shift $(($OPTIND - 1))
check_root "$0" "${orig_argv[@]}" check_root
prepare_dir "${log_dir}" prepare_dir "${log_dir}"

View file

@ -55,7 +55,7 @@ usage() {
exit $1 exit $1
} }
orig_argv=("$@") orig_argv=("$0" "$@")
opts='sacqh' opts='sacqh'
@ -72,7 +72,7 @@ done
shift $(($OPTIND - 1)) shift $(($OPTIND - 1))
check_root "$0" "${orig_argv[@]}" check_root
prepare_dir "${tree_dir_abs}" prepare_dir "${tree_dir_abs}"

View file

@ -112,7 +112,7 @@ usage() {
exit $1 exit $1
} }
orig_argv=("$@") orig_argv=("$0" "$@")
opts='p:a:i:k:gcvqh' opts='p:a:i:k:gcvqh'
@ -133,7 +133,7 @@ done
shift $(($OPTIND - 1)) shift $(($OPTIND - 1))
check_root "$0" "${orig_argv[@]}" check_root
prepare_dir "${tmp_dir}" prepare_dir "${tmp_dir}"

View file

@ -19,7 +19,9 @@ import ${LIBDIR}/util.sh
import ${LIBDIR}/util-mount.sh import ${LIBDIR}/util-mount.sh
working_dir='' working_dir=''
files=()
keep_mirrors=false keep_mirrors=false
nosetarch=false
usage() { usage() {
echo "Usage: ${0##*/} [options] working-dir [run arguments]" echo "Usage: ${0##*/} [options] working-dir [run arguments]"
@ -30,18 +32,20 @@ usage() {
echo ' -M <file> Location of a makepkg config file' echo ' -M <file> Location of a makepkg config file'
echo ' -S <file> Location of a pacman-mirrors config file' echo ' -S <file> Location of a pacman-mirrors config file'
echo ' -c <dir> Set pacman cache' echo ' -c <dir> Set pacman cache'
echo ' -f <file> Copy file from the host to the chroot'
echo ' -s Do not run setarch'
echo ' -r <list> Bind mountargs ro' echo ' -r <list> Bind mountargs ro'
echo ' -w <list> Bind mountargs rw' echo ' -w <list> Bind mountargs rw'
echo ' List format [src1:target1,...,srcN:targetN]' echo ' List format [src1:target1 ... srcN:targetN]'
echo ' -B Use custom build mirror' echo ' -B Use custom build mirror'
echo ' -K Keep mirrorlist (-B)' echo ' -K Keep mirrorlist (-B)'
echo ' -h This message' echo ' -h This message'
exit 1 exit 1
} }
orig_argv=("$@") orig_argv=("$0" "$@")
opts='hKC:M:S:c:r:w:B:' opts='hKC:M:S:c:r:w:B:f:s'
while getopts ${opts} arg; do while getopts ${opts} arg; do
case "${arg}" in case "${arg}" in
@ -49,8 +53,10 @@ while getopts ${opts} arg; do
M) makepkg_conf="$OPTARG" ;; M) makepkg_conf="$OPTARG" ;;
S) mirrors_conf="$OPTARG" ;; S) mirrors_conf="$OPTARG" ;;
c) cache_dir="$OPTARG" ;; c) cache_dir="$OPTARG" ;;
r) mountargs_ro="$OPTARG" ;; f) files+=("$OPTARG") ;;
w) mountargs_rw="$OPTARG" ;; s) nosetarch=true ;;
r) bindmounts_ro=("$OPTARG") ;;
w) bindmounts_rw=("$OPTARG") ;;
B) build_mirror="$OPTARG" ;; B) build_mirror="$OPTARG" ;;
K) keep_mirrors=true ;; K) keep_mirrors=true ;;
h|?) usage ;; h|?) usage ;;
@ -60,7 +66,8 @@ done
shift $(($OPTIND - 1)) shift $(($OPTIND - 1))
(( $# < 1 )) && die 'You must specify a directory.' (( $# < 1 )) && die 'You must specify a directory.'
check_root "$0" "${orig_argv[@]}"
check_root
working_dir=$(readlink -f "$1") working_dir=$(readlink -f "$1")
shift 1 shift 1
@ -81,6 +88,12 @@ copy_hostconf () {
[[ -n $makepkg_conf ]] && cp $makepkg_conf "$1/etc/makepkg.conf" [[ -n $makepkg_conf ]] && cp $makepkg_conf "$1/etc/makepkg.conf"
[[ -n $mirrors_conf ]] && cp ${mirrors_conf} "$1/etc/pacman-mirrors.conf" [[ -n $mirrors_conf ]] && cp ${mirrors_conf} "$1/etc/pacman-mirrors.conf"
local file
for file in "${files[@]}"; do
mkdir -p "$(dirname "$working_dir$file")"
cp -T "$file" "$working_dir$file"
done
if [[ -n ${build_mirror} ]];then if [[ -n ${build_mirror} ]];then
build_mirror=${build_mirror}'/$repo/$arch' build_mirror=${build_mirror}'/$repo/$arch'
if ${keep_mirrors}; then if ${keep_mirrors}; then
@ -95,7 +108,7 @@ copy_hostconf () {
sed -r "s|^#?\\s*CacheDir.+|CacheDir = $(echo -n ${cache_dirs[@]})|g" -i "$1/etc/pacman.conf" sed -r "s|^#?\\s*CacheDir.+|CacheDir = $(echo -n ${cache_dirs[@]})|g" -i "$1/etc/pacman.conf"
} }
chroot_extra_umount() { chroot_extra_mount() {
chroot_mount "/etc/resolv.conf" "$1/etc/resolv.conf" -B chroot_mount "/etc/resolv.conf" "$1/etc/resolv.conf" -B
chroot_mount "${cache_dirs[0]}" "$1${cache_dirs[0]}" -B chroot_mount "${cache_dirs[0]}" "$1${cache_dirs[0]}" -B
@ -103,21 +116,13 @@ chroot_extra_umount() {
chroot_mount "$cache_dir" "$1${cache_dir}" -Br chroot_mount "$cache_dir" "$1${cache_dir}" -Br
done done
if [[ -n ${mountargs_ro[@]} ]];then for m in ${bindmounts_ro[@]}; do
local IFS=',' chroot_mount "${m%%:*}" "$1${m##*:}" -Br
for m in ${mountargs_ro[@]}; do done
chroot_mount "${m%%:*}" "$1${m##*:}" -Br
done
unset IFS
fi
if [[ -n ${mountargs_rw[@]} ]];then for m in ${bindmounts_rw[@]}; do
local IFS=',' chroot_mount "${m%%:*}" "$1${m##*:}" -B
for m in ${mountargs_rw[@]}; do done
chroot_mount "${m%%:*}" "$1${m##*:}" -B
done
unset IFS
fi
} }
umask 0022 umask 0022
@ -131,12 +136,14 @@ fi
chroot_api_mount "${working_dir}" || die "failed to setup API filesystems in chroot %s" "${working_dir}" chroot_api_mount "${working_dir}" || die "failed to setup API filesystems in chroot %s" "${working_dir}"
chroot_extra_umount "${working_dir}" chroot_extra_mount "${working_dir}"
copy_hostconf "${working_dir}" copy_hostconf "${working_dir}"
eval $(grep '^CARCH=' "$working_dir/etc/makepkg.conf") eval $(grep '^CARCH=' "$working_dir/etc/makepkg.conf")
${nosetarch} && unset CARCH
${CARCH:+setarch "$CARCH"} chroot "${working_dir}" "$@" ${CARCH:+setarch "$CARCH"} chroot "${working_dir}" "$@"
kill_chroot_process "${working_dir}" # kill_chroot_process "${working_dir}"

View file

@ -55,7 +55,7 @@ usage() {
exit $1 exit $1
} }
orig_argv=("$@") orig_argv=("$0" "$@")
opts=':haq' opts=':haq'
@ -69,7 +69,7 @@ while getopts ${opts} arg; do
done done
shift $(( OPTIND - 1 )) shift $(( OPTIND - 1 ))
check_root "$0" "${orig_argv[@]}" check_root
if ${automount};then if ${automount};then
chrootdir=/mnt chrootdir=/mnt

View file

@ -18,9 +18,12 @@ LIBDIR='@libdir@'
import ${LIBDIR}/util.sh import ${LIBDIR}/util.sh
working_dir='' working_dir=''
files=()
build_locales=false build_locales=false
keep_mirrors=false keep_mirrors=false
keep_flag='' keep_flag=''
nosetarch=false
usage() { usage() {
echo "Usage: ${0##*/} [options] working-dir package-list..." echo "Usage: ${0##*/} [options] working-dir package-list..."
@ -29,6 +32,8 @@ usage() {
echo ' -M <file> Location of a makepkg config file' echo ' -M <file> Location of a makepkg config file'
echo ' -S <file> Location of a pacman-mirrors config file' echo ' -S <file> Location of a pacman-mirrors config file'
echo ' -c <dir> Set pacman cache' echo ' -c <dir> Set pacman cache'
echo ' -f <file> Copy file from the host to the chroot'
echo ' -s Do not run setarch'
echo ' -L Use build locale.gen en/de' echo ' -L Use build locale.gen en/de'
echo ' -B Use custom build mirror' echo ' -B Use custom build mirror'
echo ' -K Keep mirrorlist (-B)' echo ' -K Keep mirrorlist (-B)'
@ -37,9 +42,9 @@ usage() {
exit 1 exit 1
} }
orig_argv=("$@") orig_argv=("$0" "$@")
opts='hLKC:M:S:c:B:' opts='hLKC:M:S:c:B:f:s'
while getopts ${opts} arg; do while getopts ${opts} arg; do
case "${arg}" in case "${arg}" in
@ -47,18 +52,20 @@ while getopts ${opts} arg; do
M) makepkg_conf="$OPTARG" ;; M) makepkg_conf="$OPTARG" ;;
S) mirrors_conf="$OPTARG" ;; S) mirrors_conf="$OPTARG" ;;
c) cache_dir="$OPTARG" ;; c) cache_dir="$OPTARG" ;;
f) files+=("$OPTARG") ;;
s) nosetarch=true ;;
L) build_locales=true ;; L) build_locales=true ;;
B) build_mirror="$OPTARG" ;; B) build_mirror="$OPTARG" ;;
K) keep_mirrors=true; keep_flag='-K' ;; K) keep_mirrors=true; keep_flag='-K' ;;
h|?) usage ;; h|?) usage ;;
*) error "invalid argument '$arg'"; usage ;; *) error "invalid argument '%s'" "$arg"; usage ;;
esac esac
done done
shift $(($OPTIND - 1)) shift $(($OPTIND - 1))
(( $# < 2 )) && die 'You must specify a directory and one or more packages.' (( $# < 2 )) && die 'You must specify a directory and one or more packages.'
check_root "$0" "${orig_argv[@]}" check_root
working_dir="$(readlink -f $1)" working_dir="$(readlink -f $1)"
shift 1 shift 1
@ -89,6 +96,11 @@ if is_btrfs "$working_dir"; then
chmod 0755 "$working_dir" chmod 0755 "$working_dir"
fi fi
for file in "${files[@]}"; do
mkdir -p "$(dirname "$working_dir$file")"
cp "$file" "$working_dir$file"
done
# Workaround when creating a chroot in a branch different of the host # Workaround when creating a chroot in a branch different of the host
if [[ -n $pac_conf ]] && [[ -n $mirrors_conf ]] && [[ -n ${build_mirror} ]]; then if [[ -n $pac_conf ]] && [[ -n $mirrors_conf ]] && [[ -n ${build_mirror} ]]; then
url=${build_mirror}'/$repo/$arch' url=${build_mirror}'/$repo/$arch'
@ -96,11 +108,21 @@ if [[ -n $pac_conf ]] && [[ -n $mirrors_conf ]] && [[ -n ${build_mirror} ]]; the
pac_base="$working_dir/pacman-basestrap.conf" pac_base="$working_dir/pacman-basestrap.conf"
sed "s#Include = /etc/pacman.d/mirrorlist#Server = ${url}#g" $pac_conf > $pac_base sed "s#Include = /etc/pacman.d/mirrorlist#Server = ${url}#g" $pac_conf > $pac_base
_env=()
while read -r varname; do
_env+=("$varname=${!varname}")
done < <(declare -x | sed -r 's/^declare -x ([^=]*)=.*/\1/' | grep -i '_proxy$')
env -i "${_env[@]}" \
basestrap -GMcd ${pac_base:+-C "$pac_base"} "$working_dir" \ basestrap -GMcd ${pac_base:+-C "$pac_base"} "$working_dir" \
"${cache_dirs[@]/#/--cachedir=}" "$@" || die 'Failed to install all packages' "${cache_dirs[@]/#/--cachedir=}" "$@" || die 'Failed to install all packages'
[[ -f "$pac_base" ]] && rm "$pac_base" [[ -f "$pac_base" ]] && rm "$pac_base"
else else
_env=()
while read -r varname; do
_env+=("$varname=${!varname}")
done < <(declare -x | sed -r 's/^declare -x ([^=]*)=.*/\1/' | grep -i '_proxy$')
env -i "${_env[@]}" \
basestrap -GMcd ${pac_conf:+-C "$pac_conf"} "$working_dir" \ basestrap -GMcd ${pac_conf:+-C "$pac_conf"} "$working_dir" \
"${cache_dirs[@]/#/--cachedir=}" "$@" || die 'Failed to install all packages' "${cache_dirs[@]/#/--cachedir=}" "$@" || die 'Failed to install all packages'
fi fi
@ -117,6 +139,7 @@ if ${build_locales};then
fi fi
chroot_args=(${pac_conf:+-C "$pac_conf"} ${makepkg_conf:+-M "$makepkg_conf"} ${mirrors_conf:+-S "$mirrors_conf"} ${build_mirror:+-B "$build_mirror"} ${cache_dir:+-c "$cache_dir"} ${keep_flag}) chroot_args=(${pac_conf:+-C "$pac_conf"} ${makepkg_conf:+-M "$makepkg_conf"} ${mirrors_conf:+-S "$mirrors_conf"} ${build_mirror:+-B "$build_mirror"} ${cache_dir:+-c "$cache_dir"} ${keep_flag})
${nosetarch} && chroot_args+=(${nosetarch:+-s})
exec chroot-run \ exec chroot-run \
${chroot_args[*]} \ ${chroot_args[*]} \

View file

@ -19,138 +19,115 @@ import ${LIBDIR}/util.sh
shopt -s nullglob shopt -s nullglob
makepkg_args=(-s --noconfirm -L) init_variables() {
repack=false default_makepkg_args=(-s --noconfirm -L --holdver)
update_first=false makepkg_args=("${default_makepkg_args[@]}")
clean_first=false repack=false
install_pkg= update_first=false
run_namcap=false clean_first=false
temp_chroot=false run_namcap=false
chrootdir= temp_chroot=false
passeddir= chrootdir=
declare -a install_pkgs passeddir=
declare -i ret=0 makepkg_user=
declare -ga install_pkgs
declare -gi ret=0
copy=$USER bindmounts_ro=()
[[ -n $SUDO_USER ]] && copy=$SUDO_USER bindmounts_rw=()
[[ -z "$copy" || $copy = root ]] && copy=copy
src_owner=${SUDO_USER:-$USER} copy=$USER
[[ -n ${SUDO_USER:-} ]] && copy=$SUDO_USER
[[ -z "$copy" || $copy = root ]] && copy=copy
src_owner=${SUDO_USER:-$USER}
}
usage() { usage() {
echo "Usage: ${0##*/} [options] -r <chrootdir> [--] [makepkg args]" echo "Usage: ${0##*/} [options] -r <chrootdir> [--] [makepkg args]"
echo ' Run this script in a PKGBUILD dir to build a package inside a' echo ' Run this script in a PKGBUILD dir to build a package inside a'
echo ' clean chroot. Arguments passed to this script after the' echo ' clean chroot. Arguments passed to this script after the'
echo ' end-of-options marker (--) will be passed to makepkg.' echo ' end-of-options marker (--) will be passed to makepkg.'
echo '' echo ''
echo ' The chroot dir consists of the following directories:' echo ' The chroot dir consists of the following directories:'
echo ' <chrootdir>/{root, copy} but only "root" is required' echo ' <chrootdir>/{root, copy} but only "root" is required'
echo ' by default. The working copy will be created as needed' echo ' by default. The working copy will be created as needed'
echo '' echo ''
echo ' The chroot "root" directory must be created via the following' echo 'The chroot "root" directory must be created via the following'
echo ' command:' echo 'command:'
echo ' mkchroot <chrootdir>/root base-devel' echo ' mkarchroot <chrootdir>/root base-devel'
echo '' echo ''
echo " Default makepkg args: ${makepkg_args[*]}" echo 'This script reads {SRC,SRCPKG,PKG,LOG}DEST, MAKEFLAGS and PACKAGER'
echo 'from makepkg.conf(5), if those variables are not part of the'
echo 'environment.'
echo '' echo ''
echo ' Flags:' echo "Default makepkg args: ${default_makepkg_args[*]}"
echo ' -h This help' echo ''
echo ' -c Clean the chroot before building' echo 'Flags:'
echo ' -u Update the working copy of the chroot before building' echo '-h This help'
echo ' This is useful for rebuilds without dirtying the pristine' echo '-c Clean the chroot before building'
echo ' chroot' echo '-d <dir> Bind directory into build chroot as read-write'
echo ' -r <dir> The chroot dir to use' echo '-D <dir> Bind directory into build chroot as read-only'
echo ' -I <pkg> Install a package into the working copy of the chroot' echo '-u Update the working copy of the chroot before building'
echo ' -l <copy> The directory to use as the working copy of the chroot' echo ' This is useful for rebuilds without dirtying the pristine'
echo ' Useful for maintaining multiple copies' echo ' chroot'
echo " Default: $copy" echo '-r <dir> The chroot dir to use'
echo ' -n Run namcap on the package' echo '-I <pkg> Install a package into the working copy of the chroot'
echo ' -T Build in a temporary directory' echo '-l <copy> The directory to use as the working copy of the chroot'
echo ' Useful for maintaining multiple copies'
echo " Default: $copy"
echo '-n Run namcap on the package'
echo '-T Build in a temporary directory'
echo '-U Run makepkg as a specified user'
exit 1 exit 1
} }
orig_argv=("$@") sync_chroot() {
local chrootdir=$1
while getopts 'hcur:I:l:nT' arg; do local copy=$2
case "$arg" in local copydir=''
c) clean_first=true ;; if [[ ${copy:0:1} = / ]]; then
u) update_first=true ;; copydir=$copy
r) passeddir="$OPTARG" ;; else
I) install_pkgs+=("$OPTARG") ;; copydir="$chrootdir/$copy"
l) copy="$OPTARG" ;;
n) run_namcap=true; makepkg_args+=(-i) ;;
T) temp_chroot=true; copy+="-$$" ;;
h|*) usage ;;
esac
done
[[ ! -f PKGBUILD && -z "${install_pkgs[*]}" ]] && die 'This must be run in a directory containing a PKGBUILD.'
check_root "$0" "${orig_argv[@]}"
# Canonicalize chrootdir, getting rid of trailing /
chrootdir=$(readlink -e "$passeddir")
[[ ! -d $chrootdir ]] && die "No chroot dir defined, or invalid path '%s'" "$passeddir"
[[ ! -d $chrootdir/root ]] && die "Missing chroot dir root directory. Try using: mkchroot %s/root base-devel" "$chrootdir"
# Detect chrootdir filesystem type
chroottype=$(stat -f -c %T "$chrootdir")
if [[ ${copy:0:1} = / ]]; then
copydir=$copy
else
copydir="$chrootdir/$copy"
fi
# Pass all arguments after -- right to makepkg
makepkg_args+=("${@:$OPTIND}")
# See if -R was passed to makepkg
for arg in "${@:OPTIND}"; do
case ${arg%%=*} in
-*R*|--repackage)
repack=true
break 2
;;
esac
done
load_user_info
# {{{ functions
create_chroot() {
# Lock the chroot we want to use. We'll keep this lock until we exit.
lock 9 "$copydir.lock" "Locking chroot copy [$copy]"
if [[ ! -d $copydir ]] || $clean_first; then
# Get a read lock on the root chroot to make
# sure we don't clone a half-updated chroot
slock 8 "$chrootdir/root.lock" "Locking clean chroot"
stat_busy "Creating clean working copy [$copy]"
if is_btrfs "$chrootdir" && ! mountpoint -q "$copydir"; then
subvolume_delete_recursive "$copydir" ||
die "Unable to delete subvolume %s" "$copydir"
btrfs subvolume snapshot "$chrootdir/root" "$copydir" >/dev/null ||
die "Unable to create subvolume %s" "$copydir"
else
mkdir -p "$copydir"
rsync -a --delete -q -W -x "$chrootdir/root/" "$copydir"
fi
stat_done
# Drop the read lock again
exec 8>&-
fi fi
if [[ "$chrootdir/root" -ef "$copydir" ]]; then
error 'Cannot sync copy with itself: %s' "$copydir"
return 1
fi
# Get a read lock on the root chroot to make
# sure we don't clone a half-updated chroot
slock 8 "$chrootdir/root.lock" \
"Locking clean chroot [%s]" "$chrootdir/root"
stat_busy "Synchronizing chroot copy [%s] -> [%s]" "$chrootdir/root" "$copydir"
if is_btrfs "$chrootdir" && ! mountpoint -q "$copydir"; then
subvolume_delete_recursive "$copydir" ||
die "Unable to delete subvolume %s" "$copydir"
btrfs subvolume snapshot "$chrootdir/root" "$copydir" >/dev/null ||
die "Unable to create subvolume %s" "$copydir"
else
mkdir -p "$copydir"
rsync -a --delete -q -W -x "$chrootdir/root/" "$copydir"
fi
stat_done
# Drop the read lock again
lock_close 8
# Update mtime # Update mtime
touch "$copydir" touch "$copydir"
} }
clean_temporary() { # Usage: delete_chroot $copydir [$copy]
stat_busy "Removing temporary copy [$copy]" delete_chroot() {
local copydir=$1
local copy=${1:-$2}
stat_busy "Removing chroot copy [%s]" "$copy"
if is_btrfs "$chrootdir" && ! mountpoint -q "$copydir"; then if is_btrfs "$chrootdir" && ! mountpoint -q "$copydir"; then
btrfs subvolume delete "$copydir" >/dev/null || subvolume_delete_recursive "$copydir" ||
die "Unable to delete subvolume %s" "$copydir" die "Unable to delete subvolume %s" "$copydir"
else else
# avoid change of filesystem in case of an umount failure # avoid change of filesystem in case of an umount failure
@ -163,24 +140,35 @@ clean_temporary() {
stat_done stat_done
} }
# Usage: install_packages $copydir $pkgs...
install_packages() { install_packages() {
local copydir=$1
local install_pkgs=("${@:2}")
local -a pkgnames local -a pkgnames
local ret local ret
pkgnames=("${install_pkgs[@]##*/}") pkgnames=("${install_pkgs[@]##*/}")
cp -- "${install_pkgs[@]}" "$copydir/root/" cp -- "${install_pkgs[@]}" "$copydir/root/"
chroot-run -r "${bindmounts_ro[*]}" -w "${bindmounts_rw[*]}" "$copydir" \
chroot-run "$copydir" \ pacman -U --noconfirm -- "${pkgnames[@]/#//root/}"
pacman -U --noconfirm -- "${pkgnames[@]/#//root/}"
ret=$? ret=$?
rm -- "${pkgnames[@]/#/$copydir/root/}" rm -- "${pkgnames[@]/#/$copydir/root/}"
# If there is no PKGBUILD we are done return $ret
[[ -f PKGBUILD ]] || exit $ret
} }
# Usage: prepare_chroot $copydir $HOME $repack $run_namcap
# Globals:
# - MAKEFLAGS
# - PACKAGER
prepare_chroot() { prepare_chroot() {
local copydir=$1
local USER_HOME=$2
local repack=$3
local run_namcap=$4
$repack || rm -rf "$copydir/build" $repack || rm -rf "$copydir/build"
local builduser_uid="${SUDO_UID:-$UID}" local builduser_uid="${SUDO_UID:-$UID}"
@ -204,7 +192,7 @@ prepare_chroot() {
sed -e '/^MAKEFLAGS=/d' -e '/^PACKAGER=/d' -i "$copydir/etc/makepkg.conf" sed -e '/^MAKEFLAGS=/d' -e '/^PACKAGER=/d' -i "$copydir/etc/makepkg.conf"
for x in BUILDDIR=/build PKGDEST=/pkgdest SRCPKGDEST=/srcpkgdest SRCDEST=/srcdest LOGDEST=/logdest \ for x in BUILDDIR=/build PKGDEST=/pkgdest SRCPKGDEST=/srcpkgdest SRCDEST=/srcdest LOGDEST=/logdest \
"MAKEFLAGS='$MAKEFLAGS'" "PACKAGER='$PACKAGER'" "MAKEFLAGS='${MAKEFLAGS:-}'" "PACKAGER='${PACKAGER:-}'"
do do
grep -q "^$x" "$copydir/etc/makepkg.conf" && continue grep -q "^$x" "$copydir/etc/makepkg.conf" && continue
echo "$x" >>"$copydir/etc/makepkg.conf" echo "$x" >>"$copydir/etc/makepkg.conf"
@ -220,9 +208,7 @@ EOF
{ {
printf '#!/bin/bash\n' printf '#!/bin/bash\n'
declare -f _chrootbuild declare -f _chrootbuild
printf '_chrootbuild' printf '_chrootbuild "$@" || exit\n'
printf ' %q' "${makepkg_args[@]}"
printf ' || exit\n'
if $run_namcap; then if $run_namcap; then
declare -f _chrootnamcap declare -f _chrootnamcap
@ -236,9 +222,6 @@ EOF
# so no global variables # so no global variables
_chrootbuild() { _chrootbuild() {
. /etc/profile . /etc/profile
# export HOME=/build
# cd /startdir
# sudo -u builduser makepkg "$@"
sudo -iu builduser bash -c 'cd /startdir; makepkg "$@"' -bash "$@" sudo -iu builduser bash -c 'cd /startdir; makepkg "$@"' -bash "$@"
} }
@ -250,37 +233,52 @@ _chrootnamcap() {
done done
} }
# Usage: download_sources $copydir $src_owner
# Globals:
# - SRCDEST
# - USER
download_sources() { download_sources() {
local copydir=$1
local src_owner=$2
local builddir="$(mktemp -d)" local builddir="$(mktemp -d)"
chmod 1777 "$builddir" chmod 1777 "$builddir"
# Ensure sources are downloaded # Ensure sources are downloaded
if [[ -n $SUDO_USER ]]; then makepkg_user=${makepkg_user:-$SUDO_USER}
sudo -u $SUDO_USER env SRCDEST="$SRCDEST" BUILDDIR="$builddir" \ if [[ -n $makepkg_user ]]; then
sudo -u "$makepkg_user" env SRCDEST="$SRCDEST" BUILDDIR="$builddir" \
makepkg --config="$copydir/etc/makepkg.conf" --verifysource -o makepkg --config="$copydir/etc/makepkg.conf" --verifysource -o
else else
( export SRCDEST BUILDDIR="$builddir" error "Running makepkg as root is not allowed."
makepkg --asroot --config="$copydir/etc/makepkg.conf" --verifysource -o exit 1
)
fi fi
(( $? != 0 )) && die "Could not download sources." (( $? != 0 )) && die "Could not download sources."
# Clean up garbage from verifysource # Clean up garbage from verifysource
rm -rf $builddir rm -rf "$builddir"
} }
# Usage: move_products $copydir $owner
# Globals:
# - PKGDEST
# - LOGDEST
move_products() { move_products() {
local copydir=$1
local src_owner=$2
local pkgfile
for pkgfile in "$copydir"/pkgdest/*; do for pkgfile in "$copydir"/pkgdest/*; do
chown "$src_owner" "$pkgfile" chown "$src_owner" "$pkgfile"
mv "$pkgfile" "$PKGDEST" mv "$pkgfile" "$PKGDEST"
# Fix broken symlink because of temporary chroot PKGDEST /pkgdest # Fix broken symlink because of temporary chroot PKGDEST /pkgdest
if [[ "$PWD" != "$PKGDEST" && -L "$PWD/${pkgfile##*/}" ]]; then if [[ "$PWD" != "$PKGDEST" && -L "$PWD/${pkgfile##*/}" ]]; then
rm "$PWD/${pkgfile##*/}"
ln -sf "$PKGDEST/${pkgfile##*/}" ln -sf "$PKGDEST/${pkgfile##*/}"
fi fi
done done
local l
for l in "$copydir"/logdest/*; do for l in "$copydir"/logdest/*; do
[[ $l == */logpipe.* ]] && continue [[ $l == */logpipe.* ]] && continue
chown "$src_owner" "$l" chown "$src_owner" "$l"
@ -294,49 +292,112 @@ move_products() {
} }
# }}} # }}}
umask 0022 orig_argv=("$0" "$@")
load_vars "$USER_HOME/.makepkg.conf" || load_vars /etc/makepkg.conf main() {
init_variables
# Use PKGBUILD directory if these don't exist local opts='hcur:I:l:nTD:d:U:'
[[ -d $PKGDEST ]] || PKGDEST=$PWD
[[ -d $SRCDEST ]] || SRCDEST=$PWD
[[ -d $SRCPKGDEST ]] || SRCPKGDEST=$PWD
[[ -d $LOGDEST ]] || LOGDEST=$PWD
create_chroot while getopts ${opts} arg; do
case "$arg" in
c) clean_first=true ;;
D) bindmounts_ro+=("$OPTARG") ;;
d) bindmounts_rw+=("$OPTARG") ;;
u) update_first=true ;;
r) passeddir="$OPTARG" ;;
I) install_pkgs+=("$OPTARG") ;;
l) copy="$OPTARG" ;;
n) run_namcap=true; makepkg_args+=(-i) ;;
T) temp_chroot=true; copy+="-$$" ;;
U) makepkg_user="$OPTARG" ;;
h|*) usage ;;
esac
done
$update_first && chroot-run \ [[ ! -f PKGBUILD && -z "${install_pkgs[*]}" ]] && die 'This must be run in a directory containing a PKGBUILD.'
-r "${mountargs_ro}" \ [[ -n $makepkg_user && -z $(id -u "$makepkg_user") ]] && die 'Invalid makepkg user.'
-w "${mountargs_rw}" \
"$copydir" \ check_root
# Canonicalize chrootdir, getting rid of trailing /
chrootdir=$(readlink -e "$passeddir")
[[ ! -d $chrootdir ]] && die "No chroot dir defined, or invalid path '%s'" "$passeddir"
[[ ! -d $chrootdir/root ]] && die "Missing chroot dir root directory. Try using: mkarchroot %s/root base-devel" "$chrootdir"
if [[ ${copy:0:1} = / ]]; then
copydir=$copy
else
copydir="$chrootdir/$copy"
fi
# Pass all arguments after -- right to makepkg
makepkg_args+=("${@:$OPTIND}")
# See if -R was passed to makepkg
for arg in "${@:OPTIND}"; do
case ${arg%%=*} in
-*R*|--repackage)
repack=true
break 2
;;
esac
done
load_user_info
umask 0022
load_vars "${XDG_CONFIG_HOME:-$USER_HOME/.config}/pacman/makepkg.conf" || load_vars "$USER_HOME/.makepkg.conf"
load_vars /etc/makepkg.conf
# Use PKGBUILD directory if these don't exist
[[ -d $PKGDEST ]] || PKGDEST=$PWD
[[ -d $SRCDEST ]] || SRCDEST=$PWD
[[ -d $SRCPKGDEST ]] || SRCPKGDEST=$PWD
[[ -d $LOGDEST ]] || LOGDEST=$PWD
# Lock the chroot we want to use. We'll keep this lock until we exit.
lock 9 "$copydir.lock" "Locking chroot copy [%s]" "$copy"
if [[ ! -d $copydir ]] || $clean_first; then
sync_chroot "$chrootdir" "$copy"
fi
$update_first && chroot-run -r "${bindmounts_ro[*]}" -w "${bindmounts_rw[*]}" "$copydir" \
pacman -Syu --noconfirm pacman -Syu --noconfirm
[[ -n ${install_pkgs[*]} ]] && install_packages if [[ -n ${install_pkgs[*]:-} ]]; then
install_packages "$copydir" "${install_pkgs[@]}"
download_sources ret=$?
# If there is no PKGBUILD we have done
prepare_chroot [[ -f PKGBUILD ]] || return $ret
mountargs_rw="${PWD}:/startdir,${SRCDEST}:/srcdest"
if chroot-run -r "${mountargs_ro}" \
-w "${mountargs_rw}" \
"$copydir" \
/chrootbuild; then
move_products
else
(( ret += 1 ))
fi
$temp_chroot && clean_temporary
if (( ret != 0 )); then
if $temp_chroot; then
die "Build failed"
else
die "Build failed, check %s/build" "$copydir"
fi fi
else
true download_sources "$copydir" "$src_owner"
fi
prepare_chroot "$copydir" "$USER_HOME" "$repack" "$run_namcap"
bindmounts_rw+=("${PWD}:/startdir" "${SRCDEST}:/srcdest")
if chroot-run -r "${bindmounts_ro[*]}" -w "${bindmounts_rw[*]}" "$copydir" \
/chrootbuild "${makepkg_args[@]}"; then
move_products "$copydir" "$src_owner"
else
(( ret += 1 ))
fi
$temp_chroot && delete_chroot "$copydir" "$copy"
if (( ret != 0 )); then
if $temp_chroot; then
die "Build failed"
else
die "Build failed, check %s/build" "$copydir"
fi
else
true
fi
}
main "$@"

View file

@ -76,12 +76,6 @@ along with systemd; If not, see <http://www.gnu.org/licenses/>.
you will upload.</para></listitem> you will upload.</para></listitem>
</varlistentry> </varlistentry>
<varlistentry>
<term><option>-c</option></term>
<listitem><para>Create new remote release.</para></listitem>
</varlistentry>
<varlistentry> <varlistentry>
<term><option>-l</option></term> <term><option>-l</option></term>

View file

@ -44,12 +44,12 @@ prepare_boot_extras(){
} }
prepare_grub(){ prepare_grub(){
local platform=i386-pc img='core.img' grub=$2/boot/grub efi=$2/efi/boot \ local platform=i386-pc img='core.img' grub=$3/boot/grub efi=$3/efi/boot \
data=$1/usr/share/grub lib=$1/usr/lib/grub prefix=/boot/grub lib=$1/usr/lib/grub prefix=/boot/grub theme=$2/usr/share/grub data=$1/usr/share/grub
prepare_dir ${grub}/${platform} prepare_dir ${grub}/${platform}
cp ${data}/cfg/*.cfg ${grub} cp ${theme}/cfg/*.cfg ${grub}
cp ${lib}/${platform}/* ${grub}/${platform} cp ${lib}/${platform}/* ${grub}/${platform}
@ -80,11 +80,11 @@ prepare_grub(){
grub-mkimage -d ${grub}/${platform} -o ${efi}/${img} -O ${platform} -p ${prefix} iso9660 grub-mkimage -d ${grub}/${platform} -o ${efi}/${img} -O ${platform} -p ${prefix} iso9660
prepare_dir ${grub}/themes prepare_dir ${grub}/themes
cp -r ${data}/themes/${iso_name}-live ${grub}/themes/ cp -r ${theme}/themes/${iso_name}-live ${grub}/themes/
cp ${data}/unicode.pf2 ${grub} cp ${data}/unicode.pf2 ${grub}
cp -r ${data}/{locales,tz,video} ${grub} cp -r ${theme}/{locales,tz} ${grub}
local size=8M mnt="${mnt_dir}/efiboot" efi_img="$2/efi.img" local size=4M mnt="${mnt_dir}/efiboot" efi_img="$3/efi.img"
msg2 "Creating fat image of %s ..." "${size}" msg2 "Creating fat image of %s ..." "${size}"
truncate -s ${size} "${efi_img}" truncate -s ${size} "${efi_img}"
mkfs.fat -n MISO_EFI "${efi_img}" &>/dev/null mkfs.fat -n MISO_EFI "${efi_img}" &>/dev/null

View file

@ -161,55 +161,35 @@ make_sfs() {
assemble_iso(){ assemble_iso(){
msg "Creating ISO image..." msg "Creating ISO image..."
local iso_publisher iso_app_id local iso_publisher="$(get_osname) <$(get_disturl)>" \
iso_app_id="$(get_osname) Live/Rescue CD" \
iso_publisher="$(get_osname) <$(get_disturl)>" mod_date=$(date -u +%Y-%m-%d-%H-%M-%S-00 | sed -e s/-//g)
iso_app_id="$(get_osname) Live/Rescue CD"
# xorriso -as mkisofs \
# --protective-msdos-label \
# -volid "${iso_label}" \
# -appid "${iso_app_id}" \
# -publisher "${iso_publisher}" \
# -preparer "Prepared by manjaro-tools/${0##*/}" \
# -e /efi.img \
# -b boot/grub/i386-pc/eltorito.img \
# -c boot.catalog \
# -no-emul-boot \
# -boot-load-size 4 \
# -boot-info-table \
# -graft-points \
# --grub2-boot-info \
# --grub2-mbr ${iso_root}/boot/grub/i386-pc/boot_hybrid.img \
# --sort-weight 0 / --sort-weight 1 /boot \
# -isohybrid-gpt-basdat \
# -eltorito-alt-boot \
# -output "${iso_dir}/${iso_file}" \
# "${iso_root}/"
xorriso -as mkisofs \ xorriso -as mkisofs \
--protective-msdos-label \ --modification-date=${mod_date} \
-volid "${iso_label}" \ --protective-msdos-label \
-appid "${iso_app_id}" \ -volid "${iso_label}" \
-publisher "${iso_publisher}" \ -appid "${iso_app_id}" \
-preparer "Prepared by manjaro-tools/${0##*/}" \ -publisher "${iso_publisher}" \
-b boot/grub/i386-pc/eltorito.img \ -preparer "Prepared by manjaro-tools/${0##*/}" \
-c boot.catalog \ -r -graft-points -no-pad \
-no-emul-boot \ --sort-weight 0 / \
-boot-load-size 4 \ --sort-weight 1 /boot \
-boot-info-table \ --grub2-mbr ${iso_root}/boot/grub/i386-pc/boot_hybrid.img \
-graft-points \ -partition_offset 16 \
--grub2-boot-info \ -b boot/grub/i386-pc/eltorito.img \
--grub2-mbr ${iso_root}/boot/grub/i386-pc/boot_hybrid.img \ -c boot.catalog \
--sort-weight 0 / --sort-weight 1 /boot \ -no-emul-boot -boot-load-size 4 -boot-info-table --grub2-boot-info \
-eltorito-alt-boot \ -eltorito-alt-boot \
-efi-boot-part --efi-boot-image \ -append_partition 2 0xef ${iso_root}/efi.img \
-e efi.img \ -e --interval:appended_partition_2:all:: \
-no-emul-boot \ -no-emul-boot \
-isohybrid-gpt-basdat \ -iso-level 3 \
-output "${iso_dir}/${iso_file}" \ -o ${iso_dir}/${iso_file} \
"${iso_root}/" ${iso_root}/
# arg to add with xorriso-1.4.7
# -iso_mbr_part_type 0x00
} }
# Build ISO # Build ISO
@ -408,15 +388,18 @@ configure_grub(){
-i $1 -i $1
} }
configure_grub_theme(){
sed -e "s|@ISO_NAME@|${iso_name}|" -i "$1"
}
make_grub(){ make_grub(){
if [[ ! -e ${work_dir}/build.${FUNCNAME} ]]; then if [[ ! -e ${work_dir}/build.${FUNCNAME} ]]; then
msg "Prepare [/iso/boot/grub]" msg "Prepare [/iso/boot/grub]"
local path="${work_dir}/rootfs" prepare_grub "${work_dir}/rootfs" "${work_dir}/livefs" "${iso_root}"
prepare_grub "${path}" "${iso_root}"
configure_grub "${iso_root}/boot/grub/kernels.cfg" configure_grub "${iso_root}/boot/grub/kernels.cfg"
configure_grub_theme "${iso_root}/boot/grub/variable.cfg"
: > ${work_dir}/build.${FUNCNAME} : > ${work_dir}/build.${FUNCNAME}
msg "Done [/iso/boot/grub]" msg "Done [/iso/boot/grub]"

View file

@ -11,11 +11,9 @@
export LC_MESSAGES=C export LC_MESSAGES=C
export LANG=C export LANG=C
disable_colors(){ declare ALL_OFF='' BOLD='' BLUE='' GREEN='' RED='' YELLOW=''
unset ALL_OFF BOLD BLUE GREEN RED YELLOW
}
enable_colors(){ if [[ -t 2 ]]; then
# prefer terminal safe colored and bold text when tput is supported # prefer terminal safe colored and bold text when tput is supported
if tput setaf 0 &>/dev/null; then if tput setaf 0 &>/dev/null; then
ALL_OFF="$(tput sgr0)" ALL_OFF="$(tput sgr0)"
@ -32,14 +30,8 @@ enable_colors(){
YELLOW="${BOLD}\e[33m" YELLOW="${BOLD}\e[33m"
BLUE="${BOLD}\e[34m" BLUE="${BOLD}\e[34m"
fi fi
readonly ALL_OFF BOLD BLUE GREEN RED YELLOW
}
if [[ -t 2 ]]; then
enable_colors
else
disable_colors
fi fi
readonly ALL_OFF BOLD BLUE GREEN RED YELLOW
plain() { plain() {
local mesg=$1; shift local mesg=$1; shift
@ -73,13 +65,42 @@ error() {
stat_busy() { stat_busy() {
local mesg=$1; shift local mesg=$1; shift
printf "${GREEN}==>${ALL_OFF}${BOLD} ${mesg}...${ALL_OFF}" >&2 printf "${GREEN}==>${ALL_OFF}${BOLD} ${mesg}...${ALL_OFF}" "$@" >&2
} }
stat_done() { stat_done() {
printf "${BOLD}done${ALL_OFF}\n" >&2 printf "${BOLD}done${ALL_OFF}\n" >&2
} }
lock_close() {
local fd=$1
exec {fd}>&-
}
lock() {
if ! [[ "/dev/fd/$1" -ef "$2" ]]; then
mkdir -p -- "$(dirname -- "$2")"
eval "exec $1>"'"$2"'
fi
if ! flock -n $1; then
stat_busy "$3"
flock $1
stat_done
fi
}
slock() {
if ! [[ "/dev/fd/$1" -ef "$2" ]]; then
mkdir -p -- "$(dirname -- "$2")"
eval "exec $1>"'"$2"'
fi
if ! flock -sn $1; then
stat_busy "$3"
flock -s $1
stat_done
fi
}
cleanup() { cleanup() {
exit ${1:-0} exit ${1:-0}
} }

View file

@ -370,7 +370,7 @@ write_calamares_yaml(){
for conf in "${yaml_dir}"/etc/calamares/modules/*.conf "${yaml_dir}"/etc/calamares/settings.conf; do for conf in "${yaml_dir}"/etc/calamares/modules/*.conf "${yaml_dir}"/etc/calamares/settings.conf; do
check_yaml "$conf" check_yaml "$conf"
done done
fi fi
} }
write_netgroup_yaml(){ write_netgroup_yaml(){
@ -385,7 +385,7 @@ write_netgroup_yaml(){
for p in ${packages[@]};do for p in ${packages[@]};do
echo " - $p" >> "$2" echo " - $p" >> "$2"
done done
${validate} && check_yaml "$2" ${validate} && check_yaml "$2"
} }
write_pacman_group_yaml(){ write_pacman_group_yaml(){

View file

@ -123,7 +123,6 @@ get_timer(){
echo $(date +%s) echo $(date +%s)
} }
# $1: start timer # $1: start timer
elapsed_time(){ elapsed_time(){
echo $(echo $1 $(get_timer) | awk '{ printf "%0.2f",($2-$1)/60 }') echo $(echo $1 $(get_timer) | awk '{ printf "%0.2f",($2-$1)/60 }')
@ -133,33 +132,6 @@ show_elapsed_time(){
info "Time %s: %s minutes" "$1" "$(elapsed_time $2)" info "Time %s: %s minutes" "$1" "$(elapsed_time $2)"
} }
lock() {
eval "exec $1>"'"$2"'
if ! flock -n $1; then
stat_busy "$3"
flock $1
stat_done
fi
}
slock() {
eval "exec $1>"'"$2"'
if ! flock -sn $1; then
stat_busy "$3"
flock -s $1
stat_done
fi
}
check_root() {
(( EUID == 0 )) && return
if type -P sudo >/dev/null; then
exec sudo -- "$@"
else
exec su root -c "$(printf ' %q' "$@")"
fi
}
copy_mirrorlist(){ copy_mirrorlist(){
cp -a /etc/pacman.d/mirrorlist "$1/etc/pacman.d/" cp -a /etc/pacman.d/mirrorlist "$1/etc/pacman.d/"
} }
@ -690,29 +662,6 @@ show_config(){
fi fi
} }
# $1: chroot
kill_chroot_process(){
# enable to have more debug info
#msg "machine-id (etc): $(cat $1/etc/machine-id)"
#[[ -e $1/var/lib/dbus/machine-id ]] && msg "machine-id (lib): $(cat $1/var/lib/dbus/machine-id)"
#msg "running processes: "
#lsof | grep $1
local prefix="$1" flink pid name
for root_dir in /proc/*/root; do
flink=$(readlink $root_dir)
if [ "x$flink" != "x" ]; then
if [ "x${flink:0:${#prefix}}" = "x$prefix" ]; then
# this process is in the chroot...
pid=$(basename $(dirname "$root_dir"))
name=$(ps -p $pid -o comm=)
info "Killing chroot process: %s (%s)" "$name" "$pid"
kill -9 "$pid"
fi
fi
done
}
create_min_fs(){ create_min_fs(){
msg "Creating install root at %s" "$1" msg "Creating install root at %s" "$1"
mkdir -m 0755 -p $1/var/{cache/pacman/pkg,lib/pacman,log} $1/{dev,run,etc} mkdir -m 0755 -p $1/var/{cache/pacman/pkg,lib/pacman,log} $1/{dev,run,etc}
@ -758,8 +707,17 @@ run(){
fi fi
} }
check_root() {
(( EUID == 0 )) && return
if type -P sudo >/dev/null; then
exec sudo -- "${orig_argv[@]}"
else
exec su root -c "$(printf ' %q' "${orig_argv[@]}")"
fi
}
is_btrfs() { is_btrfs() {
[[ -e "$1" && "$(stat -f -c %T "$1")" == btrfs ]] [[ -e "$1" && "$(stat -f -c %T "$1")" == btrfs ]]
} }
subvolume_delete_recursive() { subvolume_delete_recursive() {
@ -776,3 +734,26 @@ subvolume_delete_recursive() {
return 0 return 0
} }
# $1: chroot
# kill_chroot_process(){
# # enable to have more debug info
# #msg "machine-id (etc): $(cat $1/etc/machine-id)"
# #[[ -e $1/var/lib/dbus/machine-id ]] && msg "machine-id (lib): $(cat $1/var/lib/dbus/machine-id)"
# #msg "running processes: "
# #lsof | grep $1
#
# local prefix="$1" flink pid name
# for root_dir in /proc/*/root; do
# flink=$(readlink $root_dir)
# if [ "x$flink" != "x" ]; then
# if [ "x${flink:0:${#prefix}}" = "x$prefix" ]; then
# # this process is in the chroot...
# pid=$(basename $(dirname "$root_dir"))
# name=$(ps -p $pid -o comm=)
# info "Killing chroot process: %s (%s)" "$name" "$pid"
# kill -9 "$pid"
# fi
# fi
# done
# }