install.sh 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. #!/bin/bash
  2. # Config
  3. ENVIROMENT="prod";
  4. TMP="/tmp/omni-setup";
  5. if [[ "$1" != "" ]];then
  6. ENVIROMENT="$1";
  7. fi;
  8. REGISTER_URL="http://api.omnimaga.org/register/$ENVIROMENT";
  9. PHPMYADMIN_URL="http://downloads.sourceforge.net/project/phpmyadmin/phpMyAdmin/4.2.9/phpMyAdmin-4.2.9-english.tar.xz";
  10. # Functions for logging
  11. section(){
  12. echo "=> Starting Section \"$@\"";
  13. }
  14. log(){
  15. echo "|-> $@";
  16. }
  17. sublog(){
  18. echo "|--> $@";
  19. }
  20. info(){
  21. echo "|-> INFO: $@";
  22. }
  23. subinfo(){
  24. echo "|--> INFO $@";
  25. }
  26. install(){
  27. apt-get -qq install $@;
  28. }
  29. updatesudo(){
  30. if visudo -q -c -fdata/etc/$@;then
  31. cp data/etc/$@ /etc/$@;
  32. fi;
  33. }
  34. # Make sure the script is running as root
  35. if [ "$(id -u)" != "0" ]; then
  36. sudo $0;
  37. exit;
  38. fi;
  39. # Actually run the install
  40. section "Registering";
  41. log "Getting IDs";
  42. mkdir -p /tmp/omni-setup;
  43. sublog "Hostname";
  44. wget -q "$REGISTER_URL/hostname" -O $TMP/hostname;
  45. if [[ "$(cat $TMP/hostname)" == "" ]];then
  46. hostname > $TMP/hostname;
  47. fi;
  48. hostname $(cat $TMP/hostname);
  49. cp $TMP/hostname /etc/hostname;
  50. sublog "MySQL ID";
  51. wget -q "$REGISTER_URL/mysql-id" -O $TMP/mysql-id;
  52. section "Package Installation";
  53. log "LAMP Stack";
  54. install lamp-server^;
  55. log "Node.js"
  56. install nodejs;
  57. log "SSH Server";
  58. install ssh;
  59. log "Git";
  60. install git;
  61. log "htop";
  62. install htop;
  63. section "Custom Packages";
  64. log "Omnimaga-Server-Utils";
  65. sublog "Creating directories";
  66. mkdir /opt/omnimaga/bin -p;
  67. chown root:users /opt/omnimaga/bin;
  68. sublog "Adding to path";
  69. echo "export PATH=$PATH:/opt/omnimaga/bin;" > /etc/profile.d/omnimaga-server-utils.sh;
  70. . /etc/profile.d/omnimaga-server-utils.sh;
  71. sublog "getting files";
  72. rm -rf /opt/omnimaga/bin;
  73. git clone -q https://github.com/Omnimaga/server-utils.git /opt/omnimaga/bin/;
  74. chmod a+x /opt/omnimaga/bin/*;
  75. subinfo "Add users to the group omnimaga-utils to allow access";
  76. log "phpmyadmin";
  77. sublog "Downloading";
  78. wget -q $PHPMYADMIN_URL -O $TMP/pma.tar.xz;
  79. sublog "Extracting";
  80. tar -C $TMP/ -xf $TMP/pma.tar.xz;
  81. sublog "Copying";
  82. mkdir -p /var/www/phpmyadmin/;
  83. cp -R $TMP/phpMyAdmin-*/{*,.[a-zA-Z0-9]*} /var/www/phpmyadmin/;
  84. cp data/var/www/phpmyadmin/config.inc.php /var/www/phpmyadmin/;
  85. section "Config";
  86. log "Setting up sudoers";
  87. updatesudo sudoers;
  88. log "Setting up groups";
  89. sublog "web";
  90. groupadd -f web;
  91. updatesudo sudoers.d/web;
  92. sublog "ircd";
  93. groupadd -f ircd;
  94. updatesudo sudoers.d/ircd;
  95. sublog "mysqld";
  96. cp data/etc/mysql/conf.d/replication.cnf /etc/mysql/conf.d/replication.cnf;