<commit_before>#!/bin/bash

WORK_DIR=/tmp/jasmin-packager
COMMONS_DIR=./commons
PYPI_BASEURL="https://pypi.python.org/packages/source/j/jasmin"

if [ $# -ne 2 ]; then
    echo "Usage: $0 pypi-version debian-version"
    echo "Example:"
    echo "$0 0.6b19 0.6.19-1"
    echo
    echo "Tips:"
    echo " - changelog have to be updated manually."
    echo
    exit 1
fi

[ -d $COMMONS_DIR ] || exit 10

# Reset work folder
[ -d $WORK_DIR ] && rm -rf $WORK_DIR
mkdir $WORK_DIR $WORK_DIR/package $WORK_DIR/jasmin

# Download jasmin
curl -o $WORK_DIR/jasmin.tgz "$PYPI_BASEURL/jasmin-$1.tar.gz" || exit 11
tar zxf $WORK_DIR/jasmin.tgz -C $WORK_DIR

# Prepare work folder
cp -r $COMMONS_DIR/DEBIAN $WORK_DIR/package/

## Documentation
mkdir -p $WORK_DIR/package/usr/share/doc/python-jasmin
cp $COMMONS_DIR/changelog $COMMONS_DIR/copyright $WORK_DIR/package/usr/share/doc/python-jasmin
cp $WORK_DIR/package/usr/share/doc/python-jasmin/changelog $WORK_DIR/package/usr/share/doc/python-jasmin/changelog.Debian
gzip --best $WORK_DIR/package/usr/share/doc/python-jasmin/changelog
gzip --best $WORK_DIR/package/usr/share/doc/python-jasmin/changelog.Debian
# TODO: include Jasmin documentation

# Update package version
sed -i "s/%debversion%/$2/" $WORK_DIR/package/DEBIAN/control

## /etc folder
mkdir -p $WORK_DIR/package/etc/init.d $WORK_DIR/package/etc/jasmin/resource $WORK_DIR/etc/jasmin/store
cp $WORK_DIR/jasmin-$1/misc/config/jasmin.cfg $WORK_DIR/package/etc/jasmin/
cp $WORK_DIR/jasmin-$1/misc/config/resource/* $WORK_DIR/package/etc/jasmin/resource/
cp $WORK_DIR/jasmin-$1/misc/config/init-script/jasmind-ubuntu $WORK_DIR/package/etc/init.d/jasmind

## /usr/bin folder
mkdir -p $WORK_DIR/package/usr/bin $WORK_DIR/package/usr/lib/python2.7/dist-packages
cp -r $WORK_DIR/jasmin-$1/jasmin $WORK_DIR/package/usr/lib/python2.7/dist-packages/python-jasmin
ln -s $WORK_DIR/package/usr/lib/python2.7/dist-packages/python-jasmin/bin/jasmind.py $WORK_DIR/package/usr/bin/jasmind

# Remove unneeded files
find $WORK_DIR/package -name ".gitignore" | xargs rm -f 

# Create md5sums
cd $WORK_DIR/package;find usr -type f -exec md5sum {} \; > md5sums;cd -;mv $WORK_DIR/package/md5sums $WORK_DIR/package/DEBIAN

# Fix file & folder permissions
find $WORK_DIR/package -type d | xargs chmod 755
find $WORK_DIR/package -type f | xargs chmod 644
chmod 755 $WORK_DIR/package/DEBIAN/preinst
chmod 755 $WORK_DIR/package/DEBIAN/postinst
chmod 755 $WORK_DIR/package/DEBIAN/prerm
chmod 755 $WORK_DIR/package/DEBIAN/postrm
chmod 755 $WORK_DIR/package/etc/init.d/jasmind
chmod 755 $WORK_DIR/package/usr/bin/jasmind

# Build package
fakeroot dpkg-deb --build $WORK_DIR/package
mv $WORK_DIR/package.deb packages/jasmin-$2_all.deb
lintian packages/jasmin-$2_all.deb<commit_msg>Changed output package file name<commit_after>#!/bin/bash

WORK_DIR=/tmp/jasmin-packager
COMMONS_DIR=./commons
PYPI_BASEURL="https://pypi.python.org/packages/source/j/jasmin"

if [ $# -ne 2 ]; then
    echo "Usage: $0 pypi-version debian-version"
    echo "Example:"
    echo "$0 0.6b19 0.6.19-1"
    echo
    echo "Tips:"
    echo " - changelog have to be updated manually."
    echo
    exit 1
fi

[ -d $COMMONS_DIR ] || exit 10

# Reset work folder
[ -d $WORK_DIR ] && rm -rf $WORK_DIR
mkdir $WORK_DIR $WORK_DIR/package $WORK_DIR/jasmin

# Download jasmin
curl -o $WORK_DIR/jasmin.tgz "$PYPI_BASEURL/jasmin-$1.tar.gz" || exit 11
tar zxf $WORK_DIR/jasmin.tgz -C $WORK_DIR

# Prepare work folder
cp -r $COMMONS_DIR/DEBIAN $WORK_DIR/package/

## Documentation
mkdir -p $WORK_DIR/package/usr/share/doc/python-jasmin
cp $COMMONS_DIR/changelog $COMMONS_DIR/copyright $WORK_DIR/package/usr/share/doc/python-jasmin
cp $WORK_DIR/package/usr/share/doc/python-jasmin/changelog $WORK_DIR/package/usr/share/doc/python-jasmin/changelog.Debian
gzip --best $WORK_DIR/package/usr/share/doc/python-jasmin/changelog
gzip --best $WORK_DIR/package/usr/share/doc/python-jasmin/changelog.Debian
# TODO: include Jasmin documentation

# Update package version
sed -i "s/%debversion%/$2/" $WORK_DIR/package/DEBIAN/control

## /etc folder
mkdir -p $WORK_DIR/package/etc/init.d $WORK_DIR/package/etc/jasmin/resource $WORK_DIR/etc/jasmin/store
cp $WORK_DIR/jasmin-$1/misc/config/jasmin.cfg $WORK_DIR/package/etc/jasmin/
cp $WORK_DIR/jasmin-$1/misc/config/resource/* $WORK_DIR/package/etc/jasmin/resource/
cp $WORK_DIR/jasmin-$1/misc/config/init-script/jasmind-ubuntu $WORK_DIR/package/etc/init.d/jasmind

## /usr/bin folder
mkdir -p $WORK_DIR/package/usr/bin $WORK_DIR/package/usr/lib/python2.7/dist-packages
cp -r $WORK_DIR/jasmin-$1/jasmin $WORK_DIR/package/usr/lib/python2.7/dist-packages/python-jasmin
ln -s $WORK_DIR/package/usr/lib/python2.7/dist-packages/python-jasmin/bin/jasmind.py $WORK_DIR/package/usr/bin/jasmind

# Remove unneeded files
find $WORK_DIR/package -name ".gitignore" | xargs rm -f 

# Create md5sums
cd $WORK_DIR/package;find usr -type f -exec md5sum {} \; > md5sums;cd -;mv $WORK_DIR/package/md5sums $WORK_DIR/package/DEBIAN

# Fix file & folder permissions
find $WORK_DIR/package -type d | xargs chmod 755
find $WORK_DIR/package -type f | xargs chmod 644
chmod 755 $WORK_DIR/package/DEBIAN/preinst
chmod 755 $WORK_DIR/package/DEBIAN/postinst
chmod 755 $WORK_DIR/package/DEBIAN/prerm
chmod 755 $WORK_DIR/package/DEBIAN/postrm
chmod 755 $WORK_DIR/package/etc/init.d/jasmind
chmod 755 $WORK_DIR/package/usr/bin/jasmind

# Build package
fakeroot dpkg-deb --build $WORK_DIR/package
mv $WORK_DIR/package.deb packages/python-jasmin-$2_all.deb
lintian packages/python-jasmin-$2_all.deb
{'fraction_non_alphanumeric': 0.13579576317218903, 'fraction_numerical': 0.021365200072424408, 'mean_word_length': 4.347531461761859, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1720322', 'n_tokens_mistral': 2259, 'n_tokens_neox': 2152, 'n_words': 397}