upk 786 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #!/bin/sh --
  2. set -ue
  3. # update kernel
  4. SRC=/usr/src
  5. cd "${SRC}"
  6. DELETE=1
  7. while getopts n opt; do
  8. case "${opt}" in
  9. n) DELETE=0;;
  10. *)
  11. echo 'invalid flag' 1>&2
  12. exit 1
  13. esac
  14. done
  15. select="$(
  16. for k in ./linux-*; do echo "${k##*/}"; done \
  17. | sort -rV \
  18. | sk --margin=30%,30% --height=30 --reverse
  19. )"
  20. prev="$(readlink -f -- ./linux)"
  21. [ "${prev##*/}" != "${select}" ]
  22. echo "updating '${prev##*/}' -> '${select}'"
  23. [ "${DELETE}" -eq 1 ] || echo 'and not deleting old sources'
  24. # shellcheck disable=2016
  25. {
  26. cmd='install -Tvm644 -- "${2:?}/.config" ./.config'\
  27. '; install -Tvm644 -- ./.config "${1:?}/.config"'\
  28. '; eselect kernel set "${1##*/}"'
  29. [ "${DELETE}" -eq 1 ] && cmd="${cmd}"'; rm -rf -- "${2}"'
  30. }
  31. doas -- sh -uec "${cmd}" sh "${SRC}/${select}" "${prev}"
  32. eselect kernel show