3fb1c47e3e057309bfe73d386b546739471275c4
[projects.git] / tools / cpan2deb
1 #!/bin/bash
2 set -e
3
4 usage="cpan2deb <module>"
5
6 if [ $# -ne 1 ]; then
7         echo $usage
8         exit 1
9 fi
10
11 cd $HOME
12 if [ -d locallib ]; then
13         rm -rf locallib
14 fi
15 if [ -d build ]; then
16         rm -rf build
17 fi
18
19 cpan -m $1 1>cpan.out 2>&1 || (echo "cpan failed"; exit 1)
20 builddir=$(ls -rt ~/.cpan/build |tail -1)
21 cd ~/.cpan/build/$builddir
22 perl Makefile.PL PREFIX="~/locallib"
23 make
24 make install 1>~/cpan.out 2>&1
25 echo "Module $1 installed to ~/locallib, output written to cpan.out"
26 cd
27
28 mkdir build
29
30 # build copy file
31 #grep "^Installing" cpan.out |sed "s/Installing //" >build/cpan.tmp
32
33 cd build
34
35 # edit copy file
36 #awk '{FS="/";} \
37 #/lib/ {print $0" $1/usr/share/perl5";} \
38 #/man/ {print $0" $1/usr/share/man";}' cpan.tmp >cpan.cp
39
40 # build package name
41 version=$(perl -M$1 -e 'print $ARGV[0]->VERSION' $1)
42 mname=$1
43 name=lib${mname/::/-}-perl
44 name=${name,,*}
45
46 mkdir -p $name/DEBIAN
47 cat << EOF >$name/DEBIAN/control
48 Package: $name
49 Version: $version
50 Section: base
51 Priority: optional
52 Architecture: all
53 Depends:
54 Maintainer: WagnerTech UG <mail@wagnertech.de>
55 Description: $1 perl modul
56 EOF
57
58 # execute copy script
59 #mkdir -p $name/usr/share/perl5
60 #mkdir -p $name/usr/share/man
61 #. cpan.cp $name 
62
63 # move locallib content
64 mkdir -p $name/usr/local/
65
66 for dir in $(ls ~/locallib); do
67         case $dir in
68         lib) ;;
69         share) mv ~/locallib/share $name/usr/local/
70         ;;
71         man) mv ~/locallib/man $name/usr/
72         ;;
73         esac
74 done
75
76 fakeroot dpkg-deb --build $name
77 cp $name.deb ${name}_$version.deb
78 echo "${name}_$version.deb erstellt."