[linux] Met bash parameter functie aanroepen

Frans van Berckel fberckel op xs4all.nl
Di Dec 19 12:06:31 CET 2017


On Tue, 2017-12-19 at 11:30 +0100, Frans van Berckel wrote:
> 
> Hoe vang ik in bash het beste een dpkg -i package.deb error af?
> 
> Zie script versie, van later vandaag.

#!/bin/bash
#
# @brief	Building oldstable Debian kernel packages,
#		which is no longer available in unstable
# @version	ver.1.0.4
# @date		di 19 dec 2017 11:59:13 CET
# @company	Open Software Store, www.osstore.nl
# @author  	Frans van Berckel, info op osstore.nl
#

major='3.16'
minor='3.16.51-3'
arch=$(uname -i)
workdir='/usr/src'
url='https://deb.debian.org/debian/pool/main/l/linux'
package='linux-source-${major}_${minor}_all.deb'
tarball='linux-source-${major}.tar.bz2'
linuxdir='${workdir}/linux-source-${major}'
config='${linuxdir}/linux-config-
${major}/config.${arch}_none_${arch}.xz'

install_package () { 
for package in wget kernel-package wget tar
do
  echo "Installing package '${package}'. Please wait..."
  if ! apt-get --yes --no-install-recommends install ${package}
  then
    echo "Error: Failed to install ${package}!" >&2
    exit 1;
  fi
done
}

if [ "$(id -u)" -ne 0 ]; then
        echo 'This script must be run as root' >&2
        exit 1;
fi

for apps in dpkg apt-get
do
  if ! [ -x "$(command -v ${apps})" ]; then
    echo -e "Error: Are you\nrunning a Debian based distribution?">&2
    exit 1;
  fi
done

# Check for all necessary build dependencies
for apps in make-kpkg wget tar
do
  if ! [ -x "$(command -v ${apps})" ]; then
    apt-get update
    install_package
  fi
done

# Download the oldstable kernel package and install
if [ ! -d "${workdir}" ]; then
  if ! mkdir ${workdir} 2>/dev/null; then
    print_error
    exit 1;
  fi
fi
cd ${workdir}
if [ ! -f "${package}" ]; then
  wget -c ${url}/${package}
  if [[ $? -ne 0 ]]; then
    echo "Error: Downloading ${package} failed!"
    exit 1;
  fi
  dpkg -i ${package}
fi
if [ ! -d "${linuxdir}" ]; then
  if [ -f "${tarball}" ]; then
    tar xjvf ${tarball}
    if [[ $? -ne 0 ]]; then
      echo "Error: Extracting ${tarball} failed!"
      exit 1;
    fi
  fi
fi
# Generate config with default from the ARCH supplied defconfig file
cd ${linuxdir}
if [ ! -f "./.config" ]; then
  if [ -f "${config}" ]; then
    xzcat ${config} >> ./.config
    if [[ $? -ne 0 ]]; then
      echo "Error: Extracting ${config} failed!"
      exit 1;
    fi
  else
    echo "Error: What's goning on, with the kernel config?"
    exit 1;
  fi
  make ARCH=${arch} defconfig
fi

# Building the kernel packages
make-kpkg clean
make-kpkg --rootcmd fakeroot --jobs $(`nproc`) --initrd kernel_image
kernel_headers

cd ${workdir}
ls -l *.deb

#Installing the new kernel
#Check first file names before running dpkg
#dpkg -i linux-image-${major}_${minor}_${arch}.deb
#dpkg -i linux-headers-${major}_${minor}_${arch}.deb


Meer informatie over de Linux maillijst