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.

117 lines
3.0 KiB

5 years ago
2 years ago
5 years ago
4 years ago
3 years 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. echo "--------------------------------"
  32. echo "debian-bash has been deprecated!"
  33. echo "--------------------------------"
  34. if [[ -z "$PS1" ]]; then
  35. read -rn1 -p 'Would you like to migrate to the new project named `miaou-bash`, (yN)?' answer
  36. else
  37. echo "--------------------------------------------------"
  38. echo "automatic migration from debian-bash to miaou-bash"
  39. echo "--------------------------------------------------"
  40. answer='y'
  41. fi
  42. if [[ "$answer" == 'y' ]];then
  43. pushd /tmp
  44. pushd /opt/debian-bash
  45. ./uninstall.sh
  46. popd
  47. rm -rf /opt/debian-bash
  48. curl https://git.artcode.re/miaou/miaou-bash/raw/branch/main/install.sh | sudo bash -s
  49. source /etc/bash.bashrc
  50. exit 0
  51. fi
  52. echo "cancelled!"
  53. exit 1
  54. fi
  55. }
  56. function install_containers() {
  57. echo "install containers"
  58. echo --------------------
  59. # install inside active LXC containers
  60. if [[ -f '/snap/bin/lxc' ]]; then
  61. for container in $(/snap/bin/lxc list --format=json | yq '.[] | select(.state.status == "Running") | .name' -); do
  62. install_one_container "$container"
  63. echo
  64. done
  65. fi
  66. }
  67. function install_one_container() {
  68. CT=$1
  69. echo "install container <$CT>"
  70. echo -------------------------
  71. # install inside one active LXC container
  72. if [[ -f '/snap/bin/lxc' ]]; then
  73. echo "pushed to $CT"
  74. /snap/bin/lxc file push /opt/debian-bash "${CT}/opt/" -r
  75. /snap/bin/lxc exec "$CT" -- sh -c "cd /opt/debian-bash && ./install.sh --host"
  76. fi
  77. }
  78. PARAM1=$1
  79. case $PARAM1 in
  80. "--host")
  81. install_host
  82. ;;
  83. "--containers")
  84. install_containers
  85. ;;
  86. "--one-container")
  87. CT=$2
  88. if [ ! -z "$CT" ]; then
  89. install_one_container "$CT"
  90. else
  91. usage
  92. fi
  93. ;;
  94. "--full")
  95. install_host
  96. install_containers
  97. ;;
  98. *)
  99. usage
  100. ;;
  101. esac