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.

118 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. if [[ ! $CURDIR == '/opt/debian-bash' ]]; then
  14. # download and filfull /opt/debian-bash, then run it from folder
  15. if [[ -L /opt/debian-bash ]]; then
  16. cd /opt/debian-bash && ./install.sh "$PARAM1"
  17. exit 0
  18. else
  19. rm -rf /opt/debian-bash
  20. TEMP=$(mktemp -d)
  21. cd $TEMP
  22. echo $TEMP
  23. wget https://git.artcode.re/pvincent/debian-bash/archive/master.tar.gz
  24. tar -xzf master.tar.gz
  25. mv debian-bash /opt/
  26. cd /opt/debian-bash
  27. ./install.sh $PARAM1
  28. rm -rf $TEMP
  29. exit 0
  30. fi
  31. else
  32. #remove /etc/skel/.bashrc
  33. if [ -e /etc/skel/.bashrc ]; then
  34. rm /etc/skel/.bashrc
  35. fi
  36. ORIGINAL="ORIGINAL"
  37. declare -a arr=(/etc/bash.bashrc /etc/inputrc /etc/vim/vimrc)
  38. for i in "${arr[@]}"; do
  39. if [ ! -f "$i.$ORIGINAL" ]; then
  40. echo "$i needs installation $(basename $i)"
  41. mv "$i" "$i.$ORIGINAL"
  42. ln -s "$CURDIR/$(basename $i)" "$i"
  43. else
  44. echo "$i" already overriden
  45. fi
  46. done
  47. source /etc/bash.bashrc
  48. # shellcheck disable=SC1091
  49. source "$CURDIR/lib/functions.sh"
  50. idem_apt_install "${REQUIRED_PKGS[@]}"
  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