nix-tools/lib/util-build.sh

99 lines
2.2 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.
sign_pkgs(){
cd $pkgdir
2014-11-13 13:33:38 +01:00
su $1 <<'EOF'
2014-10-08 00:11:53 +02:00
signpkgs
EOF
}
move_pkg(){
2014-11-13 13:33:38 +01:00
local ext='pkg.tar.xz'
if [[ -n $PKGDEST ]];then
mv $PKGDEST/*{any,$arch}.${ext} ${pkgdir}/
else
mv *.${ext} ${pkgdir}/
fi
2014-11-13 22:43:07 +01:00
chown -R "$1:users" "${pkgdir}"
}
2014-10-08 00:11:53 +02:00
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
}
prepare_dir(){
if ! [[ -d $1 ]];then
mkdir -p $1
2014-11-13 22:43:07 +01:00
msg "Creating $1"
chown -R "$2:users" "$(dirname $1)"
2014-10-08 00:11:53 +02:00
fi
}
2014-11-13 01:20:33 +01:00
clean_up(){
msg "Cleaning up ..."
2014-11-13 13:33:38 +01:00
local query=$(find ${pkgdir} -maxdepth 1 -name "*.*")
if [[ -n $query ]];then
rm -v $query
2014-11-13 01:20:33 +01:00
fi
2014-11-13 13:33:38 +01:00
if [[ -z $LOGDEST ]];then
query=$(find $(pwd) -maxdepth 2 -name '*.log')
if [[ -n $query ]];then
rm -v $query
fi
2014-11-13 01:53:11 +01:00
fi
2014-11-13 13:33:38 +01:00
if [[ -z $SRCDEST ]];then
query=$(find $(pwd) -maxdepth 2 -name '*.?z?')
if [[ -n $query ]];then
rm -v $query
fi
2014-11-13 01:53:11 +01:00
fi
2014-11-11 21:19:26 +01:00
}
2014-10-08 11:11:19 +02:00
eval_profile(){
2014-11-13 01:53:11 +01:00
eval "case $1 in
2014-10-08 11:11:19 +02:00
$(get_profiles)) is_profile=true ;;
*) is_profile=false ;;
esac"
}
2014-10-23 00:46:43 +02:00
blacklist_pkg(){
2014-11-13 01:20:33 +01:00
local blacklist=('libsystemd') cmd=$(pacman -Q ${blacklist[@]} -r $1/root 2> /dev/null)
2014-10-23 00:46:43 +02:00
if [[ -n $cmd ]] ; then
msg2 "Removing blacklisted [${blacklist[@]}] ..."
2014-11-13 01:20:33 +01:00
pacman -Rdd "${blacklist[@]}" -r $1/root --noconfirm
2014-10-23 00:46:43 +02:00
else
msg2 "Blacklisted [${blacklist[@]}] not present."
fi
}
2014-11-13 01:20:33 +01:00
chroot_clean(){
for copy in "$1"/*; do
2014-11-13 13:33:38 +01:00
[[ -d ${copy} ]] || continue
2014-11-13 01:20:33 +01:00
msg2 "Deleting chroot copy '$(basename "${copy}")'..."
2014-11-13 13:33:38 +01:00
lock 9 "${copy}.lock" "Locking chroot copy '${copy}'"
2014-11-13 01:20:33 +01:00
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 "$1"
}