# Functions used from inside of initrd. # Wait for specific /dev files to appear but only one # time regardless how often this function is called # in one initrd run. Needs writable /tmp. wait_for_files() { local i=0 timeout=30 all_found not_found wff_dir fpath file while getopts t: opt "$@"; do case "$opt" in t) timeout="${OPTARG}" break ;; *) echo "$0: wait_for_files: unknown option" >&2 return 1 ;; esac done shift $((OPTIND - 1)) wff_dir="/tmp/wait_for_files" [ ! -d "$wff_dir" ] && mkdir "$wff_dir" echo "Waiting for files ($@) with ${timeout}s timeout" i=0 timeout=$((timeout * 4)) while [ $i -lt $timeout ]; do all_found=1 for file in $@; do fpath="$wff_dir/${file}" [ -e "$fpath" -o -e "$file" ] && continue all_found=0 done if [ $all_found -eq 1 ]; then return 0 fi usleep 250000 i=$((i + 1 )) done not_found="" # mark files that we have waited for for file in $@; do fpath="$wff_dir/${file}" [ ! -e "$fpath" ] && mkdir -p "$fpath" [ ! -e "$file" ] && not_found="$not_found $file" done echo "Waiting for files ($@) finished. Missing files: $not_found" return 0 }