Changeset View
Standalone View
usr.sbin/freebsd-update/freebsd-update.sh
Show First 20 Lines • Show All 2,888 Lines • ▼ Show 20 Lines | backup_kernel () { | ||||
# Backup all the kernel files using hardlinks. | # Backup all the kernel files using hardlinks. | ||||
(cd ${BASEDIR}/${KERNELDIR} && find . -type f $FINDFILTER -exec \ | (cd ${BASEDIR}/${KERNELDIR} && find . -type f $FINDFILTER -exec \ | ||||
cp -pl '{}' ${BASEDIR}/${BACKUPKERNELDIR}/'{}' \;) | cp -pl '{}' ${BASEDIR}/${BACKUPKERNELDIR}/'{}' \;) | ||||
# Re-enable patchname expansion. | # Re-enable patchname expansion. | ||||
set +f | set +f | ||||
} | } | ||||
# Check for and remove an existing directory that conflicts with the file or | |||||
# symlink that we are going to install. | |||||
dir_conflict () { | |||||
if [ -d "$1" ]; then | |||||
emaste: Oh I guess -e && -d is redundant, will drop -e
| |||||
echo "Removing conflicting directory $1" | |||||
rm -rf -- "$1" | |||||
fi | |||||
} | |||||
# Install new files | # Install new files | ||||
install_from_index () { | install_from_index () { | ||||
# First pass: Do everything apart from setting file flags. We | # First pass: Do everything apart from setting file flags. We | ||||
# can't set flags yet, because schg inhibits hard linking. | # can't set flags yet, because schg inhibits hard linking. | ||||
sort -k 1,1 -t '|' $1 | | sort -k 1,1 -t '|' $1 | | ||||
tr '|' ' ' | | tr '|' ' ' | | ||||
while read FPATH TYPE OWNER GROUP PERM FLAGS HASH LINK; do | while read FPATH TYPE OWNER GROUP PERM FLAGS HASH LINK; do | ||||
case ${TYPE} in | case ${TYPE} in | ||||
d) | d) | ||||
# Create a directory. A file may change to a directory | # Create a directory. A file may change to a directory | ||||
# on upgrade (PR273661). If that happens, remove the | # on upgrade (PR273661). If that happens, remove the | ||||
# file first. | # file first. | ||||
if [ -e "${BASEDIR}/${FPATH}" ] && \ | if [ -e "${BASEDIR}/${FPATH}" ] && \ | ||||
Not Done Inline ActionsThis could be shortened as: if [ -e "${BASEDIR}/${FPATH}" ] && [ ${TYPE} = d ] && ! [ -d "${BASEDIR}/${FPATH}" ]; then since && short-circuits. But it's mostly a matter of preference. dim: This could be shortened as:
```
if [ -e "${BASEDIR}/${FPATH}" ] && [ ${TYPE} = d ] && ! [ -d… | |||||
Not Done Inline ActionsOr maybe even: if [ -e "${BASEDIR}/${FPATH}" -a ${TYPE} = d -a ! -d "${BASEDIR}/${FPATH}" ]; then (it reduces the amount of calls to test through [, although it is a built-in in sh anyway) khorben_defora.org: Or maybe even:
```
if [ -e "${BASEDIR}/${FPATH}" -a ${TYPE} = d -a ! -d "${BASEDIR}/${FPATH}"… | |||||
Done Inline ActionsThat doesn't have the benefit of short-circuiting though (and [ is a built-in anyhow, as you say). In any case that change is already committed and is independent of this review :) emaste: That doesn't have the benefit of short-circuiting though (and `[` is a built-in anyhow, as you… | |||||
! [ -d "${BASEDIR}/${FPATH}" ]; then | ! [ -d "${BASEDIR}/${FPATH}" ]; then | ||||
rm -f -- "${BASEDIR}/${FPATH}" | rm -f -- "${BASEDIR}/${FPATH}" | ||||
fi | fi | ||||
install -d -o ${OWNER} -g ${GROUP} \ | install -d -o ${OWNER} -g ${GROUP} \ | ||||
-m ${PERM} ${BASEDIR}/${FPATH} | -m ${PERM} ${BASEDIR}/${FPATH} | ||||
;; | ;; | ||||
f) | f) | ||||
dir_conflict "${BASEDIR}/${FPATH}" | |||||
if [ -z "${LINK}" ]; then | if [ -z "${LINK}" ]; then | ||||
# Create a file, without setting flags. | # Create a file, without setting flags. | ||||
gunzip < files/${HASH}.gz > ${HASH} | gunzip < files/${HASH}.gz > ${HASH} | ||||
install -S -o ${OWNER} -g ${GROUP} \ | install -S -o ${OWNER} -g ${GROUP} \ | ||||
-m ${PERM} ${HASH} ${BASEDIR}/${FPATH} | -m ${PERM} ${HASH} ${BASEDIR}/${FPATH} | ||||
rm ${HASH} | rm ${HASH} | ||||
else | else | ||||
# Create a hard link. | # Create a hard link. | ||||
ln -f ${BASEDIR}/${LINK} ${BASEDIR}/${FPATH} | ln -f ${BASEDIR}/${LINK} ${BASEDIR}/${FPATH} | ||||
fi | fi | ||||
;; | ;; | ||||
L) | L) | ||||
dir_conflict "${BASEDIR}/${FPATH}" | |||||
# Create a symlink | # Create a symlink | ||||
ln -sfh ${HASH} ${BASEDIR}/${FPATH} | ln -sfh ${HASH} ${BASEDIR}/${FPATH} | ||||
;; | ;; | ||||
esac | esac | ||||
done | done | ||||
# Perform a second pass, adding file flags. | # Perform a second pass, adding file flags. | ||||
tr '|' ' ' < $1 | | tr '|' ' ' < $1 | | ||||
Show All 20 Lines | install_delete () { | ||||
# Remove the offending bits | # Remove the offending bits | ||||
while read FPATH TYPE; do | while read FPATH TYPE; do | ||||
case ${TYPE} in | case ${TYPE} in | ||||
d) | d) | ||||
rmdir ${BASEDIR}/${FPATH} | rmdir ${BASEDIR}/${FPATH} | ||||
;; | ;; | ||||
f) | f) | ||||
rm ${BASEDIR}/${FPATH} | if [ -f "${BASEDIR}/${FPATH}" ]; then | ||||
rm "${BASEDIR}/${FPATH}" | |||||
fi | |||||
;; | ;; | ||||
L) | L) | ||||
rm ${BASEDIR}/${FPATH} | if [ -L "${BASEDIR}/${FPATH}" ]; then | ||||
rm "${BASEDIR}/${FPATH}" | |||||
fi | |||||
Not Done Inline ActionsIf you are deleting directories in dir_conflict using rm -rf I think it is reasonable to delete these offending files with rm -f too, and in that case it is not necessary to do the if [ -e, since rm will shut up and not fail in such cases. dim: If you are deleting directories in `dir_conflict` using `rm -rf` I think it is reasonable to… | |||||
Done Inline ActionsI've switched this to [ -f "${BASEDIR}/${FPATH} ] and [ -L "${BASEDIR}/${FPATH} ] locally now, because we still get an error message: $ touch not-a-dir emaste: I've switched this to `[ -f "${BASEDIR}/${FPATH} ]` and `[ -L "${BASEDIR}/${FPATH} ]` locally… | |||||
Not Done Inline ActionsTrue, I did not think of that. khorben_defora.org: True, I did not think of that. | |||||
;; | ;; | ||||
esac | esac | ||||
done < killfiles | done < killfiles | ||||
# Clean up | # Clean up | ||||
rm newfiles killfiles | rm newfiles killfiles | ||||
} | } | ||||
▲ Show 20 Lines • Show All 545 Lines • Show Last 20 Lines |
Oh I guess -e && -d is redundant, will drop -e