version 1.100, 2021/12/22 04:29:18 |
version 1.105, 2021/12/22 17:53:53 |
|
|
# we have su(1) and doas(1) is unlikely to be configured. |
# we have su(1) and doas(1) is unlikely to be configured. |
set -o monitor # make sure ftp gets its own process group |
set -o monitor # make sure ftp gets its own process group |
( |
( |
|
flags=-VM |
|
"$VERBOSE" && flags=-vm |
if [ -x /usr/bin/su ]; then |
if [ -x /usr/bin/su ]; then |
exec /usr/bin/su -s /bin/ksh "$_user" -c \ |
exec /usr/bin/su -s /bin/ksh "$_user" -c \ |
"/usr/bin/ftp -D 'Get/Verify' -Vm -o- '$_src'" > "$_dst" |
"/usr/bin/ftp -D 'Get/Verify' $flags -o- '$_src'" > "$_dst" |
else |
else |
exec /usr/bin/doas -u "$_user" \ |
exec /usr/bin/doas -u "$_user" \ |
/usr/bin/ftp -D 'Get/Verify' -Vm -o- "$_src" > "$_dst" |
/usr/bin/ftp -D 'Get/Verify' $flags -o- "$_src" > "$_dst" |
fi |
fi |
) & _pid=$! |
) & _pid=$! |
set +o monitor |
set +o monitor |
|
|
add_firmware () { |
add_firmware () { |
local _f="${1##*/}" |
local _f="${1##*/}" |
local _pkgdir="${DESTDIR}/var/db/pkg/${_f%.tgz}" |
local _pkgdir="${DESTDIR}/var/db/pkg/${_f%.tgz}" |
ftp -D "Install" -Vmo- "file:${1}" | |
local flags=-VM |
|
"$VERBOSE" && flags=-vm |
|
ftp -D "Install" "$flags" -o- "file:${1}" | |
tar -s ",^\+,${_pkgdir}/+," \ |
tar -s ",^\+,${_pkgdir}/+," \ |
-s ",^firmware,${DESTDIR}/etc/firmware," \ |
-s ",^firmware,${DESTDIR}/etc/firmware," \ |
-C / -zxphf - "+*" "firmware/*" |
-C / -zxphf - "+*" "firmware/*" |
|
|
local _cwd _pkg="$1" _pkgdir="${DESTDIR}/var/db/pkg" |
local _cwd _pkg="$1" _pkgdir="${DESTDIR}/var/db/pkg" |
|
|
# TODO: Check hash for files before deleting |
# TODO: Check hash for files before deleting |
echo "Uninstalling $_pkg" |
"$VERBOSE" && echo "Uninstalling $_pkg" |
_cwd="${_pkgdir}/$_pkg" |
_cwd="${_pkgdir}/$_pkg" |
|
|
set -A _remove -- "${_cwd}/+CONTENTS" "${_cwd}" |
set -A _remove -- "${_cwd}/+CONTENTS" "${_cwd}" |
|
|
} |
} |
|
|
usage() { |
usage() { |
echo "usage: ${0##*/} [-D | -L] [driver | file ...]" |
echo "usage: ${0##*/} [-v] [-D | -L] [driver | file ...]" |
exit 2 |
exit 2 |
} |
} |
|
|
|
|
DOWNLOAD=false |
DOWNLOAD=false |
LOCALSRC=. |
LOCALSRC=. |
else |
else |
LOCALSRC="$( tmpdir "${DESTDIR}/tmp/fw_install" )" |
LOCALSRC="$( tmpdir "${DESTDIR}/tmp/${0##*/}" )" |
fi |
fi |
|
|
CFILE="$LOCALSRC/$CFILE" |
CFILE="$LOCALSRC/$CFILE" |
|
|
if "$INSTALL" && [ -x /usr/bin/id ] && [ $(/usr/bin/id -u) != 0 ]; then |
if "$INSTALL" && [ -x /usr/bin/id ] && [ "$(/usr/bin/id -u)" != 0 ]; then |
echo "need root privileges" >&2 |
echo "need root privileges" >&2 |
exit 1 |
exit 1 |
fi |
fi |
|
|
set -A devices -- "$@" |
set -A devices -- "$@" |
|
|
if [ ! "${devices[*]:-}" ]; then |
if [ ! "${devices[*]:-}" ]; then |
echo -n "Detecting firmware ..." |
"$VERBOSE" && echo -n "Detecting firmware ..." |
set -A devices -- $( devices_needing_firmware ) |
set -A devices -- $( devices_needing_firmware ) |
[ "${devices[*]:-}" ] && echo " found." || echo " done." |
"$VERBOSE" && |
|
{ [ "${devices[*]:-}" ] && echo " found." || echo " done." ; } |
fi |
fi |
|
|
[ "${devices[*]:-}" ] || exit |
[ "${devices[*]:-}" ] || exit |
|
|
echo "Signature check of SHA256.sig failed" >&2 && exit 1 |
echo "Signature check of SHA256.sig failed" >&2 && exit 1 |
fi |
fi |
|
|
|
added='' |
|
updated='' |
for f in "${devices[@]}"; do |
for f in "${devices[@]}"; do |
d="$( firmware_devicename "$f" )" |
d="$( firmware_devicename "$f" )" |
|
|
|
|
if "$INSTALL" && [ "${installed[*]:-}" ]; then |
if "$INSTALL" && [ "${installed[*]:-}" ]; then |
for i in "${installed[@]}"; do |
for i in "${installed[@]}"; do |
if [ "${f##*/}" = "$i.tgz" ]; then |
if [ "${f##*/}" = "$i.tgz" ]; then |
echo "$i already installed" |
"$VERBOSE" && echo "$i already installed" |
continue 2 |
continue 2 |
fi |
fi |
done |
done |
|
|
|
|
if [ -e "$f" ]; then |
if [ -e "$f" ]; then |
if "$DOWNLOAD"; then |
if "$DOWNLOAD"; then |
echo "Verify existing ${f##*/}" |
"$VERBOSE" && echo "Verify existing ${f##*/}" |
verify "$f" || continue |
verify "$f" || continue |
# else assume it was verified when downloaded |
# else assume it was verified when downloaded |
fi |
fi |
|
|
|
|
"$INSTALL" || continue |
"$INSTALL" || continue |
|
|
|
removed=false |
if [ "${installed[*]:-}" ]; then |
if [ "${installed[*]:-}" ]; then |
for i in "${installed[@]}"; do |
for i in "${installed[@]}"; do |
delete_firmware "$i" |
delete_firmware "$i" |
|
removed=true |
done |
done |
fi |
fi |
|
|
add_firmware "$f" |
add_firmware "$f" |
|
|
|
if "$removed"; then |
|
[ "$updated" ] && updated="$updated," |
|
updated="$updated$d" |
|
else |
|
[ "$added" ] && added="$added," |
|
added="$added$d" |
|
fi |
done |
done |
|
|
|
if ! $VERBOSE && { [ "$added" ] || [ "$updated" ]; }; then |
|
echo "${0##*/}: $( |
|
[ "$added" ] && echo -n "added ${added}" |
|
[ "$added" ] && [ "$updated" ] && echo -n "; " |
|
[ "$updated" ] && echo -n "updated ${updated}" |
|
)" |
|
fi |