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.

109 lines
2.4 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 host"
  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. rm -rf /opt/debian-bash
  14. TEMP=`mktemp -d`
  15. cd $TEMP
  16. echo $TEMP
  17. wget https://git.artcode.re/pvincent/debian-bash/archive/master.tar.gz
  18. tar -xzf master.tar.gz
  19. mv debian-bash /opt/
  20. cd /opt/debian-bash
  21. ./install.sh $PARAM1
  22. rm -rf $TEMP
  23. exit 0
  24. else
  25. #remove /etc/skel/.bashrc
  26. if [ -e /etc/skel/.bashrc ]; then
  27. rm /etc/skel/.bashrc
  28. fi
  29. ORIGINAL="ORIGINAL"
  30. declare -a arr=(/etc/bash.bashrc /etc/inputrc /etc/vim/vimrc)
  31. for i in "${arr[@]}"
  32. do
  33. if [ ! -f "$i.$ORIGINAL" ]; then
  34. echo "$i needs installation $(basename $i)"
  35. mv "$i" "$i.$ORIGINAL"
  36. ln -s "$BASEDIR/$(basename $i)" "$i"
  37. else
  38. echo "$i" already overriden
  39. fi
  40. done
  41. source /etc/bash.bashrc
  42. fi
  43. }
  44. function install_containers {
  45. echo "install containers"
  46. echo --------------------
  47. # install inside active LXC containers
  48. if [[ -f '/snap/bin/lxc' ]]; then
  49. for container in `/snap/bin/lxc list -c n --format csv`; do
  50. install_one_container $container
  51. echo
  52. done
  53. fi
  54. }
  55. function install_one_container {
  56. CT=$1
  57. echo "install container <$CT>"
  58. echo -------------------------
  59. # install inside one active LXC container
  60. if [[ -f '/snap/bin/lxc' ]]; then
  61. echo "pushed to $CT"
  62. /snap/bin/lxc file push /opt/debian-bash "${CT}/opt/" -r
  63. /snap/bin/lxc exec "$CT" -- sh -c "cd /opt/debian-bash && ./install.sh --host"
  64. fi
  65. }
  66. PARAM1=$1
  67. case $PARAM1 in
  68. "--host")
  69. install_host
  70. ;;
  71. "--containers")
  72. install_containers
  73. ;;
  74. "--one-container")
  75. CT=$2
  76. if [ ! -z $CT ]; then
  77. install_one_container $CT
  78. else
  79. usage
  80. fi
  81. ;;
  82. "--full")
  83. install_host
  84. install_containers
  85. ;;
  86. *)
  87. usage
  88. ;;
  89. esac