[arch-haskell] Script for adding and building packages

Dominik Peteler archhaskell at with-h.at
Sat Oct 12 07:40:22 UTC 2013


hello,

I wrote a script for easily add new packages to my habs repo.
I'd be happy if you have a look at it and tell me if my approach to building packages is ok or if I'm horribly wrong.
Note that it's rather hackish and experimental.

regards

dominik
-------------- next part --------------
#!/bin/bash

# ENVIRONMENT:
# $EDITOR:    ... no explanation needed ...
# $HABS:      directory of local HABS copy
# $HABS_REPO: path to local pacman repo
#             add the following lines to pacman.conf
#                 [habs]
#                 SigLevel = Optional TrustAll
#                 Server = <content of HABS_REPO variable here>

# NOTE:
# No support for different cblrepo.db location
# No support for different patch dir location
# No support for different app dir location
#
# All these may be added in the future

# LOCAL VARIABLE DESCRIPTION:
# apkg:        file name of the arch package that was build
# apkgname:    name of the arch package, i.e. lowercase haskell package name with possible "haskell-" prefix
# hpkgname:    name of haskell package as found on hackage
# hpkgversion: version of haskell package
# cblfile:     name of the cabal file
# url:         url to cabal file



# valid command line args:
# - url to cabal file
# - PKG,VER
# - PKG (we'll take the latest version)
if [[ "$1" = "http://hackage.haskell.org"* ]]; then
  hpkgname=$(echo "$1" | cut -d'/' -f6)
  hpkgversion=$(echo "$1" | cut -d'/' -f7)
elif [[ "$1" = *","* ]]; then
  hpkgname=$(echo "$1" | cut -d',' -f1)
  hpkgversion=$(echo "$1" | cut -d',' -f2-)
else
  hpkgname="$1"
  hpkgversion=$(wget -q -O - "http://hackage.haskell.org/package/$1" | grep -o "/packages/archive/$1/[^/]*/$1.cabal" | cut -d'/' -f5)
fi
if [ ! -n "$hpkgname" ]; then
  echo "Invalid name !"
  exit 1
fi
if [ ! -n "$hpkgversion" ]; then
  echo "Invalid version !"
  exit 1
fi



echo "Updating $hpkgname,$hpkgversion"
# switch to branch <Haskell package name>
cd "$HABS" || exit 1
# get latest version of habs repo from github
git checkout master || exit 1
git pull || exit 1
# create branch if it doesn't exist
if git checkout "$hpkgname" 2>/dev/null; then
  git rebase master || exit 1
else
  git branch "$hpkgname" || exit 1
  git checkout "$hpkgname"
fi

cblrepo sync
url=$(cblrepo urls "$hpkgname,$hpkgversion")
cblfile=$(basename "$url")

# obtain cabal file from hackage
# keep original version of the cabal file
# let the user edit a copy of it
# and create patch if copy differs from original
rm -f "$cblfile"
wget "$url" || exit 1
cp "$cblfile" "$cblfile.original"
if [ -e "patches/$cblfile" ]; then
  patch "$cblfile" "patches/$cblfile"
fi
$EDITOR "$cblfile"
if ! cmp -s "$cblfile.original" "$cblfile"; then
  diff "$cblfile.original" "$cblfile" > "patches/$cblfile"
  git add "patches/$cblfile"
  git commit -m "cabal path for version $hpkgversion"
fi

# Try to add package to cblrepo
cblrepo add "$hpkgname,$hpkgversion" || exit 1
git commit cblrepo.db -m "cblrepo.db for version $hpkgversion"
rm "$cblfile" "$cblfile.original"

# create unpatched PKGBUILD with cblrepo
# (we'll patch it later)
if [ -e "patches/$hpkgname.pkgbuild" ]; then
  mv "patches/$hpkgname.pkgbuild" "patches/$hpkgname.pkgbuild.tmp"
fi
cblrepo pkgbuild $hpkgname || exit 1
apkgname=$(echo $hpkgname | tr '[A-Z]' '[a-z]')
if [ -d "haskell-$apkgname" ]; then
  apkgname="haskell-$apkgname"
elif [ -d "$apkgname" ]; then
  true
else
  echo "No pkgdir !"
  exit 1
fi

# keep original version of the PKGBUILD
# create a patched copy
# let the user edit the copy
# and create patch relative to the original - i.e. unpatched - version if copy differs from original
cp "$apkgname/PKGBUILD" "$apkgname/PKGBUILD.original"
if [ -e "patches/$hpkgname.pkgbuild.tmp" ]; then
  patch "$apkgname/PKGBUILD" "patches/$hpkgname.pkgbuild.tmp"
  rm "patches/$hpkgname.pkgbuild.tmp"
fi
$EDITOR "$apkgname/PKGBUILD"
if ! cmp -s "$apkgname/PKGBUILD.original" "$apkgname/PKGBUILD"; then
  diff "$apkgname/PKGBUILD.original" "$apkgname/PKGBUILD" > "patches/$apkgname.pkgbuild"
  git add "patches/$apkgname.pkgbuild"
  git commit -m "PKGBUILD patch for version $hpkgversion"
fi
rm "$apkgname/PKGBUILD.original"

# build the arch package
ghc/helpers/adjust-ghc.sh "$apkgname/PKGBUILD"
makeahpkg "$apkgname" || exit 1
git commit -m "Done with version $hpkgversion"

# merge with master
# QUESTION: is this really a good idea ?
git checkout master
git merge "$hpkgname"

# add the build package to a local repo
cd "$apkgname"
apkg=$(ls -t *.pkg.tar.xz | head -n 1)
sudo cp "$apkg" "$HABS_REPO"
sudo repo-add "$HABS_REPO/habs.db.tar.gz" "$HABS_REPO/$apkg"
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: not available
URL: <http://www.haskell.org/pipermail/arch-haskell/attachments/20131012/3e02bfec/attachment.sig>


More information about the arch-haskell mailing list