]> Frank Brehm's Git Trees - scripts/root-bin.git/commitdiff
Initial
authorFrank Brehm <frank@brehm-online.com>
Wed, 26 Oct 2011 20:45:46 +0000 (22:45 +0200)
committerFrank Brehm <frank@brehm-online.com>
Wed, 26 Oct 2011 20:45:46 +0000 (22:45 +0200)
archive-boot-kernel.sh [new file with mode: 0755]
installkernel [changed mode: 0644->0755]
rotate_iptables.sh [changed mode: 0644->0755]
use-desc.sh [changed mode: 0644->0755]

diff --git a/archive-boot-kernel.sh b/archive-boot-kernel.sh
new file mode 100755 (executable)
index 0000000..ed60ac3
--- /dev/null
@@ -0,0 +1,134 @@
+#/bin/bash
+
+if [ -e /etc/profile.env ] ; then
+       . /etc/profile.env
+fi
+
+export PATH="/usr/sbin:/usr/bin:/sbin:/bin:${ROOTPATH}"
+
+BOOT_DIR=/boot
+
+IS_MOUNTED=n
+if [ -d ${BOOT_DIR}/grub -a -f ${BOOT_DIR}/.keep ] ; then
+       IS_MOUNTED=y
+fi
+
+if [ ${IS_MOUNTED} == "n" ] ; then
+       echo "Mounte ${BOOT_DIR} ..."
+       mount ${BOOT_DIR}
+       RES="$?"
+       if [ ${RES} != "0" ] ; then
+               echo "Konnte ${BOOT_DIR} nicht mounten." >&2
+               exit 5
+       fi
+       if [ ! -d ${BOOT_DIR}/grub -a ! -f ${BOOT_DIR}/.keep ] ; then
+               echo "Verzeichnis ${BOOT_DIR}/grub und Datei ${BOOT_DIR}/.keep fehlen, breche ab." >&2
+               exit 6
+       fi
+fi
+
+echo "Wechsel in das verzeichnis ${BOOT_DIR} ..."
+cd ${BOOT_DIR} || exit 7
+
+OLD_DIR=.old
+if [ ! -d ${OLD_DIR} ] ; then
+       echo "Erstelle ${OLD_DIR} ..."
+       mkdir -p ${OLD_DIR}
+fi
+
+USE_LN=y
+if test -h ${OLD_DIR} ; then
+       USE_LN=n
+fi
+
+echo
+echo "Kopiere Kernel-Image (bzImage) ..."
+declare -a IMAGES
+declare -A IMAGE_IN_USE
+i=0
+for f in bzImage* ; do
+       if [ -f "${f}" ] ; then
+               if [ -h "${f}" ] ; then
+                       TARGET=$( readlink "${f}" )
+                       IMAGE_IN_USE[$TARGET]=1
+               else
+                       IMAGES[$i]="${f}"
+                       i=$(( i + 1 ))
+               fi
+       fi
+done
+
+for image in "${IMAGES[@]}" ; do
+       echo " - '${image}'"
+       i=0
+       if [ -f "${OLD_DIR}/${image}" ] ; then
+               while [ -f "${OLD_DIR}/${image}-${i}" ] ; do
+                       i=$(( i + 1 ))
+               done
+               echo "    mv \"${OLD_DIR}/${image}\" \"${OLD_DIR}/${image}-${i}\""
+               mv "${OLD_DIR}/${image}" "${OLD_DIR}/${image}-${i}"
+       fi
+       if [ "${USE_LN}" == "y" ]; then
+               echo "    ln \"${image}\" \"${OLD_DIR}\""
+               ln "${image}" "${OLD_DIR}"
+       else
+               echo "    cp -p \"${image}\" \"${OLD_DIR}\""
+               cp -p "${image}" "${OLD_DIR}"
+       fi
+       if [ "${IMAGE_IN_USE[${image}]}" != "1" ] ; then
+               echo "    rm \"${image}\""
+               rm "${image}"
+       fi
+done
+
+unset IMAGES
+unset IMAGE_IN_USE
+
+echo "Kopiere System-Maps ..."
+declare -a IMAGES
+declare -A IMAGE_IN_USE
+i=0
+for f in System*map* ; do
+       if [ -f "${f}" ] ; then
+               if [ -h "${f}" ] ; then
+                       TARGET=$( readlink "${f}" )
+                       IMAGE_IN_USE[$TARGET]=1
+               else
+                       IMAGES[$i]="${f}"
+                       i=$(( i + 1 ))
+               fi
+       fi
+done
+
+for image in "${IMAGES[@]}" ; do
+       echo " - '${image}'"
+       i=0
+       if [ -f "${OLD_DIR}/${image}" ] ; then
+               while [ -f "${OLD_DIR}/${image}-${i}" ] ; do
+                       i=$(( i + 1 ))
+               done
+               echo "    mv \"${OLD_DIR}/${image}\" \"${OLD_DIR}/${image}-${i}\""
+               mv "${OLD_DIR}/${image}" "${OLD_DIR}/${image}-${i}"
+       fi
+       if [ "${USE_LN}" == "y" ]; then
+               echo "    ln \"${image}\" \"${OLD_DIR}\""
+               ln "${image}" "${OLD_DIR}"
+       else
+               echo "    cp -p \"${image}\" \"${OLD_DIR}\""
+               cp -p "${image}" "${OLD_DIR}"
+       fi
+       if [ "${IMAGE_IN_USE[${image}]}" != "1" ] ; then
+               echo "    rm \"${image}\""
+               rm "${image}"
+       fi
+done
+
+unset IMAGES
+unset IMAGE_IN_USE
+
+if [ "${IS_MOUNTED}" == "n" ] ; then
+       echo "Mounte ${BOOT_DIR} ab ..."
+       umount ${BOOT_DIR}
+fi
+
+# vim: noai : ts=4 fenc=utf-8 filetype=sh
old mode 100644 (file)
new mode 100755 (executable)
index 0dba7c3..61f483e
 #echo $@
 #set -x
 
