mirror of
https://salsa.debian.org/kernel-team/initramfs-tools.git
synced 2026-01-26 15:39:08 +00:00
Add hookscripts
This commit is contained in:
parent
8cfdec86dd
commit
ac222142f8
7
debian/changelog
vendored
7
debian/changelog
vendored
@ -13,7 +13,12 @@ initramfs-tools (0.7) breezy; urgency=low
|
||||
|
||||
* Add hookscript directories.
|
||||
|
||||
-- Jeff Bailey <jbailey@localhost> Thu, 9 Jun 2005 15:16:15 +0000
|
||||
* Call hookscripts
|
||||
|
||||
Thanks to David Weinhall <tao@acc.umu.se> for the dependancy-based
|
||||
hookscripts.
|
||||
|
||||
-- Jeff Bailey <jbailey@ubuntu.com> Thu, 9 Jun 2005 17:08:01 +0000
|
||||
|
||||
initramfs-tools (0.6) breezy; urgency=low
|
||||
|
||||
|
||||
1
debian/initramfs-tools.examples
vendored
1
debian/initramfs-tools.examples
vendored
@ -1 +1,2 @@
|
||||
conf/modules
|
||||
docs/example_script
|
||||
|
||||
21
docs/example_script
Normal file
21
docs/example_script
Normal file
@ -0,0 +1,21 @@
|
||||
#!/bin/sh
|
||||
|
||||
# List the soft prerequisites here. So if there's something you know
|
||||
# should be run first iff it exists.
|
||||
PREREQ=""
|
||||
|
||||
prereqs()
|
||||
{
|
||||
echo "$PREREQ"
|
||||
}
|
||||
|
||||
case $1 in
|
||||
# get pre-requisites
|
||||
prereqs)
|
||||
prereqs
|
||||
exit 0
|
||||
;;
|
||||
esac
|
||||
|
||||
# Do the work here.
|
||||
echo "Got here!"
|
||||
4
init
4
init
@ -40,6 +40,8 @@ for x in $(cat /proc/cmdline); do
|
||||
esac
|
||||
done
|
||||
|
||||
run_scripts /scripts/init_top
|
||||
|
||||
. /scripts/${BOOT}
|
||||
|
||||
# Load the modules
|
||||
@ -57,6 +59,8 @@ fi
|
||||
|
||||
mountroot
|
||||
|
||||
run_scripts /scripts/init_bottom
|
||||
|
||||
umount /sys
|
||||
umount /proc
|
||||
|
||||
|
||||
@ -7,3 +7,124 @@ panic()
|
||||
FS1='(initramfs) ' exec /bin/sh
|
||||
fi
|
||||
}
|
||||
|
||||
# this function finds scripts with empty depends and adds them
|
||||
# to the ordered list
|
||||
dep_reduce()
|
||||
{
|
||||
i=0
|
||||
j=0
|
||||
unset neworder
|
||||
|
||||
for entry in "${array[@]}"; do
|
||||
set - ${entry}
|
||||
|
||||
if [ "$#" -eq "0" ]; then
|
||||
continue
|
||||
elif [ "$#" -eq "1" ]; then
|
||||
if [ $end -eq 0 ] ||
|
||||
[ x"${order[$((end-1))]}" != x"$1" ]; then
|
||||
order[$((end))]=$1
|
||||
end=$((end+1))
|
||||
neworder[$((j))]=$1
|
||||
j=$((j+1))
|
||||
fi
|
||||
|
||||
array[$((i))]=
|
||||
fi
|
||||
|
||||
i=$((i+1))
|
||||
done
|
||||
}
|
||||
|
||||
dep_remove()
|
||||
{
|
||||
i=0
|
||||
|
||||
# for each row in the array
|
||||
for entry in "${array[@]}"; do
|
||||
unset newentry
|
||||
|
||||
set - ${entry}
|
||||
|
||||
# for each dependency of the script
|
||||
for dep in "$@"; do
|
||||
new=1
|
||||
|
||||
# for each new dependency
|
||||
for tmp in "${order[@]}"; do
|
||||
if [ x"$dep" = x"$tmp" ]; then
|
||||
new=0
|
||||
fi
|
||||
done
|
||||
|
||||
if [ x"$new" = x"1" ]; then
|
||||
newentry="$newentry $dep"
|
||||
fi
|
||||
done
|
||||
|
||||
array[$((i))]="$newentry"
|
||||
i=$((i+1))
|
||||
done
|
||||
}
|
||||
|
||||
run_scripts()
|
||||
{
|
||||
initdir=${1}
|
||||
scripts=$(ls ${initdir})
|
||||
order=
|
||||
end=0
|
||||
array=
|
||||
|
||||
# FIXME: New algorithm
|
||||
# array of strings: "$file $prereqs"
|
||||
# iterate over all strings; find empty strings (just $file)
|
||||
# add to order, delete from all strings and zero out entry
|
||||
# repeat until all strings are empty
|
||||
|
||||
i=0
|
||||
for file in $scripts; do
|
||||
# if it's not a regular file, or if it's not executable, skip it
|
||||
if ! [ -f ${initdir}/${file} ] || ! [ -x ${initdir}/${file} ]; then
|
||||
continue
|
||||
fi
|
||||
|
||||
array[$((i))]="$file $(${initdir}/${file} prereqs)"
|
||||
i=$((i+1))
|
||||
done
|
||||
|
||||
# No scripts in directory, bail.
|
||||
if [ ${i} -eq 0 ]; then
|
||||
return 0
|
||||
fi
|
||||
|
||||
while /bin/true; do
|
||||
set - ${array[@]}
|
||||
|
||||
if [ "$#" -eq "0" ]; then
|
||||
break
|
||||
fi
|
||||
|
||||
dep_reduce
|
||||
|
||||
dep_remove
|
||||
|
||||
if [ "${#neworder}" -eq "0" ]; then
|
||||
for x in "${array[@]}"; do
|
||||
if [ x"$x" != x"" ]; then
|
||||
printf "could not reduce further; "
|
||||
printf "circular dependencies\n"
|
||||
return 1
|
||||
fi
|
||||
done
|
||||
|
||||
# we're done!
|
||||
break
|
||||
fi
|
||||
done
|
||||
|
||||
# run the initscripts
|
||||
for script in "${order[@]}"; do
|
||||
${initdir}/${script}
|
||||
done
|
||||
}
|
||||
|
||||
18
scripts/init-top/test
Normal file
18
scripts/init-top/test
Normal file
@ -0,0 +1,18 @@
|
||||
#!/bin/sh
|
||||
|
||||
PREREQ=""
|
||||
|
||||
prereqs()
|
||||
{
|
||||
echo "$PREREQ"
|
||||
}
|
||||
|
||||
case $1 in
|
||||
# get pre-requisites
|
||||
prereqs)
|
||||
prereqs
|
||||
exit 0
|
||||
;;
|
||||
esac
|
||||
|
||||
echo "Got here!"
|
||||
@ -3,6 +3,8 @@
|
||||
# Parameter: Where to mount the filesystem
|
||||
mountroot ()
|
||||
{
|
||||
run_scripts /scripts/local_top
|
||||
|
||||
# Get the root filesystem type
|
||||
if [ ! -e ${ROOT} ]; then
|
||||
panic "ALERT! ${ROOT} does not exist. Dropping to a shell!"
|
||||
@ -10,6 +12,10 @@ mountroot ()
|
||||
|
||||
eval $(fstype < ${ROOT})
|
||||
|
||||
run_scripts /scripts/local_premount
|
||||
|
||||
# Mount root
|
||||
mount ${ro} -t ${FSTYPE} ${ROOT} ${rootmnt}
|
||||
|
||||
run_scripts /scripts/local_bottom
|
||||
}
|
||||
|
||||
@ -2,10 +2,18 @@
|
||||
# Paramter: Where the root should be mounted
|
||||
mountroot ()
|
||||
{
|
||||
run_scripts /scripts/nfs_top
|
||||
|
||||
ipconfig ${DEVICE}
|
||||
. /tmp/net-${DEVICE}.conf
|
||||
if [ "x${NFSROOT}" = "xauto" ]; then
|
||||
NFSROOT=${ROOTSERVER}:${ROOTPATH}
|
||||
fi
|
||||
|
||||
run_scripts /scripts/nfs_premount
|
||||
|
||||
nfsmount ${NFSROOT} ${rootmnt}
|
||||
|
||||
run_scripts /scripts/nfs_bottom
|
||||
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user