mirror of
https://gitlab.archlinux.org/archlinux/devtools.git
synced 2025-09-13 09:56:18 +02:00
Compare commits
17 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
f73c1f172f | ||
![]() |
eec7fcf965 | ||
![]() |
c53a3e8017 | ||
![]() |
45f87aa9d5 | ||
![]() |
66553e7e07 | ||
![]() |
cda9cf436b | ||
![]() |
06c98c1b54 | ||
![]() |
e10ce7fc70 | ||
![]() |
ff48401963 | ||
![]() |
15f16162fb | ||
![]() |
fea14fa286 | ||
![]() |
4bafd641ab | ||
![]() |
58968cfaa2 | ||
![]() |
c8147a3512 | ||
![]() |
76dec8507e | ||
![]() |
9727b684e6 | ||
![]() |
e3fe7134e2 |
@@ -9,8 +9,7 @@
|
||||
# GNU General Public License for more details.
|
||||
|
||||
m4_include(lib/common.sh)
|
||||
|
||||
CHROOT_VERSION='v3'
|
||||
m4_include(lib/archroot.sh)
|
||||
|
||||
working_dir=''
|
||||
|
||||
@@ -26,8 +25,6 @@ usage() {
|
||||
exit 1
|
||||
}
|
||||
|
||||
orig_argv=("$@")
|
||||
|
||||
while getopts 'hC:M:c:' arg; do
|
||||
case "$arg" in
|
||||
C) pac_conf="$OPTARG" ;;
|
||||
@@ -40,7 +37,7 @@ done
|
||||
shift $(($OPTIND - 1))
|
||||
|
||||
(( $# < 1 )) && die 'You must specify a directory.'
|
||||
check_root "$0" "${orig_argv[@]}"
|
||||
check_root
|
||||
|
||||
working_dir=$(readlink -f "$1")
|
||||
shift 1
|
||||
|
@@ -1,6 +1,7 @@
|
||||
#!/bin/bash
|
||||
|
||||
m4_include(lib/common.sh)
|
||||
m4_include(lib/archroot.sh)
|
||||
|
||||
base_packages=(base-devel)
|
||||
makechrootpkg_args=(-c -n)
|
||||
@@ -29,8 +30,6 @@ usage() {
|
||||
exit 1
|
||||
}
|
||||
|
||||
orig_argv=("$@")
|
||||
|
||||
while getopts 'hcr:' arg; do
|
||||
case "${arg}" in
|
||||
c) clean_first=true ;;
|
||||
@@ -39,7 +38,7 @@ while getopts 'hcr:' arg; do
|
||||
esac
|
||||
done
|
||||
|
||||
check_root "$0" "${orig_argv[@]}"
|
||||
check_root
|
||||
|
||||
# Pass all arguments after -- right to makepkg
|
||||
makechrootpkg_args+=("${@:$OPTIND}")
|
||||
@@ -53,9 +52,7 @@ if ${clean_first} || [[ ! -d "${chroots}/${repo}-${arch}" ]]; then
|
||||
|
||||
lock 9 "$copy.lock" "Locking chroot copy '$copy'"
|
||||
|
||||
if [[ "$(stat -f -c %T "${copy}")" == btrfs ]]; then
|
||||
{ type -P btrfs && btrfs subvolume delete "${copy}"; } &>/dev/null
|
||||
fi
|
||||
subvolume_delete_recursive "${copy}"
|
||||
rm -rf --one-file-system "${copy}"
|
||||
done
|
||||
exec 9>&-
|
||||
|
42
lib/archroot.sh
Normal file
42
lib/archroot.sh
Normal file
@@ -0,0 +1,42 @@
|
||||
CHROOT_VERSION='v4'
|
||||
|
||||
##
|
||||
# usage : check_root
|
||||
##
|
||||
orig_argv=("$0" "$@")
|
||||
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
|
||||
}
|
||||
|
||||
##
|
||||
# usage : is_btrfs( $path )
|
||||
# return : whether $path is on a btrfs
|
||||
##
|
||||
is_btrfs() {
|
||||
[[ -e "$1" && "$(stat -f -c %T "$1")" == btrfs ]]
|
||||
}
|
||||
|
||||
##
|
||||
# usage : subvolume_delete_recursive( $path )
|
||||
#
|
||||
# Find all btrfs subvolumes under and including $path and delete them.
|
||||
##
|
||||
subvolume_delete_recursive() {
|
||||
local subvol
|
||||
|
||||
is_btrfs "$1" || return 0
|
||||
|
||||
while IFS= read -d $'\0' -r subvol; do
|
||||
if ! btrfs subvolume delete "$subvol" &>/dev/null; then
|
||||
error "Unable to delete subvolume %s" "$subvol"
|
||||
return 1
|
||||
fi
|
||||
done < <(find "$1" -xdev -depth -inum 256 -print0)
|
||||
|
||||
return 0
|
||||
}
|
@@ -162,8 +162,6 @@ slock() {
|
||||
# usage: pkgver_equal( $pkgver1, $pkgver2 )
|
||||
##
|
||||
pkgver_equal() {
|
||||
local left right
|
||||
|
||||
if [[ $1 = *-* && $2 = *-* ]]; then
|
||||
# if both versions have a pkgrel, then they must be an exact match
|
||||
[[ $1 = "$2" ]]
|
||||
@@ -182,7 +180,7 @@ pkgver_equal() {
|
||||
find_cached_package() {
|
||||
local searchdirs=("$PWD" "$PKGDEST") results=()
|
||||
local targetname=$1 targetver=$2 targetarch=$3
|
||||
local dir pkg pkgbasename pkgparts name ver rel arch size r results
|
||||
local dir pkg pkgbasename name ver rel arch r results
|
||||
|
||||
for dir in "${searchdirs[@]}"; do
|
||||
[[ -d $dir ]] || continue
|
||||
@@ -229,15 +227,3 @@ find_cached_package() {
|
||||
return 1
|
||||
esac
|
||||
}
|
||||
|
||||
##
|
||||
# usage : check_root ("$0" "$@")
|
||||
##
|
||||
check_root() {
|
||||
(( EUID == 0 )) && return
|
||||
if type -P sudo >/dev/null; then
|
||||
exec sudo -- "$@"
|
||||
else
|
||||
exec su root -c "$(printf ' %q' "$@")"
|
||||
fi
|
||||
}
|
||||
|
@@ -9,6 +9,7 @@
|
||||
# GNU General Public License for more details.
|
||||
|
||||
m4_include(lib/common.sh)
|
||||
m4_include(lib/archroot.sh)
|
||||
|
||||
shopt -s nullglob
|
||||
|
||||
@@ -21,6 +22,7 @@ run_namcap=false
|
||||
temp_chroot=false
|
||||
chrootdir=
|
||||
passeddir=
|
||||
makepkg_user=
|
||||
declare -a install_pkgs
|
||||
declare -i ret=0
|
||||
|
||||
@@ -46,6 +48,10 @@ usage() {
|
||||
echo 'command:'
|
||||
echo ' mkarchroot <chrootdir>/root base-devel'
|
||||
echo ''
|
||||
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 "Default makepkg args: ${makepkg_args[*]}"
|
||||
echo ''
|
||||
echo 'Flags:'
|
||||
@@ -63,6 +69,7 @@ usage() {
|
||||
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
|
||||
}
|
||||
|
||||
@@ -89,11 +96,9 @@ create_chroot() {
|
||||
slock 8 "$chrootdir/root.lock" "Locking clean chroot"
|
||||
|
||||
stat_busy "Creating clean working copy [$copy]"
|
||||
if [[ "$chroottype" == btrfs ]] && ! mountpoint -q "$copydir"; then
|
||||
if [[ -d $copydir ]]; then
|
||||
btrfs subvolume delete "$copydir" >/dev/null ||
|
||||
die "Unable to delete subvolume %s" "$copydir"
|
||||
fi
|
||||
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
|
||||
@@ -112,7 +117,7 @@ create_chroot() {
|
||||
|
||||
clean_temporary() {
|
||||
stat_busy "Removing temporary copy [$copy]"
|
||||
if [[ "$chroottype" == btrfs ]] && ! mountpoint -q "$copydir"; then
|
||||
if is_btrfs "$chrootdir" && ! mountpoint -q "$copydir"; then
|
||||
btrfs subvolume delete "$copydir" >/dev/null ||
|
||||
die "Unable to delete subvolume %s" "$copydir"
|
||||
else
|
||||
@@ -173,7 +178,6 @@ prepare_chroot() {
|
||||
done
|
||||
|
||||
cat > "$copydir/etc/sudoers.d/builduser-pacman" <<EOF
|
||||
Defaults env_keep += "HOME"
|
||||
builduser ALL = NOPASSWD: /usr/bin/pacman
|
||||
EOF
|
||||
chmod 440 "$copydir/etc/sudoers.d/builduser-pacman"
|
||||
@@ -199,9 +203,7 @@ EOF
|
||||
# so no global variables
|
||||
_chrootbuild() {
|
||||
. /etc/profile
|
||||
export HOME=/build
|
||||
cd /startdir
|
||||
sudo -u builduser makepkg "$@"
|
||||
sudo -iu builduser bash -c 'cd /startdir; makepkg "$@"' -bash "$@"
|
||||
}
|
||||
|
||||
_chrootnamcap() {
|
||||
@@ -217,13 +219,13 @@ download_sources() {
|
||||
chmod 1777 "$builddir"
|
||||
|
||||
# Ensure sources are downloaded
|
||||
if [[ -n $SUDO_USER ]]; then
|
||||
sudo -u $SUDO_USER env SRCDEST="$SRCDEST" BUILDDIR="$builddir" \
|
||||
makepkg_user=${makepkg_user:-$SUDO_USER}
|
||||
if [[ -n $makepkg_user ]]; then
|
||||
sudo -u "$makepkg_user" env SRCDEST="$SRCDEST" BUILDDIR="$builddir" \
|
||||
makepkg --config="$copydir/etc/makepkg.conf" --verifysource -o
|
||||
else
|
||||
( export SRCDEST BUILDDIR="$builddir"
|
||||
makepkg --asroot --config="$copydir/etc/makepkg.conf" --verifysource -o
|
||||
)
|
||||
error "Running makepkg as root is not allowed."
|
||||
exit 1
|
||||
fi
|
||||
(( $? != 0 )) && die "Could not download sources."
|
||||
|
||||
@@ -235,6 +237,11 @@ move_products() {
|
||||
for pkgfile in "$copydir"/pkgdest/*; do
|
||||
chown "$src_owner" "$pkgfile"
|
||||
mv "$pkgfile" "$PKGDEST"
|
||||
|
||||
# Fix broken symlink because of temporary chroot PKGDEST /pkgdest
|
||||
if [[ "$PWD" != "$PKGDEST" && -L "$PWD/${pkgfile##*/}" ]]; then
|
||||
ln -sf "$PKGDEST/${pkgfile##*/}"
|
||||
fi
|
||||
done
|
||||
|
||||
for l in "$copydir"/logdest/*; do
|
||||
@@ -250,9 +257,7 @@ move_products() {
|
||||
}
|
||||
# }}}
|
||||
|
||||
orig_argv=("$@")
|
||||
|
||||
while getopts 'hcur:I:l:nTD:d:' arg; do
|
||||
while getopts 'hcur:I:l:nTD:d:U:' arg; do
|
||||
case "$arg" in
|
||||
c) clean_first=true ;;
|
||||
D) bindmounts_ro+=(--bind-ro="$OPTARG") ;;
|
||||
@@ -263,22 +268,21 @@ while getopts 'hcur:I:l:nTD:d:' arg; do
|
||||
l) copy="$OPTARG" ;;
|
||||
n) run_namcap=true; makepkg_args+=(-i) ;;
|
||||
T) temp_chroot=true; copy+="-$$" ;;
|
||||
U) makepkg_user="$OPTARG" ;;
|
||||
h|*) usage ;;
|
||||
esac
|
||||
done
|
||||
|
||||
[[ ! -f PKGBUILD && -z "${install_pkgs[*]}" ]] && die 'This must be run in a directory containing a PKGBUILD.'
|
||||
[[ -n $makepkg_user && -z $(id -u "$makepkg_user") ]] && die 'Invalid makepkg user.'
|
||||
|
||||
check_root "$0" "${orig_argv[@]}"
|
||||
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"
|
||||
|
||||
# Detect chrootdir filesystem type
|
||||
chroottype=$(stat -f -c %T "$chrootdir")
|
||||
|
||||
if [[ ${copy:0:1} = / ]]; then
|
||||
copydir=$copy
|
||||
else
|
||||
@@ -306,7 +310,7 @@ fi
|
||||
|
||||
umask 0022
|
||||
|
||||
load_vars "$USER_HOME/.makepkg.conf"
|
||||
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
|
||||
|
@@ -9,8 +9,7 @@
|
||||
# GNU General Public License for more details.
|
||||
|
||||
m4_include(lib/common.sh)
|
||||
|
||||
CHROOT_VERSION='v3'
|
||||
m4_include(lib/archroot.sh)
|
||||
|
||||
working_dir=''
|
||||
|
||||
@@ -24,8 +23,6 @@ usage() {
|
||||
exit 1
|
||||
}
|
||||
|
||||
orig_argv=("$@")
|
||||
|
||||
while getopts 'hC:M:c:' arg; do
|
||||
case "$arg" in
|
||||
C) pac_conf="$OPTARG" ;;
|
||||
@@ -39,7 +36,7 @@ shift $(($OPTIND - 1))
|
||||
|
||||
(( $# < 2 )) && die 'You must specify a directory and one or more packages.'
|
||||
|
||||
check_root "$0" "${orig_argv[@]}"
|
||||
check_root
|
||||
|
||||
working_dir="$(readlink -f $1)"
|
||||
shift 1
|
||||
@@ -60,7 +57,7 @@ mkdir -p "$working_dir"
|
||||
|
||||
lock 9 "${working_dir}.lock" "Locking chroot"
|
||||
|
||||
if [[ $(stat -f -c %T "$working_dir") == btrfs ]]; then
|
||||
if is_btrfs "$working_dir"; then
|
||||
rmdir "$working_dir"
|
||||
if ! btrfs subvolume create "$working_dir"; then
|
||||
die "Couldn't create subvolume for '%s'" "$working_dir"
|
||||
@@ -72,7 +69,7 @@ pacstrap -GMcd ${pac_conf:+-C "$pac_conf"} "$working_dir" \
|
||||
"${cache_dirs[@]/#/--cachedir=}" "$@" || die 'Failed to install all packages'
|
||||
|
||||
printf '%s.UTF-8 UTF-8\n' en_US de_DE > "$working_dir/etc/locale.gen"
|
||||
echo 'LANG=C' > "$working_dir/etc/locale.conf"
|
||||
echo 'LANG=en_US.UTF-8' > "$working_dir/etc/locale.conf"
|
||||
echo "$CHROOT_VERSION" > "$working_dir/.arch-chroot"
|
||||
|
||||
systemd-machine-id-setup --root="$working_dir"
|
||||
|
Reference in New Issue
Block a user