manjaro-tools/bin/build-set.in

306 lines
6.8 KiB
Text
Raw Normal View History

2014-10-04 00:46:40 +02:00
#!/bin/bash
2014-10-08 11:11:19 +02:00
#
2014-10-04 15:41:22 +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@
shopt -s nullglob
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-11-13 13:33:38 +01:00
2014-11-16 23:18:01 +01:00
display_settings(){
2014-11-26 15:53:19 +01:00
msg "manjaro-tools"
msg2 "version: ${version}"
2014-11-16 23:18:01 +01:00
msg "OPTIONS:"
msg2 "arch: ${arch}"
msg2 "branch: ${branch}"
msg2 "chroots: ${chroots}"
msg "ARGS:"
msg2 "mkchrootpkg_args: ${mkchrootpkg_args[*]}"
msg2 "makepkg_args: ${makepkg_args[*]}"
msg "PATHS:"
msg2 "chrootdir: ${chrootdir}"
msg2 "profiledir: ${profiledir}"
2014-12-06 22:50:47 +01:00
msg2 "pkg_dir: ${pkg_dir}"
2014-11-16 23:18:01 +01:00
msg2 "pacman_conf: ${pacman_conf}"
msg2 "makepkg_conf: ${makepkg_conf}"
msg2 "pm_conf: ${pm_conf}"
2014-12-07 02:33:21 +01:00
msg "BLACKLIST:"
msg2 "blacklist_trigger: ${blacklist_trigger[*]}"
msg2 "blacklist: ${blacklist[*]}"
2014-11-16 23:18:01 +01:00
if ${clean_first};then
msg "PKG:"
msg2 "base_packages: ${base_packages[*]}"
fi
msg "SETS:"
2014-11-16 23:22:21 +01:00
msg2 "profiles: $(load_sets)"
2014-11-16 23:18:01 +01:00
msg2 "profile: ${profile}"
msg2 "is_profile: ${is_profile}"
if ${is_profile};then
msg "Build queue:"
local list=$(cat ${profiledir}/${profile}.set)
for item in ${list[@]}; do
msg2 "$item"
done
else
msg "Build queue:"
for arg in "${makepkg_args[@]}"; do
case ${arg} in
--pkg) continue ;;
-*) continue ;;
*) local split_arg=${arg} ;;
esac
done
if [[ -n ${split_arg} ]]; then
local IFS=','
for item in ${split_arg}; do
msg2 "$item"
done
unset IFS
else
msg2 "${profile}"
fi
fi
}
eval_profile(){
eval "case $1 in
$(load_sets)) is_profile=true ;;
*) is_profile=false ;;
esac"
}
2014-11-13 01:20:33 +01:00
chroot_create(){
mkdir -p "${chrootdir}"
setarch "${arch}" mkchroot \
${mkchroot_args[*]} \
"${chrootdir}/root" \
2014-11-14 22:18:32 +01:00
${base_packages[*]} || abort
2014-11-13 01:20:33 +01:00
}
2014-11-18 17:52:23 +01:00
chroot_clean(){
for copy in "${chrootdir}"/*; do
[[ -d ${copy} ]] || continue
msg2 "Deleting chroot copy '$(basename "${copy}")'..."
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
rm -rf --one-file-system "${copy}"
done
exec 9>&-
rm -rf --one-file-system "${chrootdir}"
}
2014-11-13 01:20:33 +01:00
chroot_update(){
lock 9 "${chrootdir}/root.lock" "Locking clean chroot"
chroot-run ${mkchroot_args[*]} \
"${chrootdir}/root" \
pacman -Syu --noconfirm || abort
}
2014-11-18 17:52:23 +01:00
clean_up(){
msg "Cleaning up ..."
local query=$(find ${pkg_dir} -maxdepth 1 -name "*.*")
[[ -n $query ]] && rm -v $query
if [[ -z $LOGDEST ]];then
query=$(find $PWD -maxdepth 2 -name '*.log')
[[ -n $query ]] && rm -v $query
fi
if [[ -z $SRCDEST ]];then
query=$(find $PWD -maxdepth 2 -name '*.?z?')
[[ -n $query ]] && rm -v $query
fi
}
blacklist_pkg(){
2014-11-26 15:53:19 +01:00
msg "Removing ${blacklist[@]}..."
2014-12-03 22:59:03 +01:00
for item in "${blacklist[@]}"; do
chroot-run $1/root pacman -Rdd "$item" --noconfirm
done
2014-11-18 17:52:23 +01:00
}
prepare_cachedir(){
mkdir -p "${pkg_dir}"
chown -R "${pkg_owner}:users" "${pkg_dir_loaded}"
2014-11-17 01:31:19 +01:00
}
2014-11-17 00:36:14 +01:00
move_pkg(){
local ext='pkg.tar.xz'
if [[ -n $PKGDEST ]];then
2014-11-18 17:52:23 +01:00
mv $PKGDEST/*{any,$arch}.${ext} ${pkg_dir}/
2014-11-17 00:36:14 +01:00
else
2014-11-18 17:52:23 +01:00
mv *.${ext} ${pkg_dir}
2014-11-17 00:36:14 +01:00
fi
2014-11-18 17:52:23 +01:00
chown -R "${pkg_owner}:users" "${pkg_dir_loaded}"
2014-11-17 00:36:14 +01:00
}
2014-11-12 04:15:40 +01:00
chroot_build(){
if ${is_profile};then
msg "Start building profile: [${profile}]"
for pkg in $(cat ${profiledir}/${profile}.set); do
cd $pkg
2014-11-26 15:53:19 +01:00
for p in ${blacklist_trigger[@]}; do
if [[ $pkg == $p ]]; then
blacklist_pkg "${chrootdir}"
fi
done
2014-11-12 04:15:40 +01:00
setarch "${arch}" \
2014-11-13 22:43:07 +01:00
mkchrootpkg ${mkchrootpkg_args[*]} -- ${makepkg_args[*]} || break
2014-11-17 00:36:14 +01:00
move_pkg
2014-11-12 04:15:40 +01:00
cd ..
done
msg "Finished building profile: [${profile}]"
else
cd ${profile}
2014-11-26 15:53:19 +01:00
for p in ${blacklist_trigger[@]}; do
if [[ ${profile} == $p ]]; then
blacklist_pkg "${chrootdir}"
fi
done
2014-11-12 04:15:40 +01:00
setarch "${arch}" \
2014-11-13 22:43:07 +01:00
mkchrootpkg ${mkchrootpkg_args[*]} -- ${makepkg_args[*]} || abort
2014-11-17 00:36:14 +01:00
move_pkg
2014-11-12 04:15:40 +01:00
cd ..
fi
}
chroot_init(){
2014-11-13 01:53:11 +01:00
if ${clean_first} || [[ ! -d "${chrootdir}" ]]; then
msg "Creating chroot for [${branch}] (${arch})..."
2014-11-18 17:52:23 +01:00
chroot_clean
2014-11-13 01:20:33 +01:00
chroot_create
2014-11-12 04:15:40 +01:00
else
msg "Updating chroot for [${branch}] (${arch})..."
2014-11-13 01:20:33 +01:00
chroot_update
2014-11-12 04:15:40 +01:00
fi
}
2014-11-17 00:36:14 +01:00
sign_pkgs(){
2014-11-18 17:52:23 +01:00
cd $pkg_dir
2014-11-17 00:36:14 +01:00
su "${pkg_owner}" <<'EOF'
signpkgs
EOF
}
2014-10-04 00:46:40 +02:00
export LC_MESSAGES=C
load_config '@sysconfdir@/manjaro-tools.conf'
2014-11-14 23:33:53 +01:00
pkg_owner=${SUDO_USER:-$USER}
if [[ -n $SUDO_USER ]]; then
eval "USER_HOME=~$SUDO_USER"
else
USER_HOME=$HOME
fi
2014-12-08 22:58:38 +01:00
load_config "$USER_HOME/.config/manjaro-tools.conf"
2014-12-08 22:58:38 +01:00
load_vars "$USER_HOME/.makepkg.conf"
2014-11-14 23:33:53 +01:00
load_vars /etc/makepkg.conf
2014-10-08 11:11:19 +02:00
pacman_conf_arch='default'
2014-11-16 23:18:01 +01:00
base_packages=('base-devel')
2014-10-08 11:11:19 +02:00
clean_first=false
2014-11-13 01:53:11 +01:00
wipe_clean=false
2014-10-04 00:46:40 +02:00
namcap=false
pretend=false
is_profile=false
2014-10-06 23:35:01 +02:00
sign=false
2014-10-04 00:46:40 +02:00
usage() {
2014-11-14 13:11:54 +01:00
echo "Usage: ${0##*/} [options] [--] [makepkg args]"
2014-10-06 01:22:45 +02:00
echo " -p <profile> Set profile or pkg [default: ${profile}]"
echo " -a <arch> Set arch [default: ${arch}]"
echo " -b <branch> Set branch [default: ${branch}]"
echo " -r <dir> Chroots directory [default: ${chroots}]"
2014-11-13 21:13:45 +01:00
echo ' -c Recreate chroot'
echo ' -w Clean up'
2014-11-14 13:11:54 +01:00
echo ' -n Install and run namcap check'
2014-10-06 23:35:01 +02:00
echo ' -s Sign packages'
2014-10-06 02:44:40 +02:00
echo ' -q Query settings and pretend build'
2014-10-04 00:46:40 +02:00
echo ' -h This help'
echo ''
echo ''
exit 1
}
2014-11-12 04:15:40 +01:00
orig_argv=("$@")
2014-11-14 23:33:53 +01:00
opts='p:a:b:r:cwnsqh'
2014-10-04 00:46:40 +02:00
while getopts "${opts}" arg; do
case "${arg}" in
2014-11-18 18:02:11 +01:00
p) profile="$OPTARG" ;;
2014-10-04 00:46:40 +02:00
a) arch="$OPTARG" ;;
b) branch="$OPTARG" ;;
r) chroots="$OPTARG" ;;
2014-11-12 04:15:40 +01:00
c) clean_first=true ;;
2014-11-13 01:53:11 +01:00
w) wipe_clean=true ;;
2014-10-13 13:38:22 +02:00
n) namcap=true; mkchrootpkg_args+=(-n) ;;
2014-10-06 23:35:01 +02:00
s) sign=true ;;
2014-10-14 21:57:44 +02:00
q) pretend=true ;;
2014-10-04 00:46:40 +02:00
h) usage ;;
esac
done
if [[ "$arch" == 'multilib' ]]; then
pacman_conf_arch='multilib'
base_packages+=('multilib-devel')
2014-11-14 23:33:53 +01:00
arch='x86_64'
2014-10-04 00:46:40 +02:00
fi
2014-11-14 22:12:29 +01:00
chrootdir=${chroots}/${branch}/${arch}
2014-11-18 17:52:23 +01:00
pkg_dir_loaded=${pkg_dir}
pkg_dir="${pkg_dir}/${branch}/${arch}"
2014-11-14 23:33:53 +01:00
load_pacman_conf "@pkgdatadir@/pacman-${pacman_conf_arch}.conf"
2014-10-04 00:46:40 +02:00
makepkg_conf="@pkgdatadir@/makepkg-${arch}.conf"
2014-11-12 02:19:58 +01:00
pm_conf="@pkgdatadir@/pacman-mirrors-${branch}.conf"
2014-10-04 00:46:40 +02:00
2014-11-12 02:19:58 +01:00
mkchroot_args+=(-C ${pacman_conf} -M ${makepkg_conf} -S ${pm_conf})
2014-10-04 00:46:40 +02:00
2014-11-12 04:15:40 +01:00
mkchrootpkg_args+=(-r ${chrootdir})
2014-10-04 00:46:40 +02:00
2014-11-12 04:15:40 +01:00
makepkg_args+=("${@:$OPTIND}")
2014-10-04 00:46:40 +02:00
2014-11-12 04:15:40 +01:00
check_root "$0" "${orig_argv[@]}"
2014-10-07 10:34:58 +02:00
2014-11-18 17:52:23 +01:00
[[ -d "${pkg_dir}" ]] || prepare_cachedir
2014-11-13 22:43:07 +01:00
eval_profile "${profile}"
2014-11-16 23:18:01 +01:00
${pretend} && display_settings && exit
${wipe_clean} && clean_up
chroot_init
chroot_build
2014-11-17 00:36:14 +01:00
${sign} && sign_pkgs