+ME=installkernel
+VERSION="2010-12-02"
+
+echo -e "\n$ME:\nFrank Brehm's installkernel script, $VERSION"
+[ $DEBUG ] && echo "
+* Arguments:
+kernel version: $1
+kernel image file: $2
+kernel map file: $3
+default install path: $4
+"
+
 #B="/mnt/misc/boot"
-B="/boot"
-V=$1
-K=$2
-M=$3
+BOOT_DIR="/boot"
+KERNEL_VERSION=$1
+KERNEL_IMAGE=$2
+KERNEL_MAPFILE=$3
+DEF_INSTALL_PATH=$4
+
+# check we have a valid kernel target directory
+if [ -n "$DEF_INSTALL_PATH" ] && [ "$DEF_INSTALL_PATH" != "$BOOT_DIR" ] ; then
+    if [ -d "$DEF_INSTALL_PATH" ] ; then
+        BOOT_DIR="$DEF_INSTALL_PATH"
+    else
+        echo -e "\n\n$ME: fatal: missing kernel target directory:" >&2
+        echo -e "\t$DEF_INSTALL_PATH" >&2
+        exit 1
+    fi
+fi
 
-if [ -n "$KBUILD_OUTPUT_PREFIX" -a -d $KBUILD_OUTPUT_PREFIX/$V ] ; then
-  L=$KBUILD_OUTPUT_PREFIX/$V
+# where to find .config, based on kernel series
+if [ -f '.config' ] ; then
+    echo "* 2.6 kernel"
+    DOT_CONFIG=".config"
 else
-  L="/usr/src/linux-$V"
+    echo "* 2.4 kernel"
+    DOT_CONFIG="../../../.config"
 fi
-echo "  INSTALL $B/bzImage-$V"
-
-if [ ! -f $L/$K ] ; then
-  if [ -f $L/arch/i386/boot/$K ] ; then
-    EX="/arch/i386/boot"
-  else
-    exit 1
-  fi
+
+i=0
+TARGET_CONFIG_BOOT=$( printf "%s/config-%s-%02d" "${BOOT_DIR}" "${KERNEL_VERSION}" "${i}" )
+while [ -f "${TARGET_CONFIG_BOOT}" ] ; do
+    i=$(( i + 1 ))
+    TARGET_CONFIG_BOOT=$( printf "%s/config-%s-%02d" "${BOOT_DIR}" "${KERNEL_VERSION}" "${i}" )
+done
+
+echo "  CP      ${DOT_CONFIG} -> ${TARGET_CONFIG_BOOT}"
+cp -p "${DOT_CONFIG}" "${TARGET_CONFIG_BOOT}"
+
+if [ ! -d /etc/kernel-config ] ; then
+    echo "  MKDIR   /etc/kernel-config"
+    mkdir -p /etc/kernel-config
 fi
 
-if [ -f $L/$M ] ; then
-  M=$L/$M
+i=0
+TARGET_CONFIG_ETC=$( printf "%s/config-%s-%02d" "/etc/kernel-config" "${KERNEL_VERSION}" "${i}" )
+while [ -f "${TARGET_CONFIG_ETC}" ] ; do
+    i=$(( i + 1 ))
+    TARGET_CONFIG_ETC=$( printf "%s/config-%s-%02d" "/etc/kernel-config" "${KERNEL_VERSION}" "${i}" )
+done
+
+echo "  CP      ${DOT_CONFIG} -> ${TARGET_CONFIG_ETC}"
+cp -p "${DOT_CONFIG}" "${TARGET_CONFIG_ETC}"
+
+if [ -n "$KBUILD_OUTPUT_PREFIX" -a -d $KBUILD_OUTPUT_PREFIX/$KERNEL_VERSION ] ; then
+    LINUX_SRC_DIR=$KBUILD_OUTPUT_PREFIX/$KERNEL_VERSION
 else
-  test -f $M || exit 1
+    LINUX_SRC_DIR="/usr/src/linux-$KERNEL_VERSION"
+fi
+echo "  INSTALL $BOOT_DIR/bzImage-$KERNEL_VERSION"
+
+if [ ! -f $LINUX_SRC_DIR/$KERNEL_IMAGE ] ; then
+    if [ -f $LINUX_SRC_DIR/arch/i386/boot/$KERNEL_IMAGE ] ; then
+        EX="/arch/i386/boot"
+    else
+        exit 1
+    fi
 fi
-cp $L$EX/$K $B/bzImage-$V
-echo "  INSTALL $B/System.map-$V"
-cp $M $B/System.map-$V
-
-case $V in
-  2.6.*-gentoo*)
-    TARG="-gentoo-2.6"
-    ;;
-  2.6*)
-    TARG="-2.6"
-    ;;
-  *)
-    TARG=""
-    ;;
+
+if [ -f $LINUX_SRC_DIR/$KERNEL_MAPFILE ] ; then
+    KERNEL_MAPFILE=$LINUX_SRC_DIR/$KERNEL_MAPFILE
+else
+    test -f $KERNEL_MAPFILE || exit 1
+fi
+cp $LINUX_SRC_DIR$EX/$KERNEL_IMAGE $BOOT_DIR/bzImage-$KERNEL_VERSION
+echo "  INSTALL $BOOT_DIR/System.map-$KERNEL_VERSION"
+cp $KERNEL_MAPFILE $BOOT_DIR/System.map-$KERNEL_VERSION
+
+case $KERNEL_VERSION in
+    2.6.*-gentoo*)
+        TARG="-gentoo-2.6"
+        ;;
+    2.6*)
+        TARG="-2.6"
+        ;;
+    *)
+        TARG=""
+        ;;
 esac
 
 TARG_LAST=${TARG}-last
 
-if [ -L $B/bzImage$TARG ] ; then
-  IMG_LAST=$(readlink $B/bzImage$TARG)
-  echo "  LN      $B/bzImage$TARG_LAST"
-  ln -sf $IMG_LAST $B/bzImage$TARG_LAST
+if [ -L $BOOT_DIR/bzImage$TARG ] ; then
+    IMG_LAST=$(readlink $BOOT_DIR/bzImage$TARG)
+    echo "  LN      $BOOT_DIR/bzImage$TARG_LAST"
+    ln -sf $IMG_LAST $BOOT_DIR/bzImage$TARG_LAST
 fi
 
-echo "  LN      $B/bzImage$TARG"
-ln -sf bzImage-$V $B/bzImage$TARG
+echo "  LN      $BOOT_DIR/bzImage$TARG"
+ln -sf bzImage-$KERNEL_VERSION $BOOT_DIR/bzImage$TARG
 
-if [ -L $B/System$TARG.map ] ; then
-  IMG_LAST=$(readlink $B/System$TARG.map)
-  echo "  LN      $B/System$TARG_LAST.map"
-  ln -sf $IMG_LAST $B/System$TARG_LAST.map
+if [ -L $BOOT_DIR/System$TARG.map ] ; then
+    IMG_LAST=$(readlink $BOOT_DIR/System$TARG.map)
+    echo "  LN      $BOOT_DIR/System$TARG_LAST.map"
+    ln -sf $IMG_LAST $BOOT_DIR/System$TARG_LAST.map
 fi
 
-echo "  LN      $B/System$TARG.map"
-ln -sf System.map-$V $B/System$TARG.map
+echo "  LN      $BOOT_DIR/System$TARG.map"
+ln -sf System.map-$KERNEL_VERSION $BOOT_DIR/System$TARG.map
 
old mode 100644 (file)
new mode 100755 (executable)
old mode 100644 (file)
new mode 100755 (executable)