fork 0k-charms
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.

92 lines
2.3 KiB

  1. #!/bin/bash
  2. set -eux
  3. ##
  4. ## kal-scripts
  5. ##
  6. if ! status=$(dpkg-query -W -f='${db:Status-Abbrev}\n' 'apt-transport-https') ||
  7. [ "$status" != "ii " ]; then
  8. ## Required to fetch our repository in https
  9. apt-get install -y apt-transport-https </dev/null
  10. fi
  11. update_repos_from_source_file() {
  12. local source_file="$1"
  13. ## Update only repo's from this source file
  14. if ! out=$(apt-get update \
  15. -o Dir::Etc::sourcelist="sources.list.d/${source_file}" \
  16. -o Dir::Etc::sourceparts="-" \
  17. -o APT::Get::List-Cleanup="0" 2>/dev/null); then
  18. return 3
  19. fi
  20. if [[ "$out" = *" NO_PUBKEY "* ]]; then
  21. return 2
  22. fi
  23. if [[ "$out" = *$'\n'"Err:1 "* ]]; then
  24. return 1
  25. fi
  26. return 0
  27. }
  28. check_working_source_file() {
  29. local source_file="$1"
  30. if ! [ -e "/etc/apt/sources.list.d/${source_file}" ]; then
  31. return 1
  32. fi
  33. update_repos_from_source_file "${source_file}" 2>/dev/null && return 0
  34. local errlvl="$?"
  35. if [[ "$errlvl" == 2 ]]; then
  36. return 2
  37. fi
  38. return 127 ## Unmanaged error
  39. }
  40. errlvl=0
  41. ## Will check and update package list if running correctly
  42. check_working_source_file "kalysto.org.list" || errlvl="$?"
  43. if [ "$errlvl" -gt 0 ]; then
  44. if [ "$errlvl" -le 1 ]; then ## no file in source list
  45. cat <<EOF > /etc/apt/sources.list.d/kalysto.org.list
  46. ## vlab's shell libraries
  47. deb https://deb.kalysto.org no-dist kal-alpha kal-beta kal-main
  48. EOF
  49. fi
  50. if [ "$errlvl" -le 2 ]; then ## no pub key
  51. if ! type gpg >/dev/null; then
  52. apt-get install -y gnupg2 </dev/null
  53. fi
  54. ## Include the GPG key
  55. wget -O - https://deb.kalysto.org/conf/public-key.gpg | apt-key add -
  56. ## Update only this repo:
  57. if ! update_repos_from_source_file "kalysto.org.list"; then
  58. echo "Error: Couldn't update repository information of kalysto deb repository" >&2
  59. echo " Despite having just added the GPG key." >&2
  60. exit 1
  61. fi
  62. fi
  63. if [ "$errlvl" == 127 ]; then
  64. echo "Error: Couldn't update repository information of kalysto deb repository..." >&2
  65. echo " - check /etc/apt/source.list.d/kalysto.org.list content and" >&2
  66. echo " - check \`\`apt-get update\`\` output for errors." >&2
  67. exit 1
  68. fi
  69. fi
  70. apt-get install -y kal-scripts </dev/null