forked from artix/artools
		
	Compare commits
	
		
			5 Commits
		
	
	
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 6d5dbc5774 | |||
| 36ee26e18c | |||
| 0b9e18ed5b | |||
| b26b6da61c | |||
| e1f762cd91 | 
| @@ -23,6 +23,8 @@ umask 0022 | ||||
| working_dir='' | ||||
| files=() | ||||
|  | ||||
| mount_args=() | ||||
|  | ||||
| usage() { | ||||
|     echo "Usage: ${0##*/} [options] working-dir [run arguments]" | ||||
|     echo "A wrapper around chroot. Provides support for pacman." | ||||
| @@ -33,16 +35,15 @@ usage() { | ||||
|     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 '    -w <list>     Bind mountargs rw' | ||||
|     echo '                  List format [src1:target1 ... srcN:targetN]' | ||||
|     echo '    -b <list>     Bind mountargs' | ||||
|     echo '                  List format [mntarg1:src1:dest1 ... mntargN:srcN:destN]' | ||||
|     echo '    -h            This message' | ||||
|     exit 1 | ||||
| } | ||||
|  | ||||
| orig_argv=("$0" "$@") | ||||
|  | ||||
| opts='hC:M:c:r:w:f:s' | ||||
| opts='hC:M:c:b:f:s' | ||||
|  | ||||
| while getopts ${opts} arg; do | ||||
|     case "${arg}" in | ||||
| @@ -51,8 +52,7 @@ while getopts ${opts} arg; do | ||||
|         c) cache_dirs+=("$OPTARG") ;; | ||||
|         f) files+=("$OPTARG") ;; | ||||
|         s) nosetarch=1 ;; | ||||
|         r) bindmounts_ro=("$OPTARG") ;; | ||||
|         w) bindmounts_rw=("$OPTARG") ;; | ||||
|         b) bindmounts=("$OPTARG"); mount_args+=(${bindmounts[@]}) ;; | ||||
|         h|?) usage ;; | ||||
|         *) error "invalid argument '$arg'"; usage ;; | ||||
|     esac | ||||
| @@ -76,6 +76,14 @@ fi | ||||
|  | ||||
| host_mirrors=($($pacconf_cmd --repo world Server 2> /dev/null | sed -r 's#(.*/)world/os/.*#\1$repo/os/$arch#')) | ||||
|  | ||||
| for host_mirror in "${host_mirrors[@]}"; do | ||||
|     if [[ $host_mirror == *file://* ]]; then | ||||
|         host_mirror=$(echo "$host_mirror" | sed -r 's#file://(/.*)/\$repo/os/\$arch#\1#g') | ||||
|         info "host mirror: %s" "$host_mirror" | ||||
|         in_array "$host_mirror" "${cache_dirs[@]}" || cache_dirs+=("$host_mirror") | ||||
|     fi | ||||
| done | ||||
|  | ||||
| while read -r line; do | ||||
|     mapfile -t lines < <($pacconf_cmd --config "${pac_conf:-$working_dir/etc/pacman.conf}" \ | ||||
|         --repo $line Server | sed -r 's#(.*/)[^/]+/os/.+#\1$repo/os/$arch#') | ||||
| @@ -95,9 +103,9 @@ copy_hostconf () { | ||||
|  | ||||
|     printf 'Server = %s\n' "${host_mirrors[@]}" >"$working_dir/etc/pacman.d/mirrorlist" | ||||
|  | ||||
|     [[ -n $pacman_conf ]] && cp $pacman_conf "$1/etc/pacman.conf" | ||||
|     [[ -n $pacman_conf ]] && cp $pacman_conf "${working_dir}/etc/pacman.conf" | ||||
|  | ||||
|     [[ -n $makepkg_conf ]] && cp $makepkg_conf "$1/etc/makepkg.conf" | ||||
|     [[ -n $makepkg_conf ]] && cp $makepkg_conf "${working_dir}/etc/makepkg.conf" | ||||
|  | ||||
|     local file | ||||
|     for file in "${files[@]}"; do | ||||
| @@ -105,37 +113,30 @@ copy_hostconf () { | ||||
|         cp -T "$file" "$working_dir$file" | ||||
|     done | ||||
|  | ||||
|     sed -r "s|^#?\\s*CacheDir.+|CacheDir = ${cache_dirs[*]}|g" -i "$1/etc/pacman.conf" | ||||
|     sed -r "s|^#?\\s*CacheDir.+|CacheDir = ${cache_dirs[*]}|g" -i "${working_dir}/etc/pacman.conf" | ||||
| } | ||||
|  | ||||
| mount_args+=("-B:${cache_dirs[0]//:/\\:}:${cache_dirs[0]//:/\\:}" "-B:/etc/hosts:/etc/hosts") | ||||
|  | ||||
| for cache_dir in "${cache_dirs[@]:1}"; do | ||||
|     mount_args+=("-Br:${cache_dir//:/\\:}:${cache_dir//:/\\:}") | ||||
| done | ||||
|  | ||||
| chroot_extra_mount() { | ||||
|     chroot_add_resolv_conf "$1" | ||||
|     chroot_mount "/etc/hosts" "$1/etc/hosts" -B | ||||
|     chroot_mount "${cache_dirs[0]}" "$1${cache_dirs[0]}" -B | ||||
|     chroot_add_resolv_conf "${working_dir}" | ||||
|  | ||||
|     for cache_dir in ${cache_dirs[@]:1}; do | ||||
|         chroot_mount "$cache_dir" "$1${cache_dir}" -Br | ||||
|     done | ||||
|  | ||||
|     for m in ${bindmounts_ro[@]}; do | ||||
|         chroot_mount "${m%%:*}" "$1${m##*:}" -Br | ||||
|     done | ||||
|  | ||||
|     for m in ${bindmounts_rw[@]}; do | ||||
|         chroot_mount "${m%%:*}" "$1${m##*:}" -B | ||||
|     done | ||||
|  | ||||
|     for host_mirror in "${host_mirrors[@]}"; do | ||||
|         if [[ $host_mirror == *file://* ]]; then | ||||
|             host_mirror_path=$(echo "$host_mirror" | sed -r 's#file://(/.*)/\$repo/os/\$arch#\1#g') | ||||
|             chroot_mount "$host_mirror_path" "$1$host_mirror_path" -Br | ||||
|         fi | ||||
|     for arg in ${mount_args[@]}; do | ||||
|         local flag=${arg%%:*} | ||||
|         local dest=${arg##*:} | ||||
|         local src=${arg%:*} | ||||
|         src=${src#*:} | ||||
|         chroot_mount "${src}" "${working_dir}${dest}" "${flag}" | ||||
|     done | ||||
| } | ||||
|  | ||||
| sync_host_localtime(){ | ||||
|     if [[ -e /etc/localtime ]]; then | ||||
|         cp -L /etc/localtime "$1"/etc/localtime | ||||
|         cp -L /etc/localtime "${working_dir}"/etc/localtime | ||||
|     fi | ||||
| } | ||||
|  | ||||
| @@ -148,13 +149,13 @@ elif [[ $(cat "$working_dir/.artools") != ${CHROOTVERSION} ]]; then | ||||
|     die "chroot '%s' is not at version %s. Please rebuild." "$working_dir" "${CHROOTVERSION}" | ||||
| fi | ||||
|  | ||||
| sync_host_localtime "${working_dir}" | ||||
| sync_host_localtime | ||||
|  | ||||
| chroot_api_mount "${working_dir}" || die "failed to setup API filesystems in chroot %s" "${working_dir}" | ||||
|  | ||||
| chroot_extra_mount "${working_dir}" | ||||
| chroot_extra_mount | ||||
|  | ||||
| copy_hostconf "${working_dir}" | ||||
| copy_hostconf | ||||
|  | ||||
| eval $(grep '^CARCH=' "$working_dir/etc/makepkg.conf") | ||||
|  | ||||
|   | ||||
| @@ -14,10 +14,7 @@ | ||||
|  | ||||
| . @libdir@/artools/util-base.sh | ||||
|  | ||||
| load_user_info | ||||
|  | ||||
| load_vars "${XDG_CONFIG_HOME}/pacman/makepkg.conf" || load_vars "${USER_HOME}/.makepkg.conf" | ||||
| load_vars /etc/makepkg.conf | ||||
| load_makepkg_config | ||||
|  | ||||
| file_to_sign="$1" | ||||
|  | ||||
|   | ||||
| @@ -195,8 +195,7 @@ sync_repos(){ | ||||
|     fi | ||||
| } | ||||
|  | ||||
| load_vars "${XDG_CONFIG_HOME}/pacman/makepkg.conf" || load_vars "${USER_HOME}/.makepkg.conf" | ||||
| load_vars /etc/makepkg.conf | ||||
| load_makepkg_config | ||||
|  | ||||
| sync=false | ||||
| sync_arch=true | ||||
|   | ||||
| @@ -141,8 +141,7 @@ symlink_commit_pkg(){ | ||||
|     fi | ||||
| } | ||||
|  | ||||
| load_vars "${XDG_CONFIG_HOME}/pacman/makepkg.conf" || load_vars "${USER_HOME}/.makepkg.conf" | ||||
| load_vars /etc/makepkg.conf | ||||
| load_makepkg_config | ||||
|  | ||||
| REPO_SRC='trunk' | ||||
| PACKAGE='' | ||||
|   | ||||
| @@ -185,8 +185,7 @@ show_version_table(){ | ||||
|     done | ||||
| } | ||||
|  | ||||
| load_vars "${XDG_CONFIG_HOME}/pacman/makepkg.conf" || load_vars "${USER_HOME}/.makepkg.conf" | ||||
| load_vars /etc/makepkg.conf | ||||
| load_makepkg_config | ||||
|  | ||||
| unstable=false | ||||
| staging=true | ||||
|   | ||||
| @@ -129,8 +129,7 @@ update_repo(){ | ||||
|     return 0 | ||||
| } | ||||
|  | ||||
| load_vars "${XDG_CONFIG_HOME}/pacman/makepkg.conf" || load_vars "${USER_HOME}/.makepkg.conf" | ||||
| load_vars /etc/makepkg.conf | ||||
| load_makepkg_config | ||||
|  | ||||
| add_pkg=false | ||||
| del_pkg=false | ||||
|   | ||||
| @@ -33,8 +33,7 @@ run_checkpkg=0 | ||||
| temp_chroot=0 | ||||
| run_nocheck=0 | ||||
|  | ||||
| bindmounts_ro=() | ||||
| bindmounts_rw=() | ||||
| bindmounts=() | ||||
|  | ||||
| copy=$USER | ||||
| [[ -n ${SUDO_USER:-} ]] && copy=$SUDO_USER | ||||
| @@ -147,8 +146,7 @@ install_packages() { | ||||
|  | ||||
|     cp -- "${install_pkgs[@]}" "$copydir/root/" | ||||
|     chroot-run \ | ||||
|         -r "${bindmounts_ro[@]}" \ | ||||
|         -r "${bindmounts_rw[@]}" \ | ||||
|         -b "${bindmounts[@]}" \ | ||||
|         "$copydir" \ | ||||
|         bash -c 'yes y | pacman -U -- "$@"' -bash "${pkgnames[@]/#//root/}" | ||||
|     ret=$? | ||||
| @@ -282,13 +280,12 @@ move_products() { | ||||
|  | ||||
| orig_argv=("$0" "$@") | ||||
|  | ||||
| opts='hcur:I:l:nNCTD:d:U:' | ||||
| opts='hcur:I:l:nNCTb:U:' | ||||
|  | ||||
| while getopts "${opts}" arg; do | ||||
|     case "$arg" in | ||||
|         c) clean_first=1 ;; | ||||
|         D) bindmounts_ro+=("$OPTARG") ;; | ||||
|         d) bindmounts_rw+=("$OPTARG") ;; | ||||
|         b) bindmounts+=("$OPTARG") ;; | ||||
|         u) update_first=1 ;; | ||||
|         r) passeddir="$OPTARG" ;; | ||||
|         I) install_pkgs+=("$OPTARG") ;; | ||||
| @@ -332,16 +329,12 @@ for arg in "${@:$OPTIND}"; do | ||||
|     esac | ||||
| done | ||||
|  | ||||
| if [[ -n $SUDO_USER ]]; then | ||||
| 	eval "USER_HOME=~$SUDO_USER" | ||||
| else | ||||
| 	USER_HOME=$HOME | ||||
| fi | ||||
|  | ||||
| umask 0022 | ||||
|  | ||||
| load_vars "${XDG_CONFIG_HOME}/pacman/makepkg.conf" || load_vars "${USER_HOME}/.makepkg.conf" | ||||
| load_vars /etc/makepkg.conf | ||||
| ORIG_HOME=$HOME | ||||
| IFS=: read -r _ _ _ _ _ HOME _ < <(getent passwd "${SUDO_USER:-$USER}") | ||||
| load_makepkg_config | ||||
| HOME=$ORIG_HOME | ||||
|  | ||||
| # Use PKGBUILD directory if these don't exist | ||||
| [[ -d $PKGDEST ]]    || PKGDEST=$PWD | ||||
| @@ -356,11 +349,10 @@ if [[ ! -d $copydir ]] || (( clean_first )); then | ||||
|     sync_chroot "$chrootdir" "$copydir" "$copy" | ||||
| fi | ||||
|  | ||||
| bindmounts_rw+=("${PWD}:/startdir" "${SRCDEST}:/srcdest") | ||||
| bindmounts+=("-B:${PWD}:/startdir" "-B:${SRCDEST}:/srcdest") | ||||
|  | ||||
| (( update_first )) && chroot-run \ | ||||
|         -r "${bindmounts_ro[*]}" \ | ||||
|         -w "${bindmounts_rw[*]}" \ | ||||
|         -b "${bindmounts[*]}" \ | ||||
|         "$copydir" \ | ||||
|         pacman -Syuu --noconfirm | ||||
|  | ||||
| @@ -381,8 +373,7 @@ download_sources | ||||
| prepare_chroot | ||||
|  | ||||
| if chroot-run \ | ||||
|     -r "${bindmounts_ro[*]}" \ | ||||
|     -w "${bindmounts_rw[*]}" \ | ||||
|     -b "${bindmounts[*]}" \ | ||||
|     "$copydir" \ | ||||
|     /chrootbuild "${makepkg_args[@]}" | ||||
| then | ||||
|   | ||||
| @@ -144,6 +144,6 @@ PACKAGE="$1"/PKGBUILD; shift | ||||
|  | ||||
| . "$PACKAGE" | ||||
|  | ||||
| . /etc/makepkg.conf | ||||
| load_makepkg_config | ||||
|  | ||||
| write_pkg_yaml | ||||
|   | ||||
| @@ -16,10 +16,9 @@ | ||||
| #GPGDir      = /etc/pacman.d/gnupg/ | ||||
| #HookDir     = /etc/pacman.d/hooks/ | ||||
| HoldPkg     = pacman glibc | ||||
| #XferCommand = /usr/bin/curl -C - -f %u > %o | ||||
| #XferCommand = /usr/bin/curl -L -C - -f -o %o %u | ||||
| #XferCommand = /usr/bin/wget --passive-ftp -c -O %o %u | ||||
| #CleanMethod = KeepInstalled | ||||
| #UseDelta    = 0.7 | ||||
| Architecture = auto | ||||
|  | ||||
| # Pacman won't upgrade packages listed in IgnorePkg and members of IgnoreGroup | ||||
|   | ||||
| @@ -16,10 +16,9 @@ | ||||
| #GPGDir      = /etc/pacman.d/gnupg/ | ||||
| #HookDir     = /etc/pacman.d/hooks/ | ||||
| HoldPkg     = pacman glibc | ||||
| #XferCommand = /usr/bin/curl -C - -f %u > %o | ||||
| #XferCommand = /usr/bin/curl -L -C - -f -o %o %u | ||||
| #XferCommand = /usr/bin/wget --passive-ftp -c -O %o %u | ||||
| #CleanMethod = KeepInstalled | ||||
| #UseDelta    = 0.7 | ||||
| Architecture = auto | ||||
|  | ||||
| # Pacman won't upgrade packages listed in IgnorePkg and members of IgnoreGroup | ||||
|   | ||||
| @@ -16,10 +16,9 @@ | ||||
| #GPGDir      = /etc/pacman.d/gnupg/ | ||||
| #HookDir     = /etc/pacman.d/hooks/ | ||||
| HoldPkg     = pacman glibc | ||||
| #XferCommand = /usr/bin/curl -C - -f %u > %o | ||||
| #XferCommand = /usr/bin/curl -L -C - -f -o %o %u | ||||
| #XferCommand = /usr/bin/wget --passive-ftp -c -O %o %u | ||||
| #CleanMethod = KeepInstalled | ||||
| #UseDelta    = 0.7 | ||||
| Architecture = auto | ||||
|  | ||||
| # Pacman won't upgrade packages listed in IgnorePkg and members of IgnoreGroup | ||||
|   | ||||
| @@ -16,10 +16,9 @@ | ||||
| #GPGDir      = /etc/pacman.d/gnupg/ | ||||
| #HookDir     = /etc/pacman.d/hooks/ | ||||
| HoldPkg     = pacman glibc | ||||
| #XferCommand = /usr/bin/curl -C - -f %u > %o | ||||
| #XferCommand = /usr/bin/curl -L -C - -f -o %o %u | ||||
| #XferCommand = /usr/bin/wget --passive-ftp -c -O %o %u | ||||
| #CleanMethod = KeepInstalled | ||||
| #UseDelta    = 0.7 | ||||
| Architecture = auto | ||||
|  | ||||
| # Pacman won't upgrade packages listed in IgnorePkg and members of IgnoreGroup | ||||
|   | ||||
| @@ -16,10 +16,9 @@ | ||||
| #GPGDir      = /etc/pacman.d/gnupg/ | ||||
| #HookDir     = /etc/pacman.d/hooks/ | ||||
| HoldPkg     = pacman glibc | ||||
| #XferCommand = /usr/bin/curl -C - -f %u > %o | ||||
| #XferCommand = /usr/bin/curl -L -C - -f -o %o %u | ||||
| #XferCommand = /usr/bin/wget --passive-ftp -c -O %o %u | ||||
| #CleanMethod = KeepInstalled | ||||
| #UseDelta    = 0.7 | ||||
| Architecture = auto | ||||
|  | ||||
| # Pacman won't upgrade packages listed in IgnorePkg and members of IgnoreGroup | ||||
|   | ||||
| @@ -16,10 +16,9 @@ | ||||
| #GPGDir      = /etc/pacman.d/gnupg/ | ||||
| #HookDir     = /etc/pacman.d/hooks/ | ||||
| HoldPkg     = pacman glibc | ||||
| #XferCommand = /usr/bin/curl -C - -f %u > %o | ||||
| #XferCommand = /usr/bin/curl -L -C - -f -o %o %u | ||||
| #XferCommand = /usr/bin/wget --passive-ftp -c -O %o %u | ||||
| #CleanMethod = KeepInstalled | ||||
| #UseDelta    = 0.7 | ||||
| Architecture = auto | ||||
|  | ||||
| # Pacman won't upgrade packages listed in IgnorePkg and members of IgnoreGroup | ||||
|   | ||||
| @@ -16,10 +16,9 @@ | ||||
| #GPGDir      = /etc/pacman.d/gnupg/ | ||||
| #HookDir     = /etc/pacman.d/hooks/ | ||||
| HoldPkg     = pacman glibc | ||||
| #XferCommand = /usr/bin/curl -C - -f %u > %o | ||||
| #XferCommand = /usr/bin/curl -L -C - -f -o %o %u | ||||
| #XferCommand = /usr/bin/wget --passive-ftp -c -O %o %u | ||||
| #CleanMethod = KeepInstalled | ||||
| #UseDelta    = 0.7 | ||||
| Architecture = auto | ||||
|  | ||||
| # Pacman won't upgrade packages listed in IgnorePkg and members of IgnoreGroup | ||||
|   | ||||
| @@ -16,10 +16,9 @@ | ||||
| #GPGDir      = /etc/pacman.d/gnupg/ | ||||
| #HookDir     = /etc/pacman.d/hooks/ | ||||
| HoldPkg     = pacman glibc | ||||
| #XferCommand = /usr/bin/curl -C - -f %u > %o | ||||
| #XferCommand = /usr/bin/curl -L -C - -f -o %o %u | ||||
| #XferCommand = /usr/bin/wget --passive-ftp -c -O %o %u | ||||
| #CleanMethod = KeepInstalled | ||||
| #UseDelta    = 0.7 | ||||
| Architecture = auto | ||||
|  | ||||
| # Pacman won't upgrade packages listed in IgnorePkg and members of IgnoreGroup | ||||
|   | ||||
| @@ -132,17 +132,17 @@ DBGSRCDIR="/usr/src/debug" | ||||
| COMPRESSGZ=(gzip -c -f -n) | ||||
| COMPRESSBZ2=(bzip2 -c -f) | ||||
| COMPRESSXZ=(xz -c -z -) | ||||
| COMPRESSZST=(zstd -c -z -q -) | ||||
| COMPRESSLRZ=(lrzip -q) | ||||
| COMPRESSLZO=(lzop -q) | ||||
| COMPRESSZ=(compress -c -f) | ||||
| COMPRESSLZ4=(lz4 -q) | ||||
| COMPRESSLZ=(lzip -c -f) | ||||
|  | ||||
| ######################################################################### | ||||
| # EXTENSION DEFAULTS | ||||
| ######################################################################### | ||||
| # | ||||
| # WARNING: Do NOT modify these variables unless you know what you are | ||||
| #          doing. | ||||
| # | ||||
| PKGEXT='.pkg.tar.xz' | ||||
| SRCEXT='.src.tar.gz' | ||||
|  | ||||
|   | ||||
| @@ -25,18 +25,6 @@ show_elapsed_time(){ | ||||
|     info "Time %s: %s minutes" "$1" "$(elapsed_time $2)" | ||||
| } | ||||
|  | ||||
| load_vars() { | ||||
|     local var | ||||
|  | ||||
|     [[ -f $1 ]] || return 1 | ||||
|  | ||||
|     for var in {SRC,SRCPKG,PKG,LOG}DEST MAKEFLAGS PACKAGER CARCH GPGKEY; do | ||||
|         [[ -z ${!var:-} ]] && eval "$(source "$1"; printf "%s='%s'" "$var" "${!var}")" | ||||
|     done | ||||
|  | ||||
|     return 0 | ||||
| } | ||||
|  | ||||
| prepare_dir(){ | ||||
|     [[ ! -d $1 ]] && mkdir -p $1 | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user