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.

122 lines
2.7 KiB

5 years ago
5 years ago
5 years ago
5 years ago
4 years ago
4 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. dpkg-query --status jq
  14. [ $? -ne 0 ] && sudo apt install -y jq
  15. if [[ ! $BASEDIR == '/opt/debian-bash' ]]; then
  16. # download and filfull /opt/debian-bash, then run it from folder
  17. if [[ -L /opt/debian-bash ]];then
  18. cd /opt/debian-bash
  19. ./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[@]}"
  42. do
  43. if [ ! -f "$i.$ORIGINAL" ]; then
  44. echo "$i needs installation $(basename $i)"
  45. mv "$i" "$i.$ORIGINAL"
  46. ln -s "$BASEDIR/$(basename $i)" "$i"
  47. else
  48. echo "$i" already overriden
  49. fi
  50. done
  51. source /etc/bash.bashrc
  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