fix symlink loop
This commit is contained in:
parent
3cd153267a
commit
9837823f82
@ -23,7 +23,7 @@
|
|||||||
|
|
||||||
# avoid possible issues with libgcc_s.so.1
|
# avoid possible issues with libgcc_s.so.1
|
||||||
# see https://bugs.archlinux.org/task/56771
|
# see https://bugs.archlinux.org/task/56771
|
||||||
[ -e /lib/libgcc_s.so.1 ] && copy_library /lib/libgcc_s.so.1
|
[ -e /lib/libgcc_s.so.1 ] && copy_file /lib/libgcc_s.so.1 /lib 755 1
|
||||||
|
|
||||||
IFS=,; set -- $luks_opts; unset IFS
|
IFS=,; set -- $luks_opts; unset IFS
|
||||||
|
|
||||||
|
105
tinyramfs
105
tinyramfs
@ -140,15 +140,40 @@ prepare_initramfs()
|
|||||||
print "blkid not found. you will unable to use UUID, LABEL, PARTUUID"
|
print "blkid not found. you will unable to use UUID, LABEL, PARTUUID"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# copy init
|
copy_file "${srcdir}/init" / 755 0
|
||||||
cp "${srcdir}/init" "${tmpdir}/init"
|
copy_file "$config" /etc/tinyramfs 644 0
|
||||||
chmod 755 "${tmpdir}/init"
|
|
||||||
|
|
||||||
# copy config
|
|
||||||
cp "$config" "${tmpdir}/etc/tinyramfs/config"
|
|
||||||
chmod 600 "${tmpdir}/etc/tinyramfs/config"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
copy_file()
|
||||||
|
(
|
||||||
|
file="$1"; dest="$2"; mode="$3"; strip="$4"
|
||||||
|
|
||||||
|
# check if file already exist
|
||||||
|
[ -e "${tmpdir}${dest}/${file##*/}" ] && return 0
|
||||||
|
|
||||||
|
mkdir -p "${tmpdir}${dest}" || panic
|
||||||
|
|
||||||
|
# iterate throught symlinks and copy them
|
||||||
|
while [ -h "$file" ]; do
|
||||||
|
cp -P "$file" "${tmpdir}${dest}" || panic
|
||||||
|
cd -P "${file%/*}"
|
||||||
|
|
||||||
|
symlink=$(ls -ld "$file")
|
||||||
|
symlink=${symlink##* -> }
|
||||||
|
|
||||||
|
file="${PWD}/${symlink##*/}"
|
||||||
|
done
|
||||||
|
|
||||||
|
{
|
||||||
|
cp "$file" "${tmpdir}${dest}"
|
||||||
|
chmod "$mode" "${tmpdir}${dest}/${file##*/}"
|
||||||
|
} || panic
|
||||||
|
|
||||||
|
# false positive
|
||||||
|
# shellcheck disable=2015
|
||||||
|
[ "$strip" = 1 ] && strip "${tmpdir}${dest}/${file##*/}" > /dev/null 2>&1 || :
|
||||||
|
)
|
||||||
|
|
||||||
copy_binary()
|
copy_binary()
|
||||||
{
|
{
|
||||||
binary=$(command -v "$1")
|
binary=$(command -v "$1")
|
||||||
@ -175,21 +200,7 @@ copy_binary()
|
|||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
# check if binary already exist
|
copy_file "$binary" /bin 755 1
|
||||||
[ -e "${tmpdir}/bin/${binary##*/}" ] && return 0
|
|
||||||
|
|
||||||
# iterate throught symlinks and copy them
|
|
||||||
while [ -h "$binary" ]; do symlink=$(ls -ld "$binary")
|
|
||||||
cp -P "$binary" "${tmpdir}/bin" || panic
|
|
||||||
binary="${binary%/*}/${symlink##* ->*[ /]}"
|
|
||||||
done
|
|
||||||
|
|
||||||
{
|
|
||||||
cp "$binary" "${tmpdir}/bin"
|
|
||||||
chmod 755 "${tmpdir}/bin/${binary##*/}"
|
|
||||||
} || panic
|
|
||||||
|
|
||||||
strip "${tmpdir}/bin/${binary##*/}" > /dev/null 2>&1 || :
|
|
||||||
|
|
||||||
# copy binary dependencies if any
|
# copy binary dependencies if any
|
||||||
ldd "$binary" 2> /dev/null |
|
ldd "$binary" 2> /dev/null |
|
||||||
@ -201,31 +212,10 @@ copy_binary()
|
|||||||
|
|
||||||
[ -e "$_library" ] || continue
|
[ -e "$_library" ] || continue
|
||||||
|
|
||||||
copy_library "$_library"
|
copy_file "$_library" /lib 755 1
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
copy_library()
|
|
||||||
{
|
|
||||||
library="$1"
|
|
||||||
|
|
||||||
# check if library already exist
|
|
||||||
[ -e "${tmpdir}/lib/${library##*/}" ] && return 0
|
|
||||||
|
|
||||||
# iterate throught symlinks and copy them
|
|
||||||
while [ -h "$library" ]; do symlink=$(ls -ld "$library")
|
|
||||||
cp -P "$library" "${tmpdir}/lib" || panic
|
|
||||||
library="/lib/${symlink##* ->*[ /]}"
|
|
||||||
done
|
|
||||||
|
|
||||||
{
|
|
||||||
cp "$library" "${tmpdir}/lib"
|
|
||||||
chmod 755 "${tmpdir}/lib/${library##*/}"
|
|
||||||
} || panic
|
|
||||||
|
|
||||||
strip "${tmpdir}/lib/${library##*/}" > /dev/null 2>&1 || :
|
|
||||||
}
|
|
||||||
|
|
||||||
copy_module()
|
copy_module()
|
||||||
{
|
{
|
||||||
module="$1"
|
module="$1"
|
||||||
@ -237,14 +227,7 @@ copy_module()
|
|||||||
# check if module contains full path(not builtin)
|
# check if module contains full path(not builtin)
|
||||||
[ "${module##*/*}" ] && continue
|
[ "${module##*/*}" ] && continue
|
||||||
|
|
||||||
# check if module already exist
|
copy_file "$module" "${module%/*}" 644 0
|
||||||
[ -e "${tmpdir}${module}" ] && continue
|
|
||||||
|
|
||||||
{
|
|
||||||
mkdir -p "${tmpdir}${module%/*}"
|
|
||||||
cp "$module" "${tmpdir}${module}"
|
|
||||||
chmod 644 "${tmpdir}${module}"
|
|
||||||
} || panic
|
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -254,7 +237,7 @@ copy_hook()
|
|||||||
|
|
||||||
# false positive
|
# false positive
|
||||||
# shellcheck disable=1090
|
# shellcheck disable=1090
|
||||||
for _dir in "$hksdir" /etc/tinyramfs/hooks /usr/share/tinyramfs/hooks; do
|
for _dir in "$hksdir" /etc/tinyramfs/hooks "${srcdir}/hooks"; do
|
||||||
[ -f "${_dir}/${hook}/${hook}" ] || ! continue
|
[ -f "${_dir}/${hook}/${hook}" ] || ! continue
|
||||||
|
|
||||||
print "running $hook hook"; . "${_dir}/${hook}/${hook}"
|
print "running $hook hook"; . "${_dir}/${hook}/${hook}"
|
||||||
@ -262,11 +245,8 @@ copy_hook()
|
|||||||
for _file in init init.late; do
|
for _file in init init.late; do
|
||||||
[ -f "${_dir}/${hook}/${hook}.${_file}" ] || continue
|
[ -f "${_dir}/${hook}/${hook}.${_file}" ] || continue
|
||||||
|
|
||||||
{
|
copy_file "${_dir}/${hook}/${hook}.${_file}" \
|
||||||
mkdir -p "${tmpdir}/usr/share/tinyramfs/hooks/${hook##*/}"
|
"/usr/share/tinyramfs/hooks/${hook##*/}" 644 0
|
||||||
cp "${_dir}/${hook}/${hook}.${_file}" \
|
|
||||||
"${tmpdir}/usr/share/tinyramfs/hooks/${hook##*/}"
|
|
||||||
} || panic
|
|
||||||
done
|
done
|
||||||
|
|
||||||
break
|
break
|
||||||
@ -345,13 +325,8 @@ copy_modules()
|
|||||||
|
|
||||||
copy_binary modprobe
|
copy_binary modprobe
|
||||||
|
|
||||||
cp "${moddir}/${kernel}/modules.builtin" \
|
copy_file "${moddir}/${kernel}/modules.order" "${moddir}/${kernel}" 644 0
|
||||||
"${moddir}/${kernel}/modules.order" \
|
copy_file "${moddir}/${kernel}/modules.builtin" "${moddir}/${kernel}" 644 0
|
||||||
"${tmpdir}${moddir}/${kernel}"
|
|
||||||
|
|
||||||
chmod 644 \
|
|
||||||
"${tmpdir}${moddir}/${kernel}/modules.builtin" \
|
|
||||||
"${tmpdir}${moddir}/${kernel}/modules.order"
|
|
||||||
|
|
||||||
depmod -b "$tmpdir" "$kernel"
|
depmod -b "$tmpdir" "$kernel"
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user