extract_config.sh 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #!/bin/bash
  2. [[ -d "$1" ]] || {
  3. echo "Usage: $(basename $0) <busybox_sourcedir>"
  4. exit 1
  5. }
  6. bbsrc="$(realpath $1)"
  7. cd $(dirname $0)
  8. [[ -e config.new ]] && {
  9. echo -n "config.new exists already. delete? [y|n] "
  10. read ans
  11. case "$ans" in
  12. y|Y)
  13. rm -rf config.new
  14. ;;
  15. n|N)
  16. ;;
  17. *)
  18. echo "what is '$ans'?"
  19. exit 1
  20. esac
  21. }
  22. mkdir -p config.new
  23. # store config paths relative to $bbsrc into an array
  24. readarray -t configs <<< $(cd "$bbsrc"; find . -type f -name Config.in)
  25. # copy each config into config.new
  26. for config in "${configs[@]}"; do
  27. mkdir -p config.new/$(dirname $config)
  28. cp "$bbsrc/$config" "config.new/$config"
  29. done
  30. # store defined config symbols into an array
  31. readarray -t symbols <<< $(grep -hr '^config ' config.new | cut -d' ' -f2)
  32. ### customize busybox config system for OpenADK
  33. cd config.new
  34. # no extra mainmenu, allow replacing PREFIX
  35. sed -i -e 's/^mainmenu/# mainmenu/' -e 's,./_install,@IDIR@,' Config.in
  36. # prefix all symbols with BUSYBOX_ to create a namespace
  37. # limit replacement to lines containing given keywords to
  38. # not mess up help texts and prompts too much
  39. keywords='\(config\|depends\|range\|select\|default\|^if \)'
  40. sympipe=$(IFS='|'; echo "${symbols[*]}" | sed -e 's/|/\\|/g')
  41. sympipe_s='/'$keywords'/s/\b\('$sympipe'\)\b/BUSYBOX_\1/g'
  42. # fix path of all sourced files
  43. source_s='s,^\(source *\)\([^ ]*\)$,\1package/busybox/config/\2,'
  44. sed -i -e "$sympipe_s" -e "$source_s" "${configs[@]}"