_addUserSite.sh 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. #!/bin/sh
  2. # bachir soussi chiadmi
  3. # TODO check if root
  4. echo '\033[35m
  5. __ _______ __________
  6. / / / / ___// ____/ __ \
  7. / / / /\__ \/ __/ / /_/ /
  8. / /_/ /___/ / /___/ _, _/
  9. \____//____/_____/_/ |_|
  10. \033[0m'
  11. echo "\033[35;1mCreate new user (you will be asked a user name and a password) \033[0m"
  12. sleep 3
  13. while [ "$user" = "" ]
  14. do
  15. read -p "Enter user name: " user
  16. if [ "$user" != "" ]; then
  17. read -p "is user $user correcte [y|n] " validated
  18. if [ "$validated" = "y" ]; then
  19. break
  20. else
  21. user=""
  22. fi
  23. fi
  24. done
  25. adduser "$user"
  26. mkdir /home/$user/logs
  27. mkdir /home/$user/public_html
  28. mkdir /home/$user/backups
  29. chmod -w /home/"$user"
  30. echo '\033[35m
  31. __ __
  32. _ __/ /_ ____ _____/ /_
  33. | | / / __ \/ __ \/ ___/ __/
  34. | |/ / / / / /_/ (__ ) /_
  35. |___/_/ /_/\____/____/\__/
  36. \033[0m'
  37. echo "\033[35;1mVHOST install \033[0m"
  38. while [ "$_host_name" = "" ]
  39. do
  40. read -p "enter a hostname ? " _host_name
  41. if [ "$_host_name" != "" ]; then
  42. read -p "is hostname $_host_name correcte [y|n] " validated
  43. if [ "$validated" = "y" ]; then
  44. break
  45. else
  46. _host_name=""
  47. fi
  48. fi
  49. done
  50. #set proper right to user will handle the app
  51. chown -R "$user":admin /home/"$user"/public_html
  52. chown -R "$user":admin /home/"$user"/logs
  53. chown -R "$user":admin /home/"$user"/backups
  54. chmod -R g+wr /home/"$user"/public_html
  55. chmod -R g+wr /home/"$user"/logs
  56. mkdir -p /var/www/"$_host_name"
  57. ln -s /home/"$user"/public_html /var/www/"$_host_name"/public_html
  58. ln -s /home/"$user"/logs /var/www/"$_host_name"/logs
  59. # TODO create nginx vhost
  60. # cp "$_cwd"/assets/example.org.conf /etc/apache2/sites-available/"$_host_name".conf
  61. # sed -i -r "s/example\.org/$_host_name/g" /etc/apache2/sites-available/"$_host_name".conf
  62. #activate the vhost
  63. # a2ensite "$_host_name".conf
  64. #restart apache
  65. # service apache2 restart
  66. echo "\033[92;1mvhost $_host_name configured\033[Om"
  67. # todo add mysql user and database
  68. echo '\033[35m
  69. __ ___ __
  70. / |/ /_ ___________ _/ /
  71. / /|_/ / / / / ___/ __ `/ /
  72. / / / / /_/ (__ ) /_/ / /
  73. /_/ /_/\__, /____/\__, /_/
  74. /____/ /_/
  75. \033[0m'
  76. echo "\033[35;1mMysql database \033[0m"
  77. while [ "$_dbname" = "" ]
  78. do
  79. read -p "enter a database name ? " _dbname
  80. if [ "$_dbname" != "" ]; then
  81. read -p "is database name $_dbname correcte [y|n] " validated
  82. if [ "$validated" = "y" ]; then
  83. break
  84. else
  85. _dbname=""
  86. fi
  87. fi
  88. done
  89. passok=0
  90. while [ "$passok" = "0" ]
  91. do
  92. echo -n "Write database password for $user"
  93. read passwda
  94. echo -n "confirm password"
  95. read passwdb
  96. if [ "$passwda" = "$passwdb" ]; then
  97. $_pswd=$passwda
  98. passok=1
  99. else
  100. echo "pass words don't match, please try again"
  101. fi
  102. done
  103. if [ "$passok" = 1 ]; then
  104. # mysql> create user '$_dbname'@'localhost' identified by '$_pswd';
  105. # mysql> create database $_dbname;
  106. # mysql> grant all privileges on esadhar_eval.* to 'esadhar_eval'@'localhost';
  107. # mysql> flush privileges;
  108. fi