Merge ../projects
[projects.git] / tools / cpan2deb
1 #!/bin/bash
2 set -e
3
4 function process_lib {
5         pushd ~/locallib 1>/dev/null
6                 if [ $(ls lib/p*/ |wc -w) -eq 1 ]
7                 then
8                         # seems to be arichtecturalsub dir
9                         arch_dir=$(ls lib/p*/)
10                         cd lib/p*/
11                         mv $arch_dir/* .
12                         rmdir $arch_dir
13                         cd ../..
14                 fi
15                 
16                 # check, if there is a real archtecturel depandence
17                 shared_lib=$(find . -name "*.so")
18                 if [ -n "$shared_lib" ]
19                 then
20                         arch=$(arch)
21                 fi                      
22         popd 1>/dev/null
23         mv ~/locallib/lib $name/usr/
24 }
25
26 usage="cpan2deb <module>"
27
28 if [ $# -ne 1 ]; then
29         echo $usage
30         exit 1
31 fi
32
33 #cd $HOME
34 if [ -d locallib ]; then
35         rm -rf locallib
36 fi
37 #if [ -d build ]; then
38 #       rm -rf build
39 #fi
40
41 start_dir=$(pwd)
42
43 echo "call CPAN ..."
44 cpan -m $1 1>$start_dir/cpan.out 2>&1 || (echo "cpan failed"; exit 1)
45
46 # find build directory
47 mname=$1
48 name=lib${mname/::/-}-perl
49 name=${name,,*}
50 builddir=$(ls -rtd ~/.cpan/build/*/ |tail -1)
51
52 pushd $builddir 1>/dev/null
53         perl Makefile.PL INSTALL_BASE="~/locallib"
54         make
55         make install 1>>~/cpan.out 2>&1
56         echo "Module $1 installed to ~/locallib, output written to $start_dir/cpan.out"
57 popd 1>/dev/null
58
59 arch=all
60
61 # move locallib content
62 mkdir -p $name/usr/
63
64 for dir in $(ls ~/locallib); do
65         case $dir in
66         lib) process_lib
67         ;;
68         share) mv ~/locallib/share $name/usr/
69         ;;
70         man) mv ~/locallib/man $name/usr/
71         ;;
72         esac
73 done
74
75 # check version
76 export PERL5LIB="$start_dir/$name/usr/lib/perl5:$PERL5LIB"
77 version=$(perl -M$mname -e 'print $ARGV[0]->VERSION' $mname)
78
79 arch_name=""
80 if [ "$arch" != "all" ]
81 then
82         arch_name="_$arch"
83         if [ "$arch" = "i686" ]
84         then
85                 # i686-Paketarchitektur gibt es nicht
86                 arch="i386"
87         fi
88 fi
89
90 mkdir -p $name/DEBIAN
91 cat << EOF >$name/DEBIAN/control
92 Package: $name
93 Version: $version
94 Section: base
95 Priority: optional
96 Architecture: $arch
97 Depends:
98 Maintainer: WagnerTech UG <mail@wagnertech.de>
99 Description: $1 perl modul
100 EOF
101
102 fakeroot dpkg-deb --build $name
103 cp $name.deb ${name}_$version$arch_name.deb
104 echo "${name}_$version$arch_name.deb erstellt."
105