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.

96 lines
2.1 KiB

5 years ago
2 years ago
5 years ago
4 years ago
3 years ago
1 year ago
1 year ago
5 years ago
5 years ago
4 years ago
5 years ago
5 years ago
4 years ago
4 years ago
  1. #!/bin/bash
  2. CURDIR=$PWD
  3. REQUIRED_PKGS=(file git bc)
  4. function usage() {
  5. echo 'usage: --host | --containers | --full | --one-container <CT_NAME>'
  6. exit 1
  7. }
  8. function install_host() {
  9. echo "install on: $HOSTNAME"
  10. echo ----------------------
  11. [ "$(id -u)" -ne 0 ] && echo 'root privilege required' && exit 1
  12. if [[ ! $CURDIR == '/opt/debian-bash' ]]; then
  13. # download and fullfill /opt/debian-bash, then run it from folder
  14. if [[ -L /opt/debian-bash ]]; then
  15. cd /opt/debian-bash && ./install.sh "$PARAM1"
  16. exit 0
  17. else
  18. rm -rf /opt/debian-bash
  19. TEMP=$(mktemp -d)
  20. cd "$TEMP" || return
  21. echo "$TEMP"
  22. wget https://git.artcode.re/pvincent/debian-bash/archive/master.tar.gz
  23. tar -xzf master.tar.gz
  24. mv debian-bash /opt/
  25. cd /opt/debian-bash || return
  26. ./install.sh "$PARAM1"
  27. rm -rf "$TEMP"
  28. exit 0
  29. fi
  30. else
  31. apt-get update
  32. apt-get install -y "${REQUIRED_PKGS[@]}"
  33. ./init.sh
  34. fi
  35. }
  36. function install_containers() {
  37. echo "install containers"
  38. echo --------------------
  39. # install inside active LXC containers
  40. if [[ -f '/snap/bin/lxc' ]]; then
  41. for container in $(/snap/bin/lxc list --format=json | yq '.[] | select(.state.status == "Running") | .name' -); do
  42. install_one_container "$container"
  43. echo
  44. done
  45. fi
  46. }
  47. function install_one_container() {
  48. CT=$1
  49. echo "install container <$CT>"
  50. echo -------------------------
  51. # install inside one active LXC container
  52. if [[ -f '/snap/bin/lxc' ]]; then
  53. echo "pushed to $CT"
  54. /snap/bin/lxc file push /opt/debian-bash "${CT}/opt/" -r
  55. /snap/bin/lxc exec "$CT" -- sh -c "cd /opt/debian-bash && ./install.sh --host"
  56. fi
  57. }
  58. PARAM1=$1
  59. case $PARAM1 in
  60. "--host")
  61. install_host
  62. ;;
  63. "--containers")
  64. install_containers
  65. ;;
  66. "--one-container")
  67. CT=$2
  68. if [ ! -z "$CT" ]; then
  69. install_one_container "$CT"
  70. else
  71. usage
  72. fi
  73. ;;
  74. "--full")
  75. install_host
  76. install_containers
  77. ;;
  78. *)
  79. usage
  80. ;;
  81. esac