rd

tiny cpt ramdisk image generator meant for system rescue
git clone git://git.ckyln.com/rd
Log | Files | Refs | README | LICENSE

rd (831B)


      1 #!/bin/sh -ef
      2 # shellcheck disable=2174
      3 
      4 out() { printf '%s\n' "$@" >&2 ;}
      5 die() { out "$@"; exit 1 ;}
      6 
      7 # Check parameters and user.
      8 case "$1" in --help|-h|'') out "usage: ${0##*/} [output]"; exit 0; esac
      9 [ "$(id -u)" -eq 0 ] || die "Please run the script as root"
     10 
     11 CPT_ROOT=$(mktemp -d /tmp/rd-XXXXXXX) CPT_PATH=$PWD
     12 export CPT_ROOT CPT_PATH
     13 
     14 # shellcheck disable=1091
     15 . cpt-lib
     16 
     17 pkg_isbuilt ramfs-image || CPT_ROOT='' cpt b ramfs-image
     18 cpt i ramfs-image
     19 
     20 # Install init and hook directory
     21 install -m755 ./init "$CPT_ROOT/init"
     22 mkdir -p "$CPT_ROOT/etc/rd/hooks"
     23 for file in /etc/rd/hooks/*; do
     24     [ -f "$file" ] || continue
     25     install -m 644 "$file" "$CPT_ROOT/etc/rd/hooks/$file"
     26 done
     27 
     28 (cd "$CPT_ROOT"
     29 find . | cpio -oH newc | gzip -c6 || die "Couldn't generate initramfs image") > "$1"
     30 
     31 [ "$debug" = 1 ] || rm -rf "$CPT_ROOT"