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
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. # shellcheck disable=SC1091
  4. REQUIRED_PKGS=(jq rsync file git)
  5. function usage() {
  6. echo 'usage: --host | --containers | --full | --one-container <CT_NAME>'
  7. exit -1
  8. }
  9. function install_host() {
  10. echo "install on: $HOSTNAME"
  11. echo ----------------------
  12. [ $(id -u) -ne 0 ] && echo 'root privilege required' && exit 1
  13. # shellcheck disable=SC1091
  14. source "$CURDIR/lib/functions.sh"
  15. idem_apt_install "${REQUIRED_PKGS[@]}"
  16. if [[ ! $CURDIR == '/opt/debian-bash' ]]; then
  17. # download and filfull /opt/debian-bash, then run it from folder
  18. if [[ -L /opt/debian-bash ]]; then
  19. cd /opt/debian-bash && ./install.sh "$PARAM1"
  20. exit 0
  21. else
  22. rm -rf /opt/debian-bash
  23. TEMP=$(mktemp -d)
  24. cd $TEMP
  25. echo $TEMP
  26. wget https://git.artcode.re/pvincent/debian-bash/archive/master.tar.gz
  27. tar -xzf master.tar.gz
  28. mv debian-bash /opt/
  29. cd /opt/debian-bash
  30. ./install.sh $PARAM1
  31. rm -rf $TEMP
  32. exit 0
  33. fi
  34. else
  35. #remove /etc/skel/.bashrc
  36. if [ -e /etc/skel/.bashrc ]; then
  37. rm /etc/skel/.bashrc
  38. fi
  39. ORIGINAL="ORIGINAL"
  40. declare -a arr=(/etc/bash.bashrc /etc/inputrc /etc/vim/vimrc)
  41. for i in "${arr[@]}"; do
  42. if [ ! -f "$i.$ORIGINAL" ]; then
  43. echo "$i needs installation $(basename $i)"
  44. mv "$i" "$i.$ORIGINAL"
  45. ln -s "$CURDIR/$(basename $i)" "$i"
  46. else
  47. echo "$i" already overriden
  48. fi
  49. done
  50. source /etc/bash.bashrc
  51. fi
  52. }
  53. function install_containers() {
  54. echo "install containers"
  55. echo --------------------
  56. # install inside active LXC containers
  57. if [[ -f '/snap/bin/lxc' ]]; then
  58. for container in $(/snap/bin/lxc list --format=json | /bin/jq -r '.[] | select(.state.status == "Running") | .name'); do
  59. install_one_container $container
  60. echo
  61. done
  62. fi
  63. }
  64. function install_one_container() {
  65. CT=$1
  66. echo "install container <$CT>"
  67. echo -------------------------
  68. # install inside one active LXC container
  69. if [[ -f '/snap/bin/lxc' ]]; then
  70. echo "pushed to $CT"
  71. /snap/bin/lxc file push /opt/debian-bash "${CT}/opt/" -r
  72. /snap/bin/lxc exec "$CT" -- sh -c "cd /opt/debian-bash && ./install.sh --host"
  73. fi
  74. }
  75. PARAM1=$1
  76. case $PARAM1 in
  77. "--host")
  78. install_host
  79. ;;
  80. "--containers")
  81. install_containers
  82. ;;
  83. "--one-container")
  84. CT=$2
  85. if [ ! -z $CT ]; then
  86. install_one_container $CT
  87. else
  88. usage
  89. fi
  90. ;;
  91. "--full")
  92. install_host
  93. install_containers
  94. ;;
  95. *)
  96. usage
  97. ;;
  98. esac