install.sh 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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. # section <message>
  13. echo "=> Starting Section \"$@\"";
  14. }
  15. log(){
  16. # log <message>
  17. echo "|-> $@";
  18. }
  19. sublog(){
  20. # sublog <message>
  21. echo "|--> $@";
  22. }
  23. info(){
  24. # info <message>
  25. echo "|-> INFO: $@";
  26. }
  27. subinfo(){
  28. # subinfo <message>
  29. echo "|--> INFO $@";
  30. }
  31. install(){
  32. # install <packages>
  33. apt-get -qq install $@;
  34. }
  35. updatesudo(){
  36. # updatesudo <path>
  37. if visudo -q -c -fdata/etc/$1;then
  38. cp data/etc/$1 /etc/$1;
  39. fi;
  40. }
  41. site(){
  42. # site <site>
  43. cp data/etc/apache2/sites-available/$1.conf /etc/apache2/sites-available/$1.conf;
  44. a2ensite $1;
  45. }
  46. host(){
  47. # host <host> [<ip>]
  48. local ip=$2;
  49. if [[ "$ip" == "" ]];then
  50. ip="127.0.0.1";
  51. fi;
  52. HOSTS=$HOSTS"$ip\t$1\n";
  53. }
  54. download(){
  55. local url=$1;
  56. local path=$2;
  57. echo -n " ";
  58. wget --progress=dot $url -O $path 2>&1 | grep --line-buffered "%" | sed -u -e "s,\.,,g" | awk '{printf("\b\b\b\b%4s", $2)}';
  59. echo -ne "\b\b\b\b";
  60. }
  61. clone(){
  62. git clone -q $1 $2;
  63. }
  64. # Make sure the script is running as root
  65. if [ "$(id -u)" != "0" ];then
  66. echo "Running with sudo";
  67. sudo $0;
  68. exit;
  69. fi;
  70. # Actually run the install
  71. section "Registering";
  72. log "Getting IDs";
  73. mkdir -p /tmp/omni-setup;
  74. sublog "Hostname";
  75. download "$REGISTER_URL/hostname" $TMP/hostname;
  76. if [[ "$(cat $TMP/hostname)" == "" ]];then
  77. hostname > $TMP/hostname;
  78. fi;
  79. hostname $(cat $TMP/hostname);
  80. HOSTS="127.0.0.1\tlocalhost\n127.0.0.1\t$(hostname)\n::1\t\tlocalhost ip6-localhost ip6-loopback\nff02::1\t\tip6-allnodes\nff02::2\t\tip6-allrouters\n";
  81. cp $TMP/hostname /etc/hostname;
  82. sublog "MySQL ID";
  83. download "$REGISTER_URL/mysql-id" $TMP/mysql-id;
  84. section "Package Installation";
  85. log "LAMP Stack";
  86. install lamp-server^;
  87. log "Node.js"
  88. install nodejs;
  89. log "SSH Server";
  90. install ssh;
  91. log "Git";
  92. install git;
  93. log "htop";
  94. install htop;
  95. log "zsh";
  96. install zsh;
  97. section "Custom Packages";
  98. log "Omnimaga-Server-Utils";
  99. sublog "Creating directories";
  100. mkdir /opt/omnimaga/bin -p;
  101. chown root:users /opt/omnimaga/bin;
  102. sublog "Adding to path";
  103. echo "export PATH=$PATH:/opt/omnimaga/bin;" > /etc/profile.d/omnimaga-server-utils.sh;
  104. . /etc/profile.d/omnimaga-server-utils.sh;
  105. sublog "getting files";
  106. rm -rf /opt/omnimaga/bin;
  107. clone https://github.com/Omnimaga/server-utils.git /opt/omnimaga/bin/;
  108. chmod a+x /opt/omnimaga/bin/*;
  109. subinfo "Add users to the group omnimaga-utils to allow access";
  110. log "phpmyadmin";
  111. sublog "Downloading";
  112. download $PHPMYADMIN_URL $TMP/pma.tar.xz;
  113. sublog "Extracting";
  114. tar -C $TMP/ -xf $TMP/pma.tar.xz;
  115. sublog "Copying";
  116. mkdir -p /var/www/phpmyadmin/;
  117. cp -R $TMP/phpMyAdmin-*/{*,.[a-zA-Z0-9]*} /var/www/phpmyadmin/;
  118. cp data/var/www/phpmyadmin/config.inc.php /var/www/phpmyadmin/;
  119. chown www-data:www-data /var/www/phpmyadmin -R;
  120. log "omnimaga";
  121. section "Config";
  122. log "Sudoers";
  123. updatesudo sudoers;
  124. log "Groups";
  125. sublog "web";
  126. groupadd -f web;
  127. updatesudo sudoers.d/web;
  128. sublog "ircd";
  129. groupadd -f ircd;
  130. updatesudo sudoers.d/ircd;
  131. log "Services";
  132. sublog "mysqld";
  133. cp data/etc/mysql/conf.d/replication.cnf /etc/mysql/conf.d/replication.cnf;
  134. service mysql reload;
  135. sublog "apache2";
  136. a2enmod -q vhost_alias;
  137. a2enmod -q rewrite;
  138. site omnimaga;
  139. site pma;
  140. service apache2 reload;
  141. log "Core";
  142. sublog "shell";
  143. cp data/etc/adduser.conf /etc/adduser.conf;
  144. cp data/etc/default/useradd /etc/default/useradd;
  145. grep -v nologin /etc/passwd | grep -v /bin/false | grep -v /bin/sync | grep -v /var/lib/libuuid | cut -d : -f 1 | while read user;do
  146. chsh -s /bin/zsh $user;
  147. info "Changed shell for $user";
  148. done;
  149. sublog "hosts";
  150. host omnimaga.org;
  151. host www.omnimaga.org;
  152. host pma.omnimaga.org;
  153. echo -e $HOSTS > /etc/hosts;
  154. sublog "phpmyadmin";
  155. echo -n "root@localhost mysql pass:";
  156. read -s pass;
  157. cat /var/www/phpmyadmin/examples/create_tables.sql | mysql -u root -p "$pass";