install.sh 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  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.1-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. download "$REGISTER_URL/replication_id" $TMP/replication_id;
  80. if [[ "$(cat $TMP/replication_id)" == "" ]];then
  81. echo 1 > $TMP/replication_id;
  82. fi;
  83. hostname $(cat $TMP/hostname);
  84. 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";
  85. cp $TMP/hostname /etc/hostname;
  86. sublog "MySQL ID";
  87. download "$REGISTER_URL/mysql-id" $TMP/mysql-id;
  88. section "Package Installation";
  89. log "LAMP Stack";
  90. install lamp-server^;
  91. log "Node.js"
  92. install nodejs;
  93. log "SSH Server";
  94. install ssh;
  95. log "Git";
  96. install git;
  97. log "htop";
  98. install htop;
  99. log "zsh";
  100. install zsh;
  101. section "Custom Packages";
  102. log "Omnimaga-Server-Utils";
  103. sublog "Creating directories";
  104. mkdir /opt/omnimaga/bin -p;
  105. chown root:users /opt/omnimaga/bin;
  106. sublog "Adding to path";
  107. echo "export PATH=$PATH:/opt/omnimaga/bin;" > /etc/profile.d/omnimaga-server-utils.sh;
  108. . /etc/profile.d/omnimaga-server-utils.sh;
  109. sublog "getting files";
  110. rm -rf /opt/omnimaga/bin;
  111. clone https://github.com/Omnimaga/server-utils.git /opt/omnimaga/bin/;
  112. chmod a+x /opt/omnimaga/bin/*;
  113. subinfo "Add users to the group omnimaga-utils to allow access";
  114. log "phpmyadmin";
  115. sublog "Downloading";
  116. download $PHPMYADMIN_URL $TMP/pma.tar.xz;
  117. sublog "Extracting";
  118. tar -C $TMP/ -xf $TMP/pma.tar.xz;
  119. sublog "Copying";
  120. mkdir -p /var/www/phpmyadmin/;
  121. cp -R $TMP/phpMyAdmin-*/{*,.[a-zA-Z0-9]*} /var/www/phpmyadmin/;
  122. cp data/var/www/phpmyadmin/config.inc.php /var/www/phpmyadmin/;
  123. chown www-data:www-data /var/www/phpmyadmin -R;
  124. log "omnimaga";
  125. section "Config";
  126. log "Sudoers";
  127. updatesudo sudoers;
  128. log "Groups";
  129. sublog "web";
  130. groupadd -f web;
  131. updatesudo sudoers.d/web;
  132. sublog "ircd";
  133. groupadd -f ircd;
  134. updatesudo sudoers.d/ircd;
  135. log "Services";
  136. sublog "mysqld";
  137. cp data/etc/mysql/conf.d/replication.cnf /etc/mysql/conf.d/replication.cnf;
  138. service mysql reload;
  139. sublog "apache2";
  140. a2enmod -q vhost_alias;
  141. a2enmod -q rewrite;
  142. site omnimaga;
  143. site pma;
  144. sed -i "s/__SERVER_HOSTNAME__/$(cat $TMP/hostname)/" /etc/apache2/sites-available/pma.conf;
  145. service apache2 reload;
  146. log "Core";
  147. sublog "shell";
  148. cp data/etc/adduser.conf /etc/adduser.conf;
  149. cp data/etc/default/useradd /etc/default/useradd;
  150. 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
  151. chsh -s /bin/zsh $user;
  152. info "Changed shell for $user";
  153. done;
  154. sublog "hosts";
  155. host omnimaga.org;
  156. host www.omnimaga.org;
  157. host pma.omnimaga.org;
  158. echo -e $HOSTS > /etc/hosts;
  159. sublog "phpmyadmin";
  160. echo -n "root@localhost mysql pass:";
  161. read -s pass;
  162. cat /var/www/phpmyadmin/examples/create_tables.sql | mysql -u root -p"$pass";