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.

112 lines
2.6 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
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 "pushed to $container"
  52. # /snap/bin/lxc file push /opt/debian-bash "${container}/opt/" -r
  53. # /snap/bin/lxc exec "$container" -- sh -c "cd /opt/debian-bash && ./install.sh --host"
  54. # echo
  55. done
  56. fi
  57. }
  58. function install_one_container {
  59. CT=$1
  60. echo "install container <$CT>"
  61. echo -------------------------
  62. # install inside one active LXC container
  63. if [[ -f '/snap/bin/lxc' ]]; then
  64. echo "pushed to $CT"
  65. /snap/bin/lxc file push /opt/debian-bash "${CT}/opt/" -r
  66. /snap/bin/lxc exec "$CT" -- sh -c "cd /opt/debian-bash && ./install.sh --host"
  67. fi
  68. }
  69. PARAM1=$1
  70. case $PARAM1 in
  71. "--host")
  72. install_host
  73. ;;
  74. "--containers")
  75. install_containers
  76. ;;
  77. "--one-container")
  78. CT=$2
  79. if [ ! -z $CT ]; then
  80. install_one_container $CT
  81. else
  82. usage
  83. fi
  84. ;;
  85. "--full")
  86. install_host
  87. install_containers
  88. ;;
  89. *)
  90. usage
  91. ;;
  92. esac