xb.sh 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. #!/usr/bin/env bash
  2. # xb - a wannabe cross system source builder written in bash
  3. # by Adnan Shameem (adnan360); License: MIT (Expat)
  4. cd "$(dirname $0)" && source "inc/common.sh"
  5. install_packages_build=''
  6. install_packages_deps=''
  7. declare -a xb_filenames
  8. if [ -d '/usr/local/etc' ]; then
  9. usrdir='/usr/local'
  10. etcdir='/usr/local/etc'
  11. else
  12. usrdir='/usr'
  13. etcdir='/etc'
  14. fi
  15. # Stores where sources will be downloaded and built
  16. xb_parent_dir="$HOME/.cache/xb"
  17. for param in "$@"; do
  18. if [ -f "$param" ]; then
  19. xb_filename="$param"
  20. elif [ -f "$(dirname $(realpath $0))/xbrepo/${param}.xb" ]; then
  21. xb_filename="$(dirname $(realpath $0))/xbrepo/${param}.xb"
  22. else
  23. echo "Error: Parameter $param is invalid"
  24. continue # no file found, so look for next params
  25. fi
  26. if [ ! -f "$xb_filename" ]; then
  27. echo "Error: File $xb_filename not found"
  28. continue # go to next param
  29. fi
  30. xb_filenames+=("$xb_filename")
  31. echo "Reading info from ${xb_filename}"
  32. # Clean previous memory
  33. unset build_depends
  34. unset depends
  35. unset sources
  36. source "$xb_filename"
  37. if [[ "$sources" =~ .*".git".* ]] && [ "$(is_binary_installed "git")" = "$FALSE" ]; then
  38. install_packages_build+=' git'
  39. fi
  40. # Bring in deps from xb file
  41. install_packages_build+="$build_depends"
  42. install_packages_deps+="$depends"
  43. done
  44. ## Step 1: Install deps
  45. # Prepare list
  46. install_packages_build=$(convert_package_names "$install_packages_build" "$TRUE")
  47. install_packages_deps=$(convert_package_names "$install_packages_deps" "$TRUE")
  48. # Actually install
  49. echo "Will be installing packages: ${install_packages_build} ${install_packages_deps}"
  50. install_packages "${install_packages_build} ${install_packages_deps}"
  51. if [ -d /usr/local/share/icons ]; then
  52. system_icon_path='/usr/local/share/icons'
  53. else
  54. system_icon_path='/usr/share/icons'
  55. fi
  56. for xb_filename in "${xb_filenames[@]}"; do
  57. builddir="${xb_parent_dir}/$(random_string)"
  58. # Some distros, like in FreeBSD, GNU Make is available as "gmake". On others simply "make".
  59. gnumakebin=$(if [ "$(is_binary_installed "gmake")" = "$TRUE" ]; then echo gmake; elif [ "$(is_binary_installed "make")" = "$TRUE" ]; then echo make; fi)
  60. gnumakeparams=''
  61. mkdir -p "${builddir}"
  62. echo "Created $builddir for the build"
  63. # Unset previously set values
  64. unset do_download
  65. unset do_build
  66. unset do_install
  67. unset build_depends
  68. unset depends
  69. unset sources
  70. unset tested_systems
  71. source "$xb_filename"
  72. echo "Starting building xb file: ${xb_filename}"
  73. ## Step 2: Download sources
  74. cd "${builddir}"
  75. for src in $sources; do
  76. if [[ "$src" =~ .*".git".* ]]; then
  77. git clone --depth 1 "$src"
  78. echo "Source '${src}' cloned in ${builddir}"
  79. else
  80. curl -LO "$src"
  81. echo "Source '${src}' downloaded in ${builddir}"
  82. fi
  83. done
  84. ## Step 3: Download function
  85. [ -n "$(command -v do_download)" ] && do_download
  86. ## Step 4: Build
  87. [ -n "$(command -v do_build)" ] && do_build
  88. ## Step 5: Install
  89. [ -n "$(command -v do_install)" ] && do_install
  90. # Delete dir after build
  91. cd "$xb_parent_dir"
  92. # $subin is to delete all files regardless of file permission issues.
  93. # e.g. jgmenu has some issues clearing up files due to permission issue.
  94. $subin find "$builddir" -name "*" -delete
  95. done
  96. ## Step 6: Remove build deps
  97. remove_packages "${install_packages_build}"