install.sh 4.8 KB

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