nix-tools/lib/build-api.sh

198 lines
4.4 KiB
Bash
Raw Normal View History

2014-10-08 00:11:53 +02:00
#!/bin/bash
2014-10-08 11:11:19 +02:00
#
2014-10-08 00:11:53 +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 11:11:19 +02:00
shopt -s nullglob
2014-10-08 00:11:53 +02:00
ch_owner(){
2014-10-13 21:21:09 +02:00
msg "chown -R [$(get_user):users] [$1]"
2014-10-08 00:11:53 +02:00
chown -R "$(get_user):users" "$1"
}
sign_pkgs(){
cd $pkgdir
su $(get_user) <<'EOF'
signpkgs
EOF
}
get_profiles(){
local prof= temp=
2014-10-08 11:11:19 +02:00
for item in $(ls ${profiledir}/*.set);do
temp=${item##*/}
2014-10-08 00:11:53 +02:00
prof=${prof:-}${prof:+|}${temp%.set}
done
echo $prof
}
get_user(){
echo $(ls ${chrootdir} | cut -d' ' -f1 | grep -v root | grep -v lock)
}
prepare_dir(){
if ! [[ -d $1 ]];then
mkdir -p $1
fi
}
2014-11-11 21:19:26 +01:00
clean_dir(){
msg2 "Cleaning $1 ..."
rm -r $1/*
}
git_clean(){
msg2 "Cleaning $(pwd) ..."
git clean -dfx$1
}
####chroot controller######
2014-10-08 00:11:53 +02:00
chroot_clean(){
for copy in "${chrootdir}"/*; do
[[ -d "${copy}" ]] || continue
msg2 "Deleting chroot copy '$(basename "${copy}")'..."
exec 9>"${copy}.lock"
if ! flock -n 9; then
stat_busy "Locking chroot copy '${copy}'"
flock 9
stat_done
fi
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}"
}
chroot_create(){
mkdir -p "${chrootdir}"
2014-10-13 21:21:09 +02:00
setarch "${arch}" \
2014-10-08 00:11:53 +02:00
mkchroot ${mkchroot_args[*]} ${chrootdir}/root ${base_packages[*]} || abort
}
2014-11-11 21:19:26 +01:00
# chroot_update(){
# setarch "${arch}" \
# mkchroot ${mkchroot_args[*]} -u ${chrootdir}/$(get_user) || abort
# }
2014-10-08 00:11:53 +02:00
chroot_init(){
if [[ ! -d "${chrootdir}" ]]; then
msg "Creating chroot for [${branch}] (${arch})..."
chroot_create
2014-11-11 21:19:26 +01:00
else ${clean_first};then
2014-10-08 00:11:53 +02:00
msg "Creating chroot for [${branch}] (${arch})..."
chroot_clean
chroot_create
2014-11-11 21:19:26 +01:00
# else
# msg "Updating chroot for [${branch}] (${arch})..."
# chroot_update
2014-10-08 00:11:53 +02:00
fi
}
2014-11-11 21:19:26 +01:00
chroot_build(){
if ${is_profile};then
msg "Start building profile: [${profile}]"
for pkg in $(cat ${profiledir}/${profile}.set); do
cd $pkg
if [[ $pkg == 'eudev' ]] || [[ $pkg == 'lib32-eudev' ]]; then
blacklist_pkg
fi
setarch "${arch}" \
mkchrootpkg ${mkchrootpkg_args[*]} -- "${makepkg_args[*]}" || break
move_pkg "${pkg}"
cd ..
done
msg "Finished building profile: [${profile}]"
else
cd ${profile}
if [[ ${profile} == 'eudev' ]] || [[ ${profile} == 'lib32-eudev' ]]; then
blacklist_pkg
fi
setarch "${arch}" \
mkchrootpkg ${mkchrootpkg_args[*]} -- "${makepkg_args[*]}" || abort
move_pkg "${profile}"
cd ..
fi
}
####end chroot controller######
2014-10-08 11:11:19 +02:00
eval_profile(){
eval "case ${profile} in
$(get_profiles)) is_profile=true ;;
*) is_profile=false ;;
esac"
}
2014-10-23 00:46:43 +02:00
blacklist_pkg(){
local blacklist=('libsystemd') cmd=$(pacman -Q ${blacklist[@]} -r ${chrootdir}/root 2> /dev/null)
if [[ -n $cmd ]] ; then
msg2 "Removing blacklisted [${blacklist[@]}] ..."
pacman -Rdd "${blacklist[@]}" -r ${chrootdir}/root --noconfirm
else
msg2 "Blacklisted [${blacklist[@]}] not present."
fi
}
install_pkg(){
msg2 "Installing built package ..."
setarch "${arch}" pacman -U *pkg*z -r ${chrootdir}/$(get_user) --noconfirm
}
move_pkg(){
msg2 "Moving [$1] to [${pkgdir}]"
local ext='pkg.tar.xz'
mv *.${ext} ${pkgdir}/
}
2014-10-08 00:11:53 +02:00
display_settings(){
2014-10-08 13:14:13 +02:00
msg "manjaro-tools version: ${version}"
2014-10-08 00:11:53 +02:00
msg "OPTARGS:"
2014-10-08 13:14:13 +02:00
msg2 "arch: ${arch}"
msg2 "branch: ${branch}"
msg2 "chroots: ${chroots}"
2014-10-08 00:11:53 +02:00
msg "PATHS:"
2014-10-08 13:14:13 +02:00
msg2 "chrootdir: ${chrootdir}"
msg2 "profiledir: ${profiledir}"
2014-10-08 00:11:53 +02:00
msg2 "pkgdir: ${pkgdir}"
2014-10-08 13:14:13 +02:00
msg2 "pacman_conf: ${pacman_conf}"
msg2 "makepkg_conf: ${makepkg_conf}"
2014-10-08 00:11:53 +02:00
if ${clean_first};then
msg "PKG:"
msg2 "base_packages: ${base_packages[*]}"
fi
msg "SETS:"
2014-10-08 11:11:19 +02:00
msg2 "profiles: $(get_profiles)"
2014-10-08 00:11:53 +02:00
msg2 "profile: ${profile}"
msg2 "is_profile: ${is_profile}"
if ${is_profile};then
msg "These packages will be built:"
2014-10-08 11:11:19 +02:00
local list=$(cat ${profiledir}/${profile}.set)
for item in ${list[@]}; do
msg2 "$item"
2014-10-08 00:11:53 +02:00
done
else
msg "This package will be built:"
msg2 "${profile}"
fi
}