From a59c14b051419610776cd7c9a35831c8864739ac Mon Sep 17 00:00:00 2001 From: Antonio Ospite Date: Thu, 14 Apr 2011 23:43:58 +0200 Subject: [PATCH 1/1] Initial import Signed-off-by: Antonio Ospite --- Makefile | 11 +++ README | 5 ++ TODO | 22 ++++++ debian/changelog | 5 ++ debian/compat | 1 + debian/control | 19 +++++ debian/copyright | 16 ++++ debian/dirs | 2 + debian/docs | 2 + debian/install | 3 + debian/kernel/zz-update-kboot | 19 +++++ debian/manpages | 2 + debian/postinst | 41 +++++++++++ debian/postrm | 21 ++++++ debian/rules | 13 ++++ debian/source/format | 1 + debian/update-kboot | 3 + debian/update-kboot.8 | 14 ++++ default.kboot | 21 ++++++ doc/kboot.conf.sample | 4 + kboot-mkconfig | 163 +++++++++++++++++++++++++++++++++++++++++ kboot-mkconfig_lib | 166 ++++++++++++++++++++++++++++++++++++++++++ man/kboot-mkconfig.8 | 22 ++++++ 23 files changed, 576 insertions(+) create mode 100644 Makefile create mode 100644 README create mode 100644 TODO create mode 100644 debian/changelog create mode 100644 debian/compat create mode 100644 debian/control create mode 100644 debian/copyright create mode 100644 debian/dirs create mode 100644 debian/docs create mode 100644 debian/install create mode 100755 debian/kernel/zz-update-kboot create mode 100644 debian/manpages create mode 100644 debian/postinst create mode 100644 debian/postrm create mode 100755 debian/rules create mode 100644 debian/source/format create mode 100755 debian/update-kboot create mode 100644 debian/update-kboot.8 create mode 100644 default.kboot create mode 100644 doc/kboot.conf.sample create mode 100755 kboot-mkconfig create mode 100644 kboot-mkconfig_lib create mode 100644 man/kboot-mkconfig.8 diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..8529cb3 --- /dev/null +++ b/Makefile @@ -0,0 +1,11 @@ +PREFIX ?= /usr +SYSCONFDIR ?= /etc + +all: + +install: + echo ${DESTDIR} + install -m 0755 -d $(DESTDIR)$(PREFIX)/lib/kboot/ + install -m 0644 kboot-mkconfig_lib $(DESTDIR)$(PREFIX)/lib/kboot/kboot-mkconfig_lib + install -m 0755 kboot-mkconfig $(DESTDIR)$(PREFIX)/sbin/kboot-mkconfig + install -m 0644 default.kboot $(DESTDIR)$(SYSCONFDIR)/default/kboot diff --git a/README b/README new file mode 100644 index 0000000..0977b6b --- /dev/null +++ b/README @@ -0,0 +1,5 @@ +Helper tools to automatically generate a kboot.conf from entries in /boot + +The kboot.conf file can be read by the petitboot bootloader which is used for +instance on the Sony Playstation 3 in OtherOS mode in order to list kernels to +boot. diff --git a/TODO b/TODO new file mode 100644 index 0000000..5c8edb1 --- /dev/null +++ b/TODO @@ -0,0 +1,22 @@ +Make the script more portable: + +grub.mkconfig is built from gub-mkconfig.in with something like this: + +grub-mkconfig: util/grub-mkconfig.in $(top_builddir)/config.status + $(top_builddir)/config.status --file=-:$< | sed -e 's,@pkglib_DATA@,$(pkglib_DATA),g' > $@ + chmod a+x grub-mkconfig + +autotools do the substitutions of placeholders used in grub-mkconfig.in + +prefix=@prefix@ +exec_prefix=@exec_prefix@ +sbindir=@sbindir@ +bindir=@bindir@ +libdir=@libdir@ +sysconfdir=@sysconfdir@ +PACKAGE_NAME=@PACKAGE_NAME@ +PACKAGE_VERSION=@PACKAGE_VERSION@ +host_os=@host_os@ +datarootdir=@datarootdir@ +datadir=@datadir@ +pkgdatadir=${datadir}/`echo @PACKAGE_TARNAME@ | sed "${transform}"` diff --git a/debian/changelog b/debian/changelog new file mode 100644 index 0000000..f72abe6 --- /dev/null +++ b/debian/changelog @@ -0,0 +1,5 @@ +kboot-utils (0.1) unstable; urgency=low + + * Initial Release. + + -- Antonio Ospite Thu, 14 Apr 2011 23:34:56 +0200 diff --git a/debian/compat b/debian/compat new file mode 100644 index 0000000..7f8f011 --- /dev/null +++ b/debian/compat @@ -0,0 +1 @@ +7 diff --git a/debian/control b/debian/control new file mode 100644 index 0000000..7e4d1a1 --- /dev/null +++ b/debian/control @@ -0,0 +1,19 @@ +Source: kboot-utils +Section: admin +Priority: extra +Maintainer: Antonio Ospite +Build-Depends: debhelper (>= 7.0.50~) +Standards-Version: 3.9.1 +Homepage: http://git.ao2.it/kboot-utils.git +Vcs-Git: git://git.ao2.it/kboot-utils.git +Vcs-Browser: http://git.ao2.it/kboot-utils.git + +Package: kboot-utils +Architecture: all +Depends: ${misc:Depends} +Description: Helper tools to generate a kboot.conf file + Helper tools to automatically generate a kboot.conf from entries in /boot + . + The kboot.conf file can be read by the petitboot bootloader which is used + for instance on the Sony Playstation 3 in OtherOS mode in order to list + kernels to boot. diff --git a/debian/copyright b/debian/copyright new file mode 100644 index 0000000..b19103c --- /dev/null +++ b/debian/copyright @@ -0,0 +1,16 @@ +Format: http://dep.debian.net/deps/dep5 +Upstream-Name: kboot-utils +Source: http://git.ao2.it/kboot-utils.git + +Files: * +Copyright: 2011 Antonio Ospite +License: GPL-3.0+ + +Files: debian/* +Copyright: 2011 Antonio Ospite +License: GPL-3.0+ + +License: GPL-3.0+ + On Debian systems the full text of the GNU General Public + License can be found in the `/usr/share/common-licenses/GPL' + file. diff --git a/debian/dirs b/debian/dirs new file mode 100644 index 0000000..f6bf4e2 --- /dev/null +++ b/debian/dirs @@ -0,0 +1,2 @@ +/etc/default +/usr/sbin diff --git a/debian/docs b/debian/docs new file mode 100644 index 0000000..c8bc46b --- /dev/null +++ b/debian/docs @@ -0,0 +1,2 @@ +README +doc/kboot.conf.sample diff --git a/debian/install b/debian/install new file mode 100644 index 0000000..47bc794 --- /dev/null +++ b/debian/install @@ -0,0 +1,3 @@ +debian/update-kboot usr/sbin +debian/kernel/zz-update-kboot etc/kernel/postinst.d +debian/kernel/zz-update-kboot etc/kernel/postrm.d diff --git a/debian/kernel/zz-update-kboot b/debian/kernel/zz-update-kboot new file mode 100755 index 0000000..3247acf --- /dev/null +++ b/debian/kernel/zz-update-kboot @@ -0,0 +1,19 @@ +#! /bin/sh +set -e + +which update-kboot >/dev/null 2>&1 || exit 0 + +set -- $DEB_MAINT_PARAMS +mode="${1#\'}" +mode="${mode%\'}" +case $0:$mode in + # Only run on postinst configure and postrm remove, to avoid wasting + # time by calling update-grub multiple times on upgrade and removal. + # Also run if we have no DEB_MAINT_PARAMS, in order to work with old + # kernel packages. + */postinst.d/*:|*/postinst.d/*:configure|*/postrm.d/*:|*/postrm.d/*:remove) + exec update-kboot + ;; +esac + +exit 0 diff --git a/debian/manpages b/debian/manpages new file mode 100644 index 0000000..764213f --- /dev/null +++ b/debian/manpages @@ -0,0 +1,2 @@ +man/kboot-mkconfig.8 +debian/update-kboot.8 diff --git a/debian/postinst b/debian/postinst new file mode 100644 index 0000000..0ccaf86 --- /dev/null +++ b/debian/postinst @@ -0,0 +1,41 @@ +#!/bin/sh +# postinst script for kboot-utils +# +# see: dh_installdeb(1) + +set -e + +# summary of how this script can be called: +# * `configure' +# * `abort-upgrade' +# * `abort-remove' `in-favour' +# +# * `abort-remove' +# * `abort-deconfigure' `in-favour' +# `removing' +# +# for details, see http://www.debian.org/doc/debian-policy/ or +# the debian-policy package + + +case "$1" in + configure) + # Update the kboot.conf on install + update-kboot 3>&- + ;; + + abort-upgrade|abort-remove|abort-deconfigure) + ;; + + *) + echo "postinst called with unknown argument \`$1'" >&2 + exit 1 + ;; +esac + +# dh_installdeb will replace this with shell code automatically +# generated by other debhelper scripts. + +#DEBHELPER# + +exit 0 diff --git a/debian/postrm b/debian/postrm new file mode 100644 index 0000000..2dcd37c --- /dev/null +++ b/debian/postrm @@ -0,0 +1,21 @@ +#!/bin/bash +set -e + +case "$1" in + purge) + rm -f /etc/kboot.conf + ;; + remove|upgrade|failed-upgrade|abort-upgrade|abort-install) + ;; + *) + echo "postrm called with unknown argument \`$1'" >&2 + exit 1 + ;; +esac + +# dh_installdeb will replace this with shell code automatically +# generated by other debhelper scripts. + +#DEBHELPER# + +exit 0 diff --git a/debian/rules b/debian/rules new file mode 100755 index 0000000..b760bee --- /dev/null +++ b/debian/rules @@ -0,0 +1,13 @@ +#!/usr/bin/make -f +# -*- makefile -*- +# Sample debian/rules that uses debhelper. +# This file was originally written by Joey Hess and Craig Small. +# As a special exception, when this file is copied by dh-make into a +# dh-make output file, you may use that output file without restriction. +# This special exception was added by Craig Small in version 0.37 of dh-make. + +# Uncomment this to turn on verbose mode. +#export DH_VERBOSE=1 + +%: + dh $@ diff --git a/debian/source/format b/debian/source/format new file mode 100644 index 0000000..89ae9db --- /dev/null +++ b/debian/source/format @@ -0,0 +1 @@ +3.0 (native) diff --git a/debian/update-kboot b/debian/update-kboot new file mode 100755 index 0000000..0a34ec1 --- /dev/null +++ b/debian/update-kboot @@ -0,0 +1,3 @@ +#!/bin/sh +set -e +exec kboot-mkconfig -o /etc/kboot.conf "$@" diff --git a/debian/update-kboot.8 b/debian/update-kboot.8 new file mode 100644 index 0000000..94a92cb --- /dev/null +++ b/debian/update-kboot.8 @@ -0,0 +1,14 @@ +.\" Copyright 2011 Antonio Ospite +.\" Lincensed under GPL3+ +.TH UPDATE-KBOOT "8" "April 2011" +.SH NAME +update-kboot \- stub for kboot-mkconfig +.SH SYNOPSIS +.B update-kboot +.SH DESCRIPTION +.B update-kboot +is a stub for running +.B kboot-mkconfig -o /etc/kboot.cfg +to generate a kboot config file. +.SH "SEE ALSO" +.BR kboot-mkconfig (8) diff --git a/default.kboot b/default.kboot new file mode 100644 index 0000000..251e6a4 --- /dev/null +++ b/default.kboot @@ -0,0 +1,21 @@ +# If you change this file, run 'update-kboot' afterwards to update +# /etc/kboot.conf. +# For full documentation of the options in this file, see: +# man 8 update-kboot + +KBOOT_TIMEOUT=5 +KBOOT_DISTRIBUTOR=`lsb_release -i -s 2> /dev/null || echo Debian` + +# 480i = ps3fb:mode:1 +# 576i = ps3fb:mode:6 +# 720p = ps3fb:mode:3 +# 1080i = ps3fb:mode:4 +# 1080p = ps3fb:mode:5 + +# This entry is NOT used on RECOVERY kernels +KBOOT_CMDLINE_LINUX_DEFAULT="quiet" +# This entry is used for all kernels +KBOOT_CMDLINE_LINUX="video=ps3fb:mode:6" + +# Uncomment to disable generation of recovery mode menu entries +#KBOOT_DISABLE_RECOVERY="true" diff --git a/doc/kboot.conf.sample b/doc/kboot.conf.sample new file mode 100644 index 0000000..c17965f --- /dev/null +++ b/doc/kboot.conf.sample @@ -0,0 +1,4 @@ +timeout=5 +default=linux + +linux='/boot/vmlinux initrd=/boot/initrd.img root=/dev/ps3da1 video=ps3fb:mode:3 quiet' diff --git a/kboot-mkconfig b/kboot-mkconfig new file mode 100755 index 0000000..276d58c --- /dev/null +++ b/kboot-mkconfig @@ -0,0 +1,163 @@ +#! /bin/sh +set -e + +# Generate kboot.conf by inspecting /boot contents. +# Copyright (C) 2011 Antonio Ospite +# +# Inspired by kboot-mkconfig +# +# This program 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 3 of the License, or +# (at your option) any later version. +# +# This progra, 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 this software. If not, see . + +PACKAGE_NAME=kboot-mkconfig +PACKAGE_VERSION=0.1 + +prefix=/usr +exec_prefix=${prefix} +sbindir=${exec_prefix}/sbin +bindir=${exec_prefix}/bin +libdir=${exec_prefix}/lib +sysconfdir=/etc +host_os=linux-gnu +datarootdir=${prefix}/share +datadir=${datarootdir} +pkgdatadir=${datadir}/kboot +kboot_conf="" + +self=`basename $0` + +# Usage: usage +# Print the usage. +usage () { + cat <. +EOF +} + +argument () { + opt=$1 + shift + + if test $# -eq 0; then + echo "$0: option requires an argument -- '$opt'" 1>&2 + exit 1 + fi + echo $1 +} + +# Check the arguments. +while test $# -gt 0 +do + option=$1 + shift + + case "$option" in + -h | --help) + usage + exit 0 ;; + -v | --version) + echo "$self (${PACKAGE_NAME}) ${PACKAGE_VERSION}" + exit 0 ;; + -o | --output) + kboot_conf=`argument $option "$@"`; shift;; + --output=*) + kboot_conf=`echo "$option" | sed 's/--output=//'` + ;; + -*) + echo "Unrecognized option \`$option'" 1>&2 + usage + exit 1 + ;; + # Explicitly ignore non-option arguments, for compatibility. + esac +done + +. ${libdir}/kboot/kboot-mkconfig_lib + +if [ "x$EUID" = "x" ] ; then + EUID=`id -u` +fi + +if [ "$EUID" != 0 ] ; then + root=f + case "`uname 2>/dev/null`" in + CYGWIN*) + # Cygwin: Assume root if member of admin group + for g in `id -G 2>/dev/null` ; do + case $g in + 0|544) root=t ;; + esac + done ;; + esac + if [ $root != t ] ; then + echo "$self: You must run this as root" >&2 + exit 1 + fi +fi + + +if test -f ${sysconfdir}/default/kboot ; then + . ${sysconfdir}/default/kboot +fi + +# Default values +if [ "x${KBOOT_TIMEOUT}" = "x" ] ; then KBOOT_TIMEOUT=5 ; fi + +if [ "x${KBOOT_DISTRIBUTOR}" = "x" ] ; then + OS=GNU/Linux +else + OS="${KBOOT_DISTRIBUTOR} GNU/Linux" +fi + +# These are optional, user-defined variables. +export KBOOT_TIMEOUT \ + KBOOT_DISTRIBUTOR \ + KBOOT_CMDLINE_LINUX \ + KBOOT_CMDLINE_LINUX_DEFAULT \ + KBOOT_DISABLE_RECOVERY + +if test "x${kboot_conf}" != "x"; then + rm -f ${kboot_conf}.new + exec > ${kboot_conf}.new +fi +echo "Generating kboot.conf ..." >&2 + +cat << EOF +# +# DO NOT EDIT THIS FILE +# +# It is automatically generated by $self +# with settings from ${sysconfdir}/default/kboot +# + +timeout=${KBOOT_TIMEOUT} + +EOF + +echo "### BEGIN list of kernels ###" +list_kernels +echo "### END list of kernels ###" + +if test "x${kboot_conf}" != "x" ; then + # none of the children aborted with error, install the new kboot.cfg + mv -f ${kboot_conf}.new ${kboot_conf} +fi + +echo "done" >&2 diff --git a/kboot-mkconfig_lib b/kboot-mkconfig_lib new file mode 100644 index 0000000..3507696 --- /dev/null +++ b/kboot-mkconfig_lib @@ -0,0 +1,166 @@ +# kboot-mkconfig helper script. +# Copyright (C) 2011 Antonio Ospite +# +# Inspired by the 10_linux script from kboot +# +# This program 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 3 of the License, or +# (at your option) any later version. +# +# This progra, 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 this software. If not, see . + +prefix=/usr +exec_prefix=${prefix} +bindir=${exec_prefix}/bin +libdir=${exec_prefix}/lib + +LINUX_ROOT_DEVICE="$(mount | grep ' / ' | cut -d ' ' -f 1)" + +if $(which gettext >/dev/null 2>/dev/null) ; then + gettext="gettext" +else + gettext="echo" +fi + +# One layer of quotation is eaten by "", the second by sed, and the third by +# printf; so this turns ' into \'. Note that you must use the output of +# this function in a printf format string. +gettext_quoted () { + $gettext "$@" | sed "s/'/'\\\\\\\\''/g" +} + +# Run the first argument through gettext_quoted, and then pass that and all +# remaining arguments to printf. This is a useful abbreviation and tends to +# be easier to type. +gettext_printf () { + local format="$1" + shift + printf "$(gettext_quoted "$format")" "$@" +} + +kboot_file_is_not_garbage () +{ + if test -f "$1" ; then + case "$1" in + *.dpkg-*) return 1 ;; # debian dpkg + README*) return 1 ;; # documentation + esac + else + return 1 + fi + return 0 +} + +version_test_gt () +{ + local sedexp="s/[^-]*-//;s/[._-]\(pre\|rc\|test\|git\|old\|trunk\)/~\1/g" + local a=`echo $1 | sed -e "$sedexp"` + local b=`echo $2 | sed -e "$sedexp"` + local cmp=gt + if [ "x$b" = "x" ] ; then + return 0 + fi + case $a:$b in + *.old:*.old) ;; + *.old:*) a=`echo -n $a | sed -e s/\.old$//` ; cmp=gt ;; + *:*.old) b=`echo -n $b | sed -e s/\.old$//` ; cmp=ge ;; + esac + dpkg --compare-versions "$a" $cmp "$b" + return $? +} + +version_find_latest () +{ + local a="" + for i in $@ ; do + if version_test_gt "$i" "$a" ; then + a="$i" + fi + done + echo "$a" +} + +linux_entry () +{ + os="$1" + version="$2" + recovery="$3" + args="$4" + if ${recovery} ; then + title="$(gettext_quoted "%s, with Linux %s (recovery mode)")" + else + title="$(gettext_quoted "%s, with Linux %s")" + fi + label="$(printf "${title}" "${os}" "${version}")" + echo -n "'${label}'='${dirname}/${basename} " + if test -n "${initrd}" ; then + echo -n "initrd=${dirname}/${initrd}" + fi + echo " root=${linux_root_device_thisversion} ro ${args}'" +} + +list_kernels () +{ + list=`for i in /boot/vmlinuz-* /boot/vmlinux-* /vmlinuz-* /vmlinux-* ; do + if kboot_file_is_not_garbage "$i" ; then echo -n "$i " ; fi + done` + prepare_boot_cache= + + while [ "x$list" != "x" ] ; do + linux=`version_find_latest $list` + echo "Found linux image: $linux" >&2 + basename=`basename $linux` + dirname=`dirname $linux` + + # XXX: this relies on a binary shipped by GRUB, we just use ${dirname} for + # now, check the ${dirname} entries if we need something like that later + #rel_dirname=`make_system_path_relative_to_its_root $dirname` + + version=`echo $basename | sed -e "s,^[^0-9]*-,,g"` + alt_version=`echo $version | sed -e "s,\.old$,,g"` + linux_root_device_thisversion="${LINUX_ROOT_DEVICE}" + + initrd= + for i in "initrd.img-${version}" "initrd-${version}.img" \ + "initrd-${version}" "initramfs-${version}.img" \ + "initrd.img-${alt_version}" "initrd-${alt_version}.img" \ + "initrd-${alt_version}" "initramfs-${alt_version}.img"; do + if test -e "${dirname}/${i}" ; then + initrd="$i" + break + fi + done + + initramfs= + for i in "config-${version}" "config-${alt_version}"; do + if test -e "${dirname}/${i}" ; then + initramfs=`grep CONFIG_INITRAMFS_SOURCE= "${dirname}/${i}" | cut -f2 -d= | tr -d \"` + break + fi + done + + if test -n "${initrd}" ; then + echo "Found initrd image: ${dirname}/${initrd}" >&2 + elif test -z "${initramfs}" ; then + # "UUID=" magic is parsed by initrd or initramfs. Since there's + # no initrd or builtin initramfs, it can't work here. + linux_root_device_thisversion=${KBOOT_DEVICE} + fi + + linux_entry "${OS}" "${version}" false \ + "${KBOOT_CMDLINE_LINUX} ${KBOOT_CMDLINE_LINUX_DEFAULT}" + if [ "x${KBOOT_DISABLE_RECOVERY}" != "xtrue" ]; then + linux_entry "${OS}" "${version}" true \ + "single ${KBOOT_CMDLINE_LINUX}" + fi + + list=`echo $list | tr ' ' '\n' | grep -vx $linux | tr '\n' ' '` + done +} diff --git a/man/kboot-mkconfig.8 b/man/kboot-mkconfig.8 new file mode 100644 index 0000000..bd0cbe8 --- /dev/null +++ b/man/kboot-mkconfig.8 @@ -0,0 +1,22 @@ +.\" Copyright 2011 Antonio Ospite +.\" Lincensed under GPL3+ +.\" Copyed from the grub-mkconfig man page +.TH KBOOT-MKCONFIG "8" "April 2011" "kboot-mkconfig 0.1" "System Administration Utilities" +.SH NAME +kboot-mkconfig \- generate a kboot configuration file +.SH SYNOPSIS +.B kboot-mkconfig +[\fIOPTION\fR] +.SH DESCRIPTION +Generate a kboot config file +.TP +\fB\-o\fR, \fB\-\-output\fR=\fIFILE\fR +output generated config to FILE [default=stdout] +.TP +\fB\-h\fR, \fB\-\-help\fR +print this message and exit +.TP +\fB\-v\fR, \fB\-\-version\fR +print the version information and exit +.SH "REPORTING BUGS" +Report bugs to . -- 2.1.4