#!/bin/sh # Залежності: # * пакети: # * block-mount # * cryptsetup # * перемістіть /sbin/block → /sbin/block.bin # * встановіть decrypt.sh у /sbin/decrypt.sh з правами на виконання # Цей скрипт повинен бути у /upper/sbin/block (UBIFS overlay) # або у /sbin/block, якщо overlay вже активний. export DEBUG= SDIR=${0%/*} BLOCK="${SDIR}/block.bin" LD_LIBRARY_PATH=${LD_LIBRARY_PATH:-.} LD_LIBRARY_PATH="${SDIR}/../usr/lib:${LD_LIBRARY_PATH}" PATH=$PATH:${SDIR}:${SDIR}/../usr/sbin:${SDIR}/../usr/bin block() { ( exec -a ${0} ${BLOCK} "$@" ) } if [ "$PREINIT" != "1" ]; then exec block "$@" fi get_jiffies() { head -n3 /proc/timer_list | tail -n1 | cut -d' ' -f 3 } if [ -z "$BLOCK_LOG" ] && [ -n "$DEBUG" ]; then TIME=$(get_jiffies) export BLOCK_LOG="/tmp/block.$(printf '%016d' ${TIME:-9999999999}).log" exec 2>"$BLOCK_LOG" set -x fi if [ ! -x "$BLOCK" ]; then echo "Error: ${BLOCK} is not an executable" >&2 return 1 fi if [ "$1" = "extroot" ] && [ -e ${SDIR}/../.use_crypt_extroot ]; then for SYSDEVPATH in /sys/class/block/sd*; do [ ! -f "$SYSDEVPATH"/dev ] && continue [ -e "/dev/${SYSDEVPATH##*/}" ] && continue MAJMIN=$(cat "$SYSDEVPATH"/dev | tr ':' ' ') mknod /dev/${SYSDEVPATH##*/} b $MAJMIN done KVER=$(uname -r) insmod ${SDIR}/../lib/modules/${KVER}/af_alg.ko insmod ${SDIR}/../lib/modules/${KVER}/algif_rng.ko insmod ${SDIR}/../lib/modules/${KVER}/algif_hash.ko insmod ${SDIR}/../lib/modules/${KVER}/algif_skcipher.ko find /dev -type b | grep -E "/(sd|mmcblk).*" | while read DEVPATH; do cryptsetup --disable-locks isLuks $DEVPATH || continue export ACTION=add DEVNAME="${DEVPATH##*/}" ALTROOT="${SDIR}/.." "$SDIR"/decrypt.sh || "$SDIR"/decrypt.sh done fi block "$@"