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
2.7 KiB

5 years ago
2 years ago
5 years ago
4 years ago
3 years ago
4 years ago
5 years ago
5 years ago
4 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 filfull /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
  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
  26. ./install.sh $PARAM1
  27. rm -rf $TEMP
  28. exit 0
  29. fi
  30. else
  31. #remove /etc/skel/.bashrc
  32. if [ -e /etc/skel/.bashrc ]; then
  33. rm /etc/skel/.bashrc
  34. fi
  35. ORIGINAL="ORIGINAL"
  36. declare -a arr=(/etc/bash.bashrc /etc/inputrc /etc/vim/vimrc)
  37. for i in "${arr[@]}"; do
  38. if [ ! -f "$i.$ORIGINAL" ]; then
  39. echo "$i needs installation $(basename $i)"
  40. mv "$i" "$i.$ORIGINAL"
  41. ln -s "$CURDIR/$(basename $i)" "$i"
  42. else
  43. echo "$i" already overriden
  44. fi
  45. done
  46. source /etc/bash.bashrc
  47. # shellcheck disable=SC1091
  48. source "$CURDIR/lib/functions.sh"
  49. idem_apt_install "${REQUIRED_PKGS[@]}"
  50. fi
  51. }
  52. function install_containers() {
  53. echo "install containers"
  54. echo --------------------
  55. # install inside active LXC containers
  56. if [[ -f '/snap/bin/lxc' ]]; then
  57. for container in $(/snap/bin/lxc list --format=json | yq '.[] | select(.state.status == "Running") | .name' -); do
  58. install_one_container $container
  59. echo
  60. done
  61. fi
  62. }
  63. function install_one_container() {
  64. CT=$1
  65. echo "install container <$CT>"
  66. echo -------------------------
  67. # install inside one active LXC container
  68. if [[ -f '/snap/bin/lxc' ]]; then
  69. echo "pushed to $CT"
  70. /snap/bin/lxc file push /opt/debian-bash "${CT}/opt/" -r
  71. /snap/bin/lxc exec "$CT" -- sh -c "cd /opt/debian-bash && ./install.sh --host"
  72. fi
  73. }
  74. PARAM1=$1
  75. case $PARAM1 in
  76. "--host")
  77. install_host
  78. ;;
  79. "--containers")
  80. install_containers
  81. ;;
  82. "--one-container")
  83. CT=$2
  84. if [ ! -z $CT ]; then
  85. install_one_container $CT
  86. else
  87. usage
  88. fi
  89. ;;
  90. "--full")
  91. install_host
  92. install_containers
  93. ;;
  94. *)
  95. usage
  96. ;;
  97. esac