Bug 14923: Remove C4::Dates from labels/label-item-search.pl
[koha.git] / install_misc / ubuntu-packages.sh
blob11f8a7fc9fbd237acb75ff2973d1d99ce3a5cb04
1 #!/bin/bash
3 # Copyright 2012 Universidad Nacional de Cordoba
4 # Written by Tomas Cohen Arazi
5 # Mark Tompsett
7 # This file is part of Koha.
9 # Koha is free software; you can redistribute it and/or modify it
10 # under the terms of the GNU General Public License as published by
11 # the Free Software Foundation; either version 3 of the License, or
12 # (at your option) any later version.
14 # Koha is distributed in the hope that it will be useful, but
15 # WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 # GNU General Public License for more details.
19 # You should have received a copy of the GNU General Public License
20 # along with Koha; if not, see <http://www.gnu.org/licenses>.
22 # Output simple help
23 usage() {
24 local scriptname=$(basename $0)
25 cat <<EOF
26 $scriptname
28 Query for missing dependencies. Print the install command for them if specified.
30 Usage:
31 $scriptname -r
32 $scriptname -ic
33 $scriptname -h
35 -r | --report Report the status of Koha's dependencies
36 -ic | --install-command Display the install command for the missing dependencies
37 -h | --help Display this help message
38 EOF
41 # Check if the package is installed
42 packageInstalled() {
43 local package=$1
44 local package_status=`dpkg-query --showformat='${Status}' \
45 -W $package 2> /dev/null`
47 if [ "$package_status" == "install ok installed" ] ; then
48 echo "yes"
49 else
50 echo "no"
54 # Get the installed package version
55 getPackageVersion() {
56 local package=$1
57 dpkg-query --showformat='${Version}' -W $package
60 # A parameter is required.
61 if [ "$#" -eq "0" ]; then
62 usage
63 exit 1
66 # Initialize variables
67 CHECK=no
68 INSTALLCMD=no
69 HELP=no
71 # Loop over parameters
72 while (( "$#" )); do
73 case $1 in
74 -r | --report )
75 CHECK=yes
77 -ic | --install-command )
78 INSTALLCMD=yes
80 -h | --help)
81 HELP=yes
83 * )
84 usage
85 exit 1
86 esac
87 shift
88 done
90 if [ "$HELP" = "yes" ]; then
91 usage
92 exit 0
95 # Determine what directory this script is in, the packages files
96 # should be in the same path.
97 DIR=`dirname $0`
99 # Determine the Ubuntu release
100 UBUNTU_RELEASE=`lsb_release -r | cut -f2 -d' '`
101 UBUNTU_PACKAGES_FILE=$DIR/ubuntu.$UBUNTU_RELEASE.packages
103 # Check for the release-specific packages file. Default to the general one
104 # but warn the user about LTS releases recommended, if they are attempting
105 # to do an install command option.
106 if [ ! -e $UBUNTU_PACKAGES_FILE ]; then
107 UBUNTU_PACKAGES_FILE=$DIR/ubuntu.packages
108 if [ "$INSTALLCMD" == "yes" ]; then
109 echo "# There's no packages file for your distro/release"
110 echo "# WARNING! We strongly recommend an LTS release."
114 # We where asked to print the packages list and current versions (if any)
115 UBUNTU_PACKAGES=`awk '{print $1}' $UBUNTU_PACKAGES_FILE | grep -v '^\s*#' | grep -v '^\s*$'`
117 # Only output this on an install command option in order to maintain
118 # output equivalence to the former script, in the case of reporting
119 # only.
120 if [ "$INSTALLCMD" == "yes" ]; then
122 # Tell them which file being used to determine the output.
123 echo "# Using the $UBUNTU_PACKAGES_FILE file as source"
125 # Comment for skiping the dots if needed ....
126 if [ "$CHECK" == "no" ]; then
127 echo -n "#"
131 # Initialize variable to accumulate missing packages in.
132 MISSING_PACKAGES=""
134 # Loop used to accumulate the missing packages and display package information if requested to report.
135 for PACKAGE in $UBUNTU_PACKAGES; do
137 # If an install command option is running, but not a report option,
138 # There is no need to determine the version number. If it was
139 # This would run even slower!
141 # Test if the package is installed
142 PACKAGE_INSTALLED=`packageInstalled $PACKAGE`
144 # Determine the package version if it is installed.
145 if [ "$PACKAGE_INSTALLED" == "yes" ]; then
146 PACKAGE_VERSION=`getPackageVersion $PACKAGE`
148 # otherwise default to 'none'.
149 else
150 PACKAGE_VERSION="none"
151 MISSING_PACKAGES="$PACKAGE $MISSING_PACKAGES"
154 # If we are supposed to report...
155 if [ "$CHECK" == "yes" ]; then
158 # report the package name and version number.
159 echo "$PACKAGE = $PACKAGE_VERSION"
161 # Otherwise, we'll just echo a dot for the impatient.
162 else
163 echo -n "."
166 done
168 # If we aren't reporting, then the last echo didn't have a newline.
169 if [ ! "$CHECK" == "yes" ]; then
170 echo
173 # If the install command was requested...
174 if [ "$INSTALLCMD" == "yes" ]; then
176 # Give them a nicely indented command to copy, if dependencies are missing.
177 if [ "${#MISSING_PACKAGES}" -gt "0" ]; then
178 cat <<EOF
179 # Copy and paste the following command to install all Koha's dependencies on your system:
180 # Note: this command will run with admin privileges. Make sure your user has sudo rights
183 echo -e "\tsudo apt-get install $MISSING_PACKAGES"
185 # Otherwise tell them all is well.
186 else
187 echo -e "# All dependencies installed!"
188 echo -e "# Please confirm the version numbers are sufficient"
189 echo -e "# By running koha_perl_deps.pl -m -u."
194 exit 0