From 39b92d751b4592057c1c2e47c22293e8c810cc08 Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Thu, 27 Sep 2012 15:03:06 -0300 Subject: [PATCH] Bug 8840 - ubuntu-pkg-check.sh script doesn't work on non englush setups MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Using dpkg -s to query for installed packages works in languages other than english. Added some switches (and checks for them) too. Sponsored-by: Universidad Nacional de Córdoba --- install_misc/ubuntu-packages.sh | 140 ++++++++++++++++++++++++++++++++++++++ install_misc/ubuntu-pkg-check.sh | 27 -------- 2 files changed, 140 insertions(+), 27 deletions(-) create mode 100755 install_misc/ubuntu-packages.sh delete mode 100755 install_misc/ubuntu-pkg-check.sh diff --git a/install_misc/ubuntu-packages.sh b/install_misc/ubuntu-packages.sh new file mode 100755 index 0000000..e34164c --- /dev/null +++ b/install_misc/ubuntu-packages.sh @@ -0,0 +1,140 @@ +#!/bin/bash + +# Copyright 2012 Universidad Nacional de Córdoba +# +# This file is part of Koha. +# +# Koha is free software; you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation; either version 2 of the License, or (at your option) any later +# version. +# +# Koha is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with Koha; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +usage() { + local scriptname=$(basename $0) + cat <1&> /dev/null` +} + + +# Get the installed package version +getPackageVersion() { + local package=$1 + dpkg-query -W $package | cut -f2 +} + +# Loop over parameters +while [ $1 ]; do + case $1 in + -c | --check ) + shift + CHECK=yes + ;; + -i | --install ) + shift + INSTALL=yes + ;; + -h | --help) + HELP=yes + ;; + * ) + usage + exit 1 + esac + shift +done + +if [ "$HELP" = "yes" ]; then + usage + exit 0 +fi + +# Determine what directory this script is in, the packages files +# should be in the same path. + +DIR=`dirname $0` + +# Determine the Ubuntu release +UBUNTU_RELEASE=`lsb_release -r | cut -f2 -d' '` +UBUNTU_PACKAGES=$DIR/ubuntu.$UBUNTU_RELEASE.packages + +# Check for the release-specific packages file. Default to the general one +# but warn the user about LTS releases recommended +if [ ! -e $UBUNTU_PACKAGES ]; then + UBUNTU_PACKAGES=$DIR/ubuntu.packages + + echo "There's no packages file for your distro/release" + echo "WARNING! We strongly recommend an LTS release." +fi + +echo "Using the $UBUNTU_PACKAGES file." + + +if [ "$CHECK" = "yes" ]; then + + # We where asked to print the packages list and current versions (if any) + + UBUNTU_PACKAGES_LIST=`awk '{print $1}' $UBUNTU_PACKAGES | grep -v '^\s*#' | grep -v '^\s*$'` + + for PACKAGE in $UBUNTU_PACKAGES_LIST + do + UBUNTU_PKG_POLICY=`packageInstalled $PACKAGE` + + if [ `packageInstalled $PACKAGE` ]; then + UBUNTU_PKG_POLICY="Installed: (none)" + else + PACKAGE_VERSION=`getPackageVersion $PACKAGE` + UBUNTU_PKG_POLICY="Installed: ($PACKAGE_VERSION)" + fi + + UBUNTU_PKG_VERSION=`echo $UBUNTU_PKG_POLICY | awk '{print $2}'` + echo "$PACKAGE = $UBUNTU_PKG_VERSION" + done +fi + +if [ "$INSTALL" = "yes" ]; then + + # We where asked to issue the apt-get command for the packages. + + UBUNTU_PACKAGES_LIST=`awk '{print $1}' $UBUNTU_PACKAGES | grep -v '^\s*#' | grep -v '^\s*$'` + + echo "Packages to be installed: " + echo "$UBUNTU_PACKAGES_LIST" + echo -n "Proceed (You'll be prompted to type your password)? (Y/n): " + + read answer + if [ $answer ] && [ $answer != "Y" ] && [ $answer != "y" ]; then + echo "Aborting" + exit 1 + else + sudo apt-get install $UBUNTU_PACKAGES_LIST + fi + +fi + +exit 0 diff --git a/install_misc/ubuntu-pkg-check.sh b/install_misc/ubuntu-pkg-check.sh deleted file mode 100755 index 75bec3f..0000000 --- a/install_misc/ubuntu-pkg-check.sh +++ /dev/null @@ -1,27 +0,0 @@ -#!/bin/sh - -# determine what directory this script is in, because the packages files -# should be there too. -DIR=`dirname $0` - -#determine which vbersion of ubuntu -VERSION=`lsb_release -r | cut -f2 -d' '` -UBUNTU_PACKAGES=$DIR/ubuntu.$VERSION.packages - -# sanity checks -if [ ! -e $UBUNTU_PACKAGES ]; then - echo "WARNING! We strongly recommend an LTS release." - UBUNTU_PACKAGES=$DIR/ubuntu.packages -fi -echo "Using the $UBUNTU_PACKAGES file." - -# main -UBUNTU_PACKAGES_LIST=`awk '{print $1}' $UBUNTU_PACKAGES | grep -v '^\s*#' | grep -v '^\s*$'` -for F in $UBUNTU_PACKAGES_LIST; do - UBUNTU_PKG_POLICY=`apt-cache policy $F 2> /dev/null | grep "Installed:"` - if [ "${#UBUNTU_PKG_POLICY}" -eq "0" ]; then - UBUNTU_PKG_POLICY="Installed: \(none\)\*" - fi - UBUNTU_PKG_VERSION=`echo $UBUNTU_PKG_POLICY | awk '{print $2}'` - echo "$F = $UBUNTU_PKG_VERSION" -done -- 1.7.9.5