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.

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