Useful CLI tools (bash) for Arch Linux administration
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

113 lines
2.4 KiB

  1. #!/usr/bin/bash
  2. #
  3. # source.sh - functions for downloading and extracting sources
  4. #
  5. # Copyright (c) 2015-2018 Pacman Development Team <pacman-dev@archlinux.org>
  6. #
  7. # This program is free software; you can redistribute it and/or modify
  8. # it under the terms of the GNU General Public License as published by
  9. # the Free Software Foundation; either version 2 of the License, or
  10. # (at your option) any later version.
  11. #
  12. # This program is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. # GNU General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU General Public License
  18. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. #
  20. [[ -n "$LIBMAKEPKG_SOURCE_SH" ]] && return
  21. LIBMAKEPKG_SOURCE_SH=1
  22. LIBRARY=${LIBRARY:-'/usr/share/makepkg'}
  23. source "$LIBRARY/util/message.sh"
  24. source "$LIBRARY/util/pkgbuild.sh"
  25. source "$LIBRARY/util/source.sh"
  26. for lib in "$LIBRARY/source/"*.sh; do
  27. source "$lib"
  28. done
  29. download_sources() {
  30. local netfile all_sources
  31. local get_source_fn=get_all_sources_for_arch get_vcs=1
  32. msg "$(gettext "Retrieving sources...")"
  33. while true; do
  34. case $1 in
  35. allarch)
  36. get_source_fn=get_all_sources
  37. ;;
  38. novcs)
  39. get_vcs=0
  40. ;;
  41. *)
  42. break
  43. ;;
  44. esac
  45. shift
  46. done
  47. "$get_source_fn" 'all_sources'
  48. for netfile in "${all_sources[@]}"; do
  49. pushd "$SRCDEST" &>/dev/null
  50. local proto=$(get_protocol "$netfile")
  51. case "$proto" in
  52. local)
  53. download_local "$netfile"
  54. ;;
  55. bzr*)
  56. (( get_vcs )) && download_bzr "$netfile"
  57. ;;
  58. git*)
  59. (( get_vcs )) && download_git "$netfile" "--depth" "1"
  60. ;;
  61. hg*)
  62. (( get_vcs )) && download_hg "$netfile"
  63. ;;
  64. svn*)
  65. (( get_vcs )) && download_svn "$netfile"
  66. ;;
  67. *)
  68. download_file "$netfile"
  69. ;;
  70. esac
  71. popd &>/dev/null
  72. done
  73. }
  74. extract_sources() {
  75. msg "$(gettext "Extracting sources...")"
  76. local netfile all_sources
  77. get_all_sources_for_arch 'all_sources'
  78. for netfile in "${all_sources[@]}"; do
  79. local file=$(get_filename "$netfile")
  80. local proto=$(get_protocol "$netfile")
  81. case "$proto" in
  82. bzr*)
  83. extract_bzr "$netfile"
  84. ;;
  85. git*)
  86. extract_git "$netfile"
  87. ;;
  88. hg*)
  89. extract_hg "$netfile"
  90. ;;
  91. svn*)
  92. extract_svn "$netfile"
  93. ;;
  94. *)
  95. extract_file "$file"
  96. ;;
  97. esac
  98. done
  99. }