1#!/bin/sh
2
3print_perl_include_paths() {
4    perl -e 'foreach (@INC) { print "\t$_\n"; }'
5}
6
7APPNAME=rebot3.pl
8
9echo "Preparing to install $APPNAME. First let's do some checks."
10echo
11
12# perl executable check
13echo -n "Checking for perl..."
14perl -e 'print " OK\n"' 2> /dev/null
15if [ $? -ne 0 ]; then
16    echo " not found"
17    cat <<EOF
18There was error running perl. Make sure perl is installed on your system and
19the directory containing your perl executable is in your PATH environment
20variable.
21EOF
22    exit 1
23fi
24
25# perl version check
26echo -n "Checking for correct perl version..."
27perl -e 'require 5.004; print " OK (version $])\n"' 2> /dev/null
28if [ $? -ne 0 ]; then
29    perl -e 'print " incorrect (version $])\n"'
30    cat <<EOF
31$APPNAME requires at least perl version 5.004. Please update to a supported
32version.
33EOF
34    exit 2
35fi
36
37# CDDB module check
38echo -n "Checking for module CDDB..."
39perl -MCDDB -e 'print " OK\n"' 2> /dev/null
40if [ $? -ne 0 ]; then
41    echo " not installed"
42    cat <<EOF
43The perl module CDDB is not installed correctly. Please install it and make
44sure it is available in one of perl's include paths. You can get this module
45from www.cpan.org. Or use search.cpan.org to let CPAN's search engine make
46the dirty work for you.
47Btw, perl's include paths are:
48EOF
49    print_perl_include_paths
50    exit 3
51fi
52
53# MP3::ID3v1Tag module check
54echo -n "Checking for module MP3::ID3v1Tag..."
55perl -MMP3::ID3v1Tag -e 'print " OK\n"' 2> /dev/null
56if [ $? -ne 0 ]; then
57    echo " not installed"
58    cat <<EOF
59The perl module MP3v1Tag is not installed correctly. Please install it and
60make sure it is available in one of perl's include paths. You can get this
61module from www.cpan.org. Or use search.cpan.org to let CPAN's search engine
62make the dirty work for you.
63Btw, perl's include paths are:
64EOF
65    print_perl_include_paths
66    exit 4
67fi
68
69echo
70echo "Looks good. Proceeding with install."
71echo
72
73# default install paths
74BIN_PATH=/usr/local/bin
75MAN_PATH=/usr/local/man
76
77# bin path prompt
78echo "Enter the path where $APPNAME should be installed."
79echo -n "[$BIN_PATH]: "
80read bin_path
81: ${bin_path:=$BIN_PATH}
82
83# man path prompt
84echo "Enter the path where $APPNAME's man page should be installed."
85echo -n "[$MAN_PATH]: "
86read man_path
87: ${man_path:=$MAN_PATH}
88
89# translate leading tilde to users home dir
90bin_path=$(perl -e '$p = $ARGV[0]; $h = ($ENV{HOME} || $ENV{LOGDIR}); unless (defined $h) { print $p; exit; } $p =~ s/^~/$h/; print $p;' "$bin_path")
91man_path=$(perl -e '$p = $ARGV[0]; $h = ($ENV{HOME} || $ENV{LOGDIR}); unless (defined $h) { print $p; exit; } $p =~ s/^~/$h/; print $p;' "$man_path")
92
93# check for source files
94for n in $APPNAME $APPNAME.1; do
95    if ! [ -r $n ]; then
96        echo "$n not found in current directory. Aborting installation..."
97        exit 5
98    fi
99done
100
101# the installation itself
102error=0
103install -d -m 0755 "$bin_path";                 let "error = error + $?"
104install    -m 0755 $APPNAME "$bin_path";        let "error = error + $?"
105install -d -m 0755 "$man_path/man1";            let "error = error + $?"
106install    -m 0644 $APPNAME.1 "$man_path/man1"; let "error = error + $?"
107
108# bye
109echo
110if [ $error -ne 0 ]; then
111    cat <<EOF
112Oops. Some error occurred while installing $APPNAME. Please investigate the
113problem and run `basename $0` again.
114EOF
115    exit 6
116else
117    cat <<EOF
118Congratulations. You just installed $APPNAME successfully.
119Please send any comments or suggestions to panos@bigfoot.de.
120Have fun!
121EOF
122fi
123