mirror of
https://gitlab.archlinux.org/archlinux/devtools.git
synced 2025-10-27 14:02:22 +01:00
Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f73c1f172f | ||
|
|
eec7fcf965 | ||
|
|
c53a3e8017 | ||
|
|
45f87aa9d5 | ||
|
|
66553e7e07 | ||
|
|
cda9cf436b | ||
|
|
06c98c1b54 |
@@ -9,8 +9,7 @@
|
|||||||
# GNU General Public License for more details.
|
# GNU General Public License for more details.
|
||||||
|
|
||||||
m4_include(lib/common.sh)
|
m4_include(lib/common.sh)
|
||||||
|
m4_include(lib/archroot.sh)
|
||||||
CHROOT_VERSION='v4'
|
|
||||||
|
|
||||||
working_dir=''
|
working_dir=''
|
||||||
|
|
||||||
@@ -26,8 +25,6 @@ usage() {
|
|||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
orig_argv=("$@")
|
|
||||||
|
|
||||||
while getopts 'hC:M:c:' arg; do
|
while getopts 'hC:M:c:' arg; do
|
||||||
case "$arg" in
|
case "$arg" in
|
||||||
C) pac_conf="$OPTARG" ;;
|
C) pac_conf="$OPTARG" ;;
|
||||||
@@ -40,7 +37,7 @@ 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
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
m4_include(lib/common.sh)
|
m4_include(lib/common.sh)
|
||||||
|
m4_include(lib/archroot.sh)
|
||||||
|
|
||||||
base_packages=(base-devel)
|
base_packages=(base-devel)
|
||||||
makechrootpkg_args=(-c -n)
|
makechrootpkg_args=(-c -n)
|
||||||
@@ -29,8 +30,6 @@ usage() {
|
|||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
orig_argv=("$@")
|
|
||||||
|
|
||||||
while getopts 'hcr:' arg; do
|
while getopts 'hcr:' arg; do
|
||||||
case "${arg}" in
|
case "${arg}" in
|
||||||
c) clean_first=true ;;
|
c) clean_first=true ;;
|
||||||
@@ -39,7 +38,7 @@ while getopts 'hcr:' arg; do
|
|||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
check_root "$0" "${orig_argv[@]}"
|
check_root
|
||||||
|
|
||||||
# Pass all arguments after -- right to makepkg
|
# Pass all arguments after -- right to makepkg
|
||||||
makechrootpkg_args+=("${@:$OPTIND}")
|
makechrootpkg_args+=("${@:$OPTIND}")
|
||||||
@@ -53,9 +52,7 @@ if ${clean_first} || [[ ! -d "${chroots}/${repo}-${arch}" ]]; then
|
|||||||
|
|
||||||
lock 9 "$copy.lock" "Locking chroot copy '$copy'"
|
lock 9 "$copy.lock" "Locking chroot copy '$copy'"
|
||||||
|
|
||||||
if [[ "$(stat -f -c %T "${copy}")" == btrfs ]]; then
|
subvolume_delete_recursive "${copy}"
|
||||||
{ type -P btrfs && btrfs subvolume delete "${copy}"; } &>/dev/null
|
|
||||||
fi
|
|
||||||
rm -rf --one-file-system "${copy}"
|
rm -rf --one-file-system "${copy}"
|
||||||
done
|
done
|
||||||
exec 9>&-
|
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
|
||||||
|
}
|
||||||
@@ -227,15 +227,3 @@ find_cached_package() {
|
|||||||
return 1
|
return 1
|
||||||
esac
|
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.
|
# GNU General Public License for more details.
|
||||||
|
|
||||||
m4_include(lib/common.sh)
|
m4_include(lib/common.sh)
|
||||||
|
m4_include(lib/archroot.sh)
|
||||||
|
|
||||||
shopt -s nullglob
|
shopt -s nullglob
|
||||||
|
|
||||||
@@ -21,6 +22,7 @@ run_namcap=false
|
|||||||
temp_chroot=false
|
temp_chroot=false
|
||||||
chrootdir=
|
chrootdir=
|
||||||
passeddir=
|
passeddir=
|
||||||
|
makepkg_user=
|
||||||
declare -a install_pkgs
|
declare -a install_pkgs
|
||||||
declare -i ret=0
|
declare -i ret=0
|
||||||
|
|
||||||
@@ -46,6 +48,10 @@ usage() {
|
|||||||
echo 'command:'
|
echo 'command:'
|
||||||
echo ' mkarchroot <chrootdir>/root base-devel'
|
echo ' mkarchroot <chrootdir>/root base-devel'
|
||||||
echo ''
|
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 "Default makepkg args: ${makepkg_args[*]}"
|
||||||
echo ''
|
echo ''
|
||||||
echo 'Flags:'
|
echo 'Flags:'
|
||||||
@@ -63,6 +69,7 @@ usage() {
|
|||||||
echo " Default: $copy"
|
echo " Default: $copy"
|
||||||
echo '-n Run namcap on the package'
|
echo '-n Run namcap on the package'
|
||||||
echo '-T Build in a temporary directory'
|
echo '-T Build in a temporary directory'
|
||||||
|
echo '-U Run makepkg as a specified user'
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -89,11 +96,9 @@ create_chroot() {
|
|||||||
slock 8 "$chrootdir/root.lock" "Locking clean chroot"
|
slock 8 "$chrootdir/root.lock" "Locking clean chroot"
|
||||||
|
|
||||||
stat_busy "Creating clean working copy [$copy]"
|
stat_busy "Creating clean working copy [$copy]"
|
||||||
if [[ "$chroottype" == btrfs ]] && ! mountpoint -q "$copydir"; then
|
if is_btrfs "$chrootdir" && ! mountpoint -q "$copydir"; then
|
||||||
if [[ -d $copydir ]]; then
|
subvolume_delete_recursive "$copydir" ||
|
||||||
btrfs subvolume delete "$copydir" >/dev/null ||
|
die "Unable to delete subvolume %s" "$copydir"
|
||||||
die "Unable to delete subvolume %s" "$copydir"
|
|
||||||
fi
|
|
||||||
btrfs subvolume snapshot "$chrootdir/root" "$copydir" >/dev/null ||
|
btrfs subvolume snapshot "$chrootdir/root" "$copydir" >/dev/null ||
|
||||||
die "Unable to create subvolume %s" "$copydir"
|
die "Unable to create subvolume %s" "$copydir"
|
||||||
else
|
else
|
||||||
@@ -112,7 +117,7 @@ create_chroot() {
|
|||||||
|
|
||||||
clean_temporary() {
|
clean_temporary() {
|
||||||
stat_busy "Removing temporary copy [$copy]"
|
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 ||
|
btrfs subvolume delete "$copydir" >/dev/null ||
|
||||||
die "Unable to delete subvolume %s" "$copydir"
|
die "Unable to delete subvolume %s" "$copydir"
|
||||||
else
|
else
|
||||||
@@ -214,13 +219,13 @@ download_sources() {
|
|||||||
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."
|
||||||
|
|
||||||
@@ -252,9 +257,7 @@ move_products() {
|
|||||||
}
|
}
|
||||||
# }}}
|
# }}}
|
||||||
|
|
||||||
orig_argv=("$@")
|
while getopts 'hcur:I:l:nTD:d:U:' arg; do
|
||||||
|
|
||||||
while getopts 'hcur:I:l:nTD:d:' arg; do
|
|
||||||
case "$arg" in
|
case "$arg" in
|
||||||
c) clean_first=true ;;
|
c) clean_first=true ;;
|
||||||
D) bindmounts_ro+=(--bind-ro="$OPTARG") ;;
|
D) bindmounts_ro+=(--bind-ro="$OPTARG") ;;
|
||||||
@@ -265,22 +268,21 @@ while getopts 'hcur:I:l:nTD:d:' arg; do
|
|||||||
l) copy="$OPTARG" ;;
|
l) copy="$OPTARG" ;;
|
||||||
n) run_namcap=true; makepkg_args+=(-i) ;;
|
n) run_namcap=true; makepkg_args+=(-i) ;;
|
||||||
T) temp_chroot=true; copy+="-$$" ;;
|
T) temp_chroot=true; copy+="-$$" ;;
|
||||||
|
U) makepkg_user="$OPTARG" ;;
|
||||||
h|*) usage ;;
|
h|*) usage ;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
[[ ! -f PKGBUILD && -z "${install_pkgs[*]}" ]] && die 'This must be run in a directory containing a PKGBUILD.'
|
[[ ! -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 /
|
# Canonicalize chrootdir, getting rid of trailing /
|
||||||
chrootdir=$(readlink -e "$passeddir")
|
chrootdir=$(readlink -e "$passeddir")
|
||||||
[[ ! -d $chrootdir ]] && die "No chroot dir defined, or invalid path '%s'" "$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"
|
[[ ! -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
|
if [[ ${copy:0:1} = / ]]; then
|
||||||
copydir=$copy
|
copydir=$copy
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -9,8 +9,7 @@
|
|||||||
# GNU General Public License for more details.
|
# GNU General Public License for more details.
|
||||||
|
|
||||||
m4_include(lib/common.sh)
|
m4_include(lib/common.sh)
|
||||||
|
m4_include(lib/archroot.sh)
|
||||||
CHROOT_VERSION='v4'
|
|
||||||
|
|
||||||
working_dir=''
|
working_dir=''
|
||||||
|
|
||||||
@@ -24,8 +23,6 @@ usage() {
|
|||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
orig_argv=("$@")
|
|
||||||
|
|
||||||
while getopts 'hC:M:c:' arg; do
|
while getopts 'hC:M:c:' arg; do
|
||||||
case "$arg" in
|
case "$arg" in
|
||||||
C) pac_conf="$OPTARG" ;;
|
C) pac_conf="$OPTARG" ;;
|
||||||
@@ -39,7 +36,7 @@ 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
|
||||||
@@ -60,7 +57,7 @@ mkdir -p "$working_dir"
|
|||||||
|
|
||||||
lock 9 "${working_dir}.lock" "Locking chroot"
|
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"
|
rmdir "$working_dir"
|
||||||
if ! btrfs subvolume create "$working_dir"; then
|
if ! btrfs subvolume create "$working_dir"; then
|
||||||
die "Couldn't create subvolume for '%s'" "$working_dir"
|
die "Couldn't create subvolume for '%s'" "$working_dir"
|
||||||
|
|||||||
Reference in New Issue
Block a user