nix-tools/lib/util-build.sh

97 lines
2.1 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.
ext='pkg.tar.xz'
2014-10-08 11:11:19 +02:00
2014-10-08 00:11:53 +02:00
ch_owner(){
msg "chown -R [$pkg_owner:users] [$1]"
chown -R "$pkg_owner:users" "$1"
2014-10-08 00:11:53 +02:00
}
sign_pkgs(){
cd $pkgdir
su $pkg_owner <<'EOF'
2014-10-08 00:11:53 +02:00
signpkgs
EOF
}
move_pkg(){
msg2 "Moving [$1] to [${pkgdir}]"
local
if [[ -n $PKGDEST ]];then
mv $PKGDEST/*{any,$arch}.${ext} ${pkgdir}/
else
mv *.${ext} ${pkgdir}/
fi
}
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
fi
}
2014-11-13 01:20:33 +01:00
clean_up(){
msg "Cleaning up ..."
if [[ -n $LOGDEST ]];then
msg2 "Cleaning logs $LOGDEST ..."
rm $LOGDEST/*.log
else
msg2 "Cleaning logs $(pwd) ..."
rm $(pwd)/*.log
fi
msg2 "Cleaning ${pkgdir} ..."
rm ${pkgdir}/*.$ext
2014-11-11 21:19:26 +01:00
}
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(){
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
[[ -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 "$1"
}