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.

116 lines
2.5 KiB

5 years ago
5 years ago
5 years ago
4 years ago
4 years ago
4 years ago
5 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. function usage {
  4. echo 'usage: --host | --containers | --full | --one-container <CT_NAME>'
  5. exit -1
  6. }
  7. function install_host {
  8. echo "install on: $HOSTNAME"
  9. echo ----------------------
  10. [ `id -u` -ne 0 ] && echo 'root privilege required' && exit 1
  11. if [[ ! $BASEDIR == '/opt/debian-bash' ]]; then
  12. # download and filfull /opt/debian-bash, then run it from folder
  13. if [[ -L /opt/debian-bash ]];then
  14. cd /opt/debian-bash
  15. git pull
  16. ./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[@]}"
  39. do
  40. if [ ! -f "$i.$ORIGINAL" ]; then
  41. echo "$i needs installation $(basename $i)"
  42. mv "$i" "$i.$ORIGINAL"
  43. ln -s "$BASEDIR/$(basename $i)" "$i"
  44. else
  45. echo "$i" already overriden
  46. fi
  47. done
  48. source /etc/bash.bashrc
  49. fi
  50. }
  51. function install_containers {
  52. echo "install containers"
  53. echo --------------------
  54. # install inside active LXC containers
  55. if [[ -f '/snap/bin/lxc' ]]; then
  56. for container in `/snap/bin/lxc list -c n --format csv`; do
  57. install_one_container $container
  58. echo
  59. done
  60. fi
  61. }
  62. function install_one_container {
  63. CT=$1
  64. echo "install container <$CT>"
  65. echo -------------------------
  66. # install inside one active LXC container
  67. if [[ -f '/snap/bin/lxc' ]]; then
  68. echo "pushed to $CT"
  69. /snap/bin/lxc file push /opt/debian-bash "${CT}/opt/" -r
  70. /snap/bin/lxc exec "$CT" -- sh -c "cd /opt/debian-bash && ./install.sh --host"
  71. fi
  72. }
  73. PARAM1=$1
  74. case $PARAM1 in
  75. "--host")
  76. install_host
  77. ;;
  78. "--containers")
  79. install_containers
  80. ;;
  81. "--one-container")
  82. CT=$2
  83. if [ ! -z $CT ]; then
  84. install_one_container $CT
  85. else
  86. usage
  87. fi
  88. ;;
  89. "--full")
  90. install_host
  91. install_containers
  92. ;;
  93. *)
  94. usage
  95. ;;
  96. esac