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.

126 lines
2.9 KiB

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