From: Andrew Sichevoi Date: Tue, 5 Jun 2012 07:25:22 +0000 (+0400) Subject: Added initrd helper script X-Git-Url: http://git.thekondor.net/?a=commitdiff_plain;h=4aed9dbf6f4418a078650e509617d8ba3d72f69f;p=scripts.git Added initrd helper script --- diff --git a/initrd-tool/initrd-extract-here b/initrd-tool/initrd-extract-here new file mode 100755 index 0000000..ba43af7 --- /dev/null +++ b/initrd-tool/initrd-extract-here @@ -0,0 +1,39 @@ +#!/bin/sh + +### +### This script is distributed in the terms of GNU GPL v3.0+ +### (c) Andrew Sichevoi, http://thekondor.net +### +### Name: initrd-extract-here +### Description: Helper script to extract initramfs image contents to the current directory +### Notes: By default initramfs for current kernel version is extracted. +### +### Arguments: +### name : %kernel_version% +### type : string +### required: optional +### default : $(uname -r) +### + + +### TODO: move C&P code to a common place + +PREFIX=/boot/initrd.img- +CURRENT_VERSION=$(uname -r) +VERSION=${CURRENT_VERSION} + +if [ x"current" = x"$1" -o -z "$1" ]; then + VERSION=${CURRENT_VERSION} +else + VERSION=$1 +fi + +INITRD_FILENAME=${PREFIX}${VERSION} +if [ ! -e ${INITRD_FILENAME} ]; then + echo "Error: '${INITRD_FILENAME}' is not existent" + exit 1 +fi + +echo "Initrd to extract: '${INITRD_FILENAME}'" + +cat ${INITRD_FILENAME} | gzip -d - | cpio -i diff --git a/initrd-tool/initrd-pack-here b/initrd-tool/initrd-pack-here new file mode 100755 index 0000000..b648d8f --- /dev/null +++ b/initrd-tool/initrd-pack-here @@ -0,0 +1,51 @@ +#!/bin/sh + +### +### This script is distributed in the terms of GNU GPL v3.0+ +### (c) Andrew Sichevoi, http://thekondor.net +### +### Name: initrd-pack-here +### Description: Helper script to create initramfs image from current the directory +### Notes: By default an initramfs image is created in the parent directory +### +### Arguments +### name : replace +### desc : specifies that initramfs image must be replaced in /boot directory +### The next following argument must specify kernel version. +### type : keyword +### required: optional +### default : - +### +### name : current +### desc : used with a combination of 'replace' only. Synonym for $(uname -r) +### type : keyword +### required: required +### default : - +### + +if [ ! -e init -o ! -d scripts ]; then + echo "Error: current directory is not contents of initrd" + exit 1 +fi + +PREFIX=/boot/initrd.img- +INITRD_FILENAME= +if [ x"replace" = x"$1" ]; then + if [ x"current" = x"$2" ]; then + VERSION=$(uname -r) + INITRD_FILENAME=${PREFIX}${VERSION} + else + INITRD_FILENAME=$2 + fi +else + INITRD_FILENAME=../initrd.img-$(date +"%R-%F") +fi + +if [ -z "${INITRD_FILENAME}" ]; then + echo "Error: Filename of initrd image is not specified" + exit 1 +fi + +echo "Packing initrd to '${INITRD_FILENAME}'" + +find ./ | cpio -H newc --no-absolute-filenames -o | gzip - > ${INITRD_FILENAME} diff --git a/initrd-tool/initrd-tool b/initrd-tool/initrd-tool new file mode 100755 index 0000000..2e55dba --- /dev/null +++ b/initrd-tool/initrd-tool @@ -0,0 +1,45 @@ +#!/bin/sh + +### +### This script is distributed in the terms of GNU GPL v3.0+ +### (c) Andrew Sichevoi, http://thekondor.net +### +### Name: initrd-tool +### Description: wrapper over initrd image packing and extracting scripts +### Notes: depends on ``initrd-extract-here'', ``initrd-pack-here'' +### +### Arguments: +### +### + +show_usage() +{ + echo 'Usage:' + echo ' [|]' + echo ' []' +} + +INITRD_EXTRACT_TOOL="initrd-extract-here" +INITRD_PACK_TOOL="initrd-pack-here" + +command=$1 +tool= +case "${command}" in + extract-here | x-here) + tool=${INITRD_EXTRACT_TOOL} + break + ;; + pack-here | p-here) + tool=${INITRD_PACK_TOOL} + break + ;; +esac + +if [ ! -z "${tool}" ]; then + [ ! 0 -eq $# ] && shift + ${tool} $@ + exit $? +fi + +show_usage +exit 1