openwrtContainerBuild 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. #!/usr/bin/env bash
  2. source ./functions
  3. #####################
  4. ##### DEFAULTS ######
  5. #####################
  6. _image="ath79-generic-19.07.2"
  7. _profile="tplink_archer-c7-v2"
  8. _debug="true" # Turn debugging on by default (useful for testing)
  9. #####################
  10. ##### FUNCTIONS #####
  11. #####################
  12. printHelpAndExit () {
  13. runDebug "${FUNCNAME[0]}"
  14. cat <<-'EOF'
  15. USAGE:
  16. buildOpenWRT [[OPTION] [VALUE]]...
  17. OPTIONS
  18. --image, -i OPENWRT_IMAGE
  19. Default: "ath79-generic-19.07.2"
  20. --profile, -p PROFILE
  21. Default: tplink_archer-c7-v2
  22. --builddir, -b PATH
  23. Default: Current working directory
  24. --package
  25. Add this package to the packages array declared in DEFAULTS
  26. Supports multiple --package directives
  27. --ssh-backup SSH_PATH
  28. Example: root@192.168.1.1
  29. --backup PATH
  30. Add this file or directory to the packages array declared in DEFAULTS
  31. --debug, -d
  32. --help, -h
  33. EOF
  34. # Exit using passed exit code
  35. [[ -z $1 ]] && exit 0 || exit "$1"
  36. }
  37. parseInput () {
  38. runDebug "${FUNCNAME[0]}"
  39. if _input=$(getopt -o +i:p:b:dh -l image:,profile:,builddir:,ssh-backup:,backup:,package:,debug,help -- "$@"); then
  40. eval set -- "$_input"
  41. while true; do
  42. case "$1" in
  43. --image|-i)
  44. shift && _image="$1"
  45. ;;
  46. --profile|-p)
  47. shift && _profile="$1"
  48. ;;
  49. --package)
  50. shift && _packages+=("$1")
  51. ;;
  52. --builddir|-b)
  53. shift && _builddir="$1"
  54. ;;
  55. --ssh-backup)
  56. shift && _ssh_backup="$1"
  57. ;;
  58. --backup)
  59. shift && _backedup+=("$1")
  60. ;;
  61. --debug|-d)
  62. echo "Debugging on"
  63. _debug="true"
  64. ;;
  65. --help|-h)
  66. _printHelpAndExit 0
  67. ;;
  68. --)
  69. shift
  70. break
  71. ;;
  72. esac
  73. shift
  74. done
  75. else
  76. echo "Incorrect options provided"
  77. printHelpAndExit 1
  78. fi
  79. }
  80. mkDirs () {
  81. runDebug "${FUNCNAME[0]}"
  82. [[ ! -d "$_filesroot" ]] && \
  83. mkdir -p "$_filesroot"
  84. [[ ! -d "$_builddir/bin" ]] && \
  85. mkdir -p "$_builddir/bin"
  86. # fix SELinux contexts
  87. chcon -t container_file_t -R "$_builddir/bin"
  88. chcon -t container_file_t -R "$_filesroot"
  89. }
  90. __main() {
  91. parseInput "$@"
  92. mkDirs
  93. [[ -n $_ssh_backup ]] && sshBackup
  94. podman run \
  95. --rm \
  96. --userns="keep-id" \
  97. -v "$_builddir/bin/:/home/build/openwrt/bin" \
  98. -v "$_filesroot:$_filesroot" \
  99. openwrtorg/imagebuilder:"$_image" \
  100. make image PROFILE="$_profile" PACKAGES="${_packages[*]}" FILES="$_filesroot"
  101. }
  102. __main "$@"