Debian Codegraph @

install-pkg.sh

raw
1 #!/bin/bash
2 #
3 # A basic script to retrieve and install packages to a local directory
4 # (e.g. in a users home space)
5 #
6 # We assume packages can be compiled in the "standard" way using
7 # "configure" and "make"
8 #
9 # A better alternative is to use your inbuilt package manager to install things
10 # e.g.
11 # Debian/Ubuntu:
12 # sudo apt-get install package_name
13 # Fedora/Red Hat/CentOS:
14 # sudo yum install package_name
15 # OpenSUSE:
16 # zypper install package_name
17 # MacPorts:
18 # sudo port install package_name
19 # Homebrew:
20 # brew install package_name
21 #
22 # Written by Daniel Price, April 2020
23 # Contact: [email protected]
24 #
25 xzdist=xz-5.2.1.tar.gz;
26 xzurl="http://tukaani.org/xz/";
27 if [ $# -le 1 ]; then
28 echo "Usage: $0 http://blah.org/release/blah.tar.gz install_dir";
29 exit 1;
30 fi
31 disturl=$1;
32 installprefix=$2;
33 distfile=$(basename $disturl);
34 pkg_name=$(basename $distfile .tar.gz)
35 pkg_name=$(basename $pkg_name .tar.xz)
36 extension=${distfile/$pkg_name/}
37 pkg_dir=${distfile/$extension/};
38 #
39 #--Check that the install dir is present.
40 # This is not strictly necessary, but it means we install cairo and
41 # pixman to the same location as the giza libraries and linking of
42 # giza with cairo will work automatically.
43 #
44 check_install_dir_exists()
45 {
46 if [ ! -d $installprefix ]; then
47 echo;
48 echo " ERROR: installation directory $installprefix does not exist "
49 echo;
50 return 1;
51 fi
52 }
53 #
54 #--if not already downloaded, retrieve the tarball using wget
55 #
56 download_dist_file()
57 {
58 if [ ! -f $distfile ]; then
59 echo "$distfile not downloaded";
60 if !(type -p wget); then
61 echo "ERROR: $0 requires the \"wget\" command, which is not present on";
62 echo "your system. Instead, you will need to download the following file by hand:"; echo
63 echo "$disturl";
64 echo; echo "To proceed, download this files, place them in the current directory and try again"
65 return 1;
66 else
67 wget $disturl;
68 fi
69 fi
70 if [ ! -f $distfile ]; then
71 echo; echo "ERROR: $distfile download failed. Please try again"; echo;
72 return 1;
73 else
74 echo "$distfile found in current dir";
75 return 0;
76 fi
77 }
78 #
79 #--unpack the distribution file with tar or unxz, depending on compression
80 #
81 unpack_dist_file()
82 {
83 echo ":: unpacking $distfile to $installprefix";
84 if [ $extension==".tar.xz" ]; then
85 tar -Jxf $distfile;
86 else
87 tar xfz $distfile;
88 fi
89 if [ ! -d $pkg_dir ]; then
90 echo; echo "ERROR: failed to unpack (no directory $pkg_dir)"; echo;
91 return 1;
92 if [ $extension==".tar.xz" ]; then
93 #
94 #--install xzutils if tar -Jxf fails...
95 #
96 echo "Attempting to download xzutils in order to unpack cairo..."
97 wget $xzurl/$xzdist;
98 tar xfz $xzdist;
99 xzdir=${xzdist/.tar.gz/};
100 cd $xzdir;
101 xzinstalldir=/tmp/xz-tmp/;
102 ./configure --prefix=$xzinstalldir;
103 make || ( echo; echo "ERROR during xzutils build"; echo; return $? );
104 make install || ( echo; echo "ERROR installing xzutils into $xzinstalldir"; echo; return $? );
105 cd ..;
106 #
107 #--now unpack using xz utils
108 #
109 ${xzinstalldir}/bin/unxz $distfile;
110 tar xf ${distfile/.xz/};
111 if [ ! -d $pkg_dir ]; then
112 echo; echo "ERROR: failed to unpack even with xz downloaded (no directory $pkg_dir)"; echo;
113 return 1;
114 fi
115 fi
116 fi
117 }
118 #
119 #--install the package to the local file system
120 #
121 install_package()
122 {
123 echo ":: installing $pkg_name"
124 cd $pkg_dir;
125 ./configure --prefix=$installprefix > /dev/null || ( echo; echo "ERROR during config"; echo; return $? );
126 make > /dev/null || ( echo; echo "ERROR during build"; echo; return $? );
127 make install > /dev/null || ( echo; echo "ERROR installing into $installdir"; echo; return $? );
128 cd ..;
129 }
130 check_and_finish()
131 {
132 echo ":: $pkg_name installation successful"; echo;
133 echo "type \"make\" to compile your main program"; echo;
134 echo "You should also add the following line to your .bashrc or equivalent:"; echo;
135 if [[ `uname` =~ Darwin ]]; then
136 echo "export DYLD_LIBRARY_PATH=\$DYLD_LIBRARY_PATH:$installprefix/lib";
137 else
138 echo "export LD_LIBRARY_PATH=\$LD_LIBRARY_PATH:$installprefix/lib";
139 fi
140 echo;
141 }
142 check_install_dir_exists; err=$?;
143 if [ $err -gt 0 ]; then exit $err; fi
144 download_dist_file; err=$?;
145 if [ $err -gt 0 ]; then exit $err; fi
146 unpack_dist_file; err=$?;
147 if [ $err -gt 0 ]; then exit $err; fi
148 install_package; err=$?;
149 if [ $err -gt 0 ]; then exit $err; fi
150 check_and_finish; err=$?;
151 if [ $err -gt 0 ]; then exit $err; fi