Skip to content

Commit

Permalink
Fix #75 - clean build dir. Also check tmpfs free space, define exit c…
Browse files Browse the repository at this point in the history
…ode 7, touch up release.sh and work towards #38
  • Loading branch information
oshazard committed Oct 13, 2016
1 parent 85635b2 commit 246d3df
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 25 deletions.
54 changes: 42 additions & 12 deletions apacman
Original file line number Diff line number Diff line change
Expand Up @@ -864,6 +864,41 @@ offlineinstall() {
fi
}

# Sanity check for umask permissions ($1 is build directory)
checkumask() {
otherbits=$(ls -ld "$1" | awk '{print $1}' | cut -c 8,10)
if [[ $otherbits != "rx" ]]; then
mask=$(umask 2>/dev/null)
if [[ $mask != *022 ]]; then
echo -e "${COLOR6}warning:${ENDCOLOR} umask set to ${COLOR4}${mask}${ENDCOLOR} (should be 022)"
fi
rmdir "$1"
err "${COLOR7}error:${COLOR1} no write permission in ${1}${ENDCOLOR}"
fi
}

# Sanity check for tmpfs free disk space ($1 is build directory)
checkcapacity() {
capacity=$(df -P "$1" 2>/dev/null | tail -n 1 | awk '{print $5}' | tr -dc '[0-9]\n')
if [[ $capacity -ge 99 ]]; then
echo -e "${COLOR7}error:${COLOR1} no free space in ${1}${ENDCOLOR}"
[[ "$warn" == 1 ]] || exit 7
elif [[ $capacity -gt 90 ]]; then
echo -e "${COLOR6}warning:${ENDCOLOR} low disk space in ${1} (tmpfs)"
fi
}

# Clean package source ($1 is package)
cleanbuild() {
whatlinkshere=$(ls -l --color=never "$builddir" | grep ^l | grep "/${1}$" | awk '{print $(NF-2)}')
if [[ $whatlinkshere ]]; then
echo -e "${COLOR3}notice:${ENDCOLOR} cleaning delayed until finished with $whatlinkshere"
else
echo -e "${COLOR5}::${COLOR1} Cleaning build ${builddir}/$1 ${ENDCOLOR}"
rm -rf "${builddir}/$1"
fi
}

# Installs packages from aur ($1 is package, $2 is dependency or explicit)
aurinstall() {
if [[ $offline = '1' ]]; then
Expand All @@ -882,22 +917,14 @@ aurmakepkg() {
# Prepare the installation directory
# If there is an old directory and aurversion is not newer, use old directory
if parser "$dir/PKGBUILD" &>/dev/null && ! aurversionisnewer "$1" "$pkgver-$pkgrel"; then
checkumask "$dir"
checkcapacity "$dir"
cd "$dir"
else
[[ -d "$dir" ]] && rm -rf "$dir"
mkdir -p "$builddir"

# Check umask permissions
otherbits=$(ls -ld "$builddir" | awk '{print $1}' | cut -c 8,10)
if [[ $otherbits != "rx" ]]; then
mask=$(umask 2>/dev/null)
if [[ $mask != *022 ]]; then
echo -e "${COLOR6}warning:${ENDCOLOR} umask set to ${COLOR4}${mask}${ENDCOLOR} (should be 022)"
fi
rmdir "$builddir"
err "${COLOR7}error:${COLOR1} no write permission in ${builddir}${ENDCOLOR}"
fi

checkumask "$builddir"
checkcapacity "$builddir"
cd "$builddir"
curl -Lfs "$(pkglink $1)" > "$1.tar.gz"
cstatus=$?; curlyq "$cstatus" "$1"
Expand Down Expand Up @@ -1000,6 +1027,9 @@ aurmakepkg() {
cp ${pkgtar} $savedir/ 2>/dev/null || runasroot cp ${pkgtar} $savedir/
echo -e "${COLOR5} -> ${COLOR1}Installing ${1}${ENDCOLOR}"
buildinstall $1 $2 ${savedir}/$pkgtar
cleanbuild $1
elif [[ $nofail ]]; then
cleanbuild $1
fi
}

Expand Down
2 changes: 1 addition & 1 deletion apacman.8
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ Package does not exist
.IP 6
No internet connection
.IP 7
\-\-\-
No free space in tmpfs
.IP 8
One or more package(s) failed to build, keep going
.IP 9
Expand Down
2 changes: 1 addition & 1 deletion docs/apacman.8.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 16 additions & 11 deletions release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,16 @@ err() {
manual2html() {
mkdir -p docs/
for manual in $manpages; do
echo "==> Generating docs/${manual}.html"
output="docs/${manual}.html"
[ -f "$output" ] && hash=$(md5sum "$output");
cat "$manual" | groff -mandoc -Thtml | grep -v "^<\!--" > "docs/${manual}.html"
echo "$hash" | md5sum -c &>/dev/null ||
echo "==> Generating docs/${manual}.html"
done
}

compare2rel() {
lastrel=$(git tag 2>/dev/null | tail -n 1)
if [[ "$lastrel" ]]; then
tagged=$(git log -1 --pretty=oneline $lastrel | awk '{print $1}')
head=$(git log -1 --pretty=oneline HEAD | awk '{print $1}')
Expand All @@ -38,21 +42,22 @@ testunits() {

createarchive() {
newrel="${lastrel#v}"
mkdir -p "$tmpdir/${pkgname}-${newrel}" &&
cp * "$tmpdir/${pkgname}-${newrel}/" &&
cd "$tmpdir" &&
tar -czvf "${pkgname}-${newrel}.tar.gz" "${pkgname}-${newrel}/" &&
echo "==> ${pkgname}-${newrel}.tar.gz" &&
exit 0
if [ ! -z "$newrel" ]; then
mkdir -p "$tmpdir/${pkgname}-${newrel}" &&
find . -maxdepth 1 -type f -exec cp {} "$tmpdir/${pkgname}-${newrel}/" \; &&
cd "$tmpdir" &&
tar -czvf "${pkgname}-${newrel}.tar.gz" "${pkgname}-${newrel}/" &&
echo "==> ${pkgname}-${newrel}.tar.gz" &&
return 0
fi
return 1
}

manual2html
staging=$(git status -s --untracked-files=no 2>/dev/null)
ready=$(echo "$staging" | wc -l)
lastrel=$(git tag 2>/dev/null | tail -n 1)

ready=$(echo "$staging" | grep -v ^$ | wc -l)
[ "$ready" -eq 0 ] || err "$staging"
compare2rel || err ":: HEAD not tagged"
testunits || err ":: Unit tests failed"
compare2rel || err ":: HEAD not tagged"
createarchive || err ":: Unable to create archive"
echo "==> Release ready"

0 comments on commit 246d3df

Please sign in to comment.