#!/bin/bash # saturnin - Smart and ready desktop helper # See LICENSE file for copyright and license details. tmp=$(mktemp) sed -e 's/ = /=/' < config.mk > $tmp . $tmp rm -f $tmp bindir=${DESTDIR}${PREFIX}/bin list_of_bins() { echo bin/saturnin-abrt echo bin/saturnin-czrates echo bin/saturnin-dmenu echo bin/saturnin-get echo bin/saturnin-iam echo bin/saturnin-ini echo bin/saturnin-ip echo bin/saturnin-ln echo bin/saturnin-push echo bin/saturnin-revert echo bin/saturnin-watch echo bin/saturnin-www } list_of_installed_bins() { list_of_bins | sed -e "s/bin/$(sed -e 's/\//\\\//g' <<<$bindir)/" } die() { for l in "$@"; do echo "$l" >&2; done exit 9 } build1() { local srcpath dstpath srcpath=$1 dstpath=${srcpath%.skel} perl -pe " s|__SATURNIN_INI_PATH__|$SATURNIN_INI_PATH_GLOBAL:\\\$HOME/$SATURNIN_INI_PATH_USER|; s|__VERSION__|$(get_version)|; " < $srcpath > $dstpath echo $dstpath >> built.list } build() { local srcpath find -type f -name '*.skel' \ | while read srcpath; do build1 "$srcpath" done } clean() { test -f built.list && { cat built.list | xargs rm -f rm -f built.list } || : } dist() { local version=$(get_version) local dirname=saturnin-$version mkdir -p $dirname cp -R bin \ config.mk \ Makefile \ README \ LICENSE \ setup \ utils \ $dirname sed -ie "s/^VERSION = .*/VERSION = $version/" $dirname/config.mk tar -cf $dirname.tar $dirname gzip $dirname.tar rm -rf $dirname } install() { mkdir -vp $bindir list_of_bins | xargs cp -vrt $bindir list_of_installed_bins | xargs chmod -v 755 test -f .autoclean && clean || : } get_version() { local version=$VERSION local stage=$STAGE if git rev-parse HEAD >&/dev/null; then # we are in git repo... so we can get smart local lasttag=$(git tag | grep ^v | tail -n1) if ! git describe --tags --exact-match HEAD >&/dev/null; then # we are not at later commit than the last tag local sha=g$(git describe --always HEAD) fi if test "$(git diff --shortstat 2>/dev/null)" != ""; then # thr tree is "dirty", i.e. has been edited local dirty=dirty fi version=${lasttag:1} case $stage:$sha:$dirty in ::) suffix="" ;; ::dirty) suffix="+$dirty" ;; :g*:) suffix="+$sha" ;; :g*:dirty) suffix="+$sha.dirty" ;; *::) suffix="-$stage" ;; *::dirty) suffix="-$stage+$dirty" ;; *:g*:) suffix="-$stage+$sha" ;; *:g*:dirty) suffix="-$stage+$sha.$dirty" ;; esac version=$version$suffix fi echo $version } run_test() { pushd test find -maxdepth 1 -type f \! -name '*.skel' | while read test; do chmod 0755 $test $test || exit $? done popd } uninstall() { list_of_installed_bins | xargs rm -vf } case $1 in build|clean|dist|install|install_manpages|manpages|uninstall) $1 ;; test) run_test ;; *) echo "usage: $(basename $0) build|clean|dist|install|test|uninstall" >&2 esac