View | Details | Raw Unified | Return to bug 8840
Collapse All | Expand All

(-)a/install_misc/ubuntu-packages.sh (+196 lines)
Line 0 Link Here
1
#!/bin/bash
2
3
# Copyright 2012 Universidad Nacional de Cordoba
4
# Written by Tomas Cohen Arazi
5
#            Mark Tompsett
6
#
7
# This file is part of Koha.
8
#
9
# Koha is free software; you can redistribute it and/or modify it under the
10
# terms of the GNU General Public License as published by the Free Software
11
# Foundation; either version 2 of the License, or (at your option) any later
12
# version.
13
#
14
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
15
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
16
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
17
#
18
# You should have received a copy of the GNU General Public License along
19
# with Koha; if not, write to the Free Software Foundation, Inc.,
20
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21
22
# Output simple help
23
usage() {
24
    local scriptname=$(basename $0)
25
    cat <<EOF
26
$scriptname
27
28
Query for missing dependencies. Print the install command for them if specified.
29
30
Usage:
31
$scriptname -r
32
$scriptname -ic
33
$scriptname -h
34
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
39
}
40
41
# Check if the package is installed
42
packageInstalled() {
43
    local package=$1
44
    if dpkg -s $package &> /dev/null ; then
45
        return 0
46
    else
47
        return 1
48
    fi
49
}
50
51
# Get the installed package version
52
getPackageVersion() {
53
    local package=$1
54
    dpkg-query -W $package | cut -f2
55
}
56
57
# A parameter is required.
58
if [ "$#" -eq "0" ]; then
59
    usage
60
    exit 1
61
fi
62
63
# Initialize variables
64
CHECK=no
65
INSTALLCMD=no
66
HELP=no
67
68
# Loop over parameters
69
while (( "$#" )); do
70
    case $1 in
71
        -r | --report )
72
            CHECK=yes
73
            ;;
74
        -ic | --install-command )
75
            INSTALLCMD=yes
76
            ;;
77
        -h | --help)
78
            HELP=yes
79
            ;;
80
        * )
81
            usage
82
            exit 1
83
    esac
84
    shift
85
done
86
87
if [ "$HELP" = "yes" ]; then
88
    usage
89
    exit 0
90
fi
91
92
# Determine what directory this script is in, the packages files
93
# should be in the same path.
94
DIR=`dirname $0`
95
96
# Determine the Ubuntu release
97
UBUNTU_RELEASE=`lsb_release -r | cut -f2 -d'	'`
98
UBUNTU_PACKAGES_FILE=$DIR/ubuntu.$UBUNTU_RELEASE.packages
99
100
# Check for the release-specific packages file. Default to the general one
101
# but warn the user about LTS releases recommended, if they are attempting
102
# to do an install command option.
103
if [ ! -e $UBUNTU_PACKAGES_FILE ]; then
104
    UBUNTU_PACKAGES_FILE=$DIR/ubuntu.packages
105
    if [ "$INSTALLCMD" == "yes" ]; then
106
        echo "# There's no packages file for your distro/release"
107
        echo "# WARNING! We strongly recommend an LTS release."
108
    fi
109
fi
110
111
# We where asked to print the packages list and current versions (if any)
112
UBUNTU_PACKAGES=`awk '{print $1}' $UBUNTU_PACKAGES_FILE | grep -v '^\s*#' | grep -v '^\s*$'`
113
114
# Only output this on an install command option in order to maintain
115
# output equivalence to the former script, in the case of reporting
116
# only.
117
if [ "$INSTALLCMD" == "yes" ]; then
118
119
    # Tell them which file being used to determine the output.
120
    echo "# Using the $UBUNTU_PACKAGES_FILE file as source"
121
122
    # Comment for skiping the dots if needed ....
123
    if [ "$CHECK" == "no" ]; then
124
        echo -n "#"
125
    fi
126
fi
127
128
# Initialize variable to accumulate missing packages in.
129
MISSING_PACKAGES=""
130
131
# Loop used to accumulate the missing packages and display package information if requested to report.
132
for PACKAGE in $UBUNTU_PACKAGES; do
133
134
    # If an install command option is running, but not a report option,
135
    # There is no need to determine the version number. If it was
136
    # This would run even slower!
137
138
    # Test if the package is installed
139
    if packageInstalled $PACKAGE ; then
140
        PACKAGE_INSTALLED=1
141
142
    # It must not be installed, accumulate for output
143
    else
144
        PACKAGE_INSTALLED=0
145
        MISSING_PACKAGES="$MISSING_PACKAGES $PACKAGE"
146
    fi
147
148
    # If we are supposed to report...
149
    if [ "$CHECK" == "yes" ]; then
150
151
        # Determine the package version if it is installed.
152
        if [ $PACKAGE_INSTALLED ]; then
153
            PACKAGE_VERSION=`getPackageVersion $PACKAGE`
154
155
        # otherwise default to 'none'.
156
        else
157
            PACKAGE_VERSION="none"
158
        fi
159
160
        # report the package name and version number.
161
        echo -e "$PACKAGE = $PACKAGE_VERSION"
162
163
    # Otherwise, we'll just echo a dor for the impatient.
164
    else
165
        echo -n "."
166
    fi
167
168
done
169
170
# If we aren't reporting, then the last echo didn't have a newline.
171
if [ "$CHECK" != "yes" ]; then
172
    echo 
173
fi
174
175
# If the install command was requested...
176
if [ "$INSTALLCMD" == "yes" ]; then
177
178
    # Give them a nicely indented command to copy, if dependencies are missing.
179
    if [ "${#MISSING_PACKAGES}" -gt "0" ]; then
180
        cat <<EOF
181
# Copy and paste the following command to install all Koha's dependencies on your system:
182
# Note: this command will run with admin privileges. Make sure your user has sudo rights
183
EOF
184
185
        echo -e "\tsudo apt-get install $MISSING_PACKAGES"
186
187
    # Otherwise tell them all is well.
188
    else
189
        echo -e "# All dependencies installed!"
190
        echo -e "# Please confirm the version numbers are sufficient"
191
        echo -e "# By running koha_perl_deps.pl -m -u."
192
    fi
193
194
fi
195
196
exit 0
(-)a/install_misc/ubuntu-pkg-check.sh (-28 lines)
Lines 1-27 Link Here
1
#!/bin/sh
2
3
# determine what directory this script is in, because the packages files
4
# should be there too.
5
DIR=`dirname $0`
6
7
#determine which vbersion of ubuntu
8
VERSION=`lsb_release -r | cut -f2 -d'	'`
9
UBUNTU_PACKAGES=$DIR/ubuntu.$VERSION.packages
10
11
# sanity checks
12
if [ ! -e $UBUNTU_PACKAGES ]; then
13
   echo "WARNING! We strongly recommend an LTS release."
14
   UBUNTU_PACKAGES=$DIR/ubuntu.packages
15
fi
16
echo "Using the $UBUNTU_PACKAGES file."
17
18
# main
19
UBUNTU_PACKAGES_LIST=`awk '{print $1}' $UBUNTU_PACKAGES | grep -v '^\s*#' | grep -v '^\s*$'`
20
for F in $UBUNTU_PACKAGES_LIST; do
21
   UBUNTU_PKG_POLICY=`apt-cache policy $F 2> /dev/null | grep "Installed:"`
22
   if [ "${#UBUNTU_PKG_POLICY}" -eq "0" ]; then
23
      UBUNTU_PKG_POLICY="Installed: \(none\)\*"
24
   fi
25
   UBUNTU_PKG_VERSION=`echo $UBUNTU_PKG_POLICY | awk '{print $2}'`
26
   echo "$F = $UBUNTU_PKG_VERSION"
27
done
28
- 

Return to bug 8840