install.sh 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  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 "Prep";
  73. TMP="$TMP/temp/";
  74. mkdir -p $TMP;
  75. rm -rf $TMP/*;
  76. section "Registering";
  77. log "Getting IDs";
  78. sublog "Hostname";
  79. download "$REGISTER_URL/hostname" $TMP/hostname;
  80. if [[ "$(cat $TMP/hostname)" == "" ]];then
  81. hostname > $TMP/hostname;
  82. fi;
  83. download "$REGISTER_URL/replication_id" $TMP/replication_id;
  84. if [[ "$(cat $TMP/replication_id)" == "" ]];then
  85. echo 1 > $TMP/replication_id;
  86. fi;
  87. hostname $(cat $TMP/hostname);
  88. 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";
  89. cp $TMP/hostname /etc/hostname;
  90. sublog "MySQL ID";
  91. download "$REGISTER_URL/mysql-id" $TMP/mysql-id;
  92. section "Package Installation";
  93. log "LAMP Stack";
  94. install lamp-server^;
  95. log "Node.js"
  96. install nodejs;
  97. log "SSH Server";
  98. install ssh;
  99. log "Git";
  100. install git;
  101. log "htop";
  102. install htop;
  103. log "zsh";
  104. install zsh;
  105. log "openssl";
  106. install openssl;
  107. log "build tools";
  108. install build-essential;
  109. install libcurl4-openssl-dev;
  110. section "Custom Packages";
  111. log "Omnimaga-Server-Utils";
  112. sublog "Creating directories";
  113. mkdir /opt/omnimaga/bin -p;
  114. chown root:users /opt/omnimaga/bin;
  115. sublog "Adding to path";
  116. echo "export PATH=$PATH:/opt/omnimaga/bin;" > /etc/profile.d/omnimaga-server-utils.sh;
  117. . /etc/profile.d/omnimaga-server-utils.sh;
  118. sublog "getting files";
  119. rm -rf /opt/omnimaga/bin;
  120. clone https://github.com/Omnimaga/server-utils.git /opt/omnimaga/bin/;
  121. chmod a+x /opt/omnimaga/bin/*;
  122. subinfo "Add users to the group omnimaga-utils to allow access";
  123. log "phpmyadmin";
  124. sublog "Downloading";
  125. download $PHPMYADMIN_URL $TMP/pma.tar.xz;
  126. sublog "Extracting";
  127. tar -C $TMP/ -xf $TMP/pma.tar.xz;
  128. sublog "Copying";
  129. rm -rf /var/www/phpmyadmin/;
  130. mkdir -p /var/www/phpmyadmin/;
  131. cp -R $TMP/phpMyAdmin-*/{*,.[a-zA-Z0-9]*} /var/www/phpmyadmin/;
  132. cp data/var/www/phpmyadmin/config.inc.php /var/www/phpmyadmin/;
  133. chown www-data:www-data /var/www/phpmyadmin -R;
  134. log "unrealircd";
  135. download $UNREALIRCD_URL $TMP/unreal.tar.gz;
  136. adduser --system --no-create-home ircd;
  137. rm -rf /opt/unrealircd/;
  138. mkdir -p /opt/unrealircd;
  139. tar -C $TMP/ -xf $TMP/unreal.tar.gz
  140. cp -R $TMP/Unreal*/{*,.[a-zA-Z0-9]*} /opt/unrealircd;
  141. cp data/opt/unrealircd/config.settings /opt/unrealircd;
  142. pushd $(pwd);
  143. cd /opt/unrealircd;
  144. ./curlinstall;
  145. ./Config -quick -nointro;
  146. make;
  147. popd;
  148. section "Config";
  149. log "Sudoers";
  150. updatesudo sudoers;
  151. log "Groups";
  152. sublog "web";
  153. groupadd -f web;
  154. updatesudo sudoers.d/web;
  155. sublog "ircd";
  156. groupadd -f ircd;
  157. updatesudo sudoers.d/ircd;
  158. sublog "admin";
  159. groupadd -f admin;
  160. log "Services";
  161. sublog "mysqld";
  162. cp data/etc/mysql/conf.d/replication.cnf /etc/mysql/conf.d/replication.cnf;
  163. service mysql reload;
  164. sublog "apache2";
  165. a2enmod -q vhost_alias;
  166. a2enmod -q rewrite;
  167. site omnimaga;
  168. site pma;
  169. sed -i "s/__SERVER_HOSTNAME__/$(cat $TMP/hostname)/" /etc/apache2/sites-available/pma.conf;
  170. service apache2 reload;
  171. log "Core";
  172. sublog "shell";
  173. cp data/etc/adduser.conf /etc/adduser.conf;
  174. cp data/etc/default/useradd /etc/default/useradd;
  175. 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
  176. chsh -s /bin/zsh $user;
  177. info "Changed shell for $user";
  178. done;
  179. sublog "hosts";
  180. host omnimaga.org;
  181. host www.omnimaga.org;
  182. host $(hostname).omnimaga.org;
  183. host pma.$(hostname).omnimaga.org;
  184. echo -e $HOSTS > /etc/hosts;
  185. sublog "phpmyadmin";
  186. echo -n "root@localhost mysql pass:";
  187. read -s pass;
  188. cat /var/www/phpmyadmin/examples/create_tables.sql | mysql -u root -p"$pass";
  189. echo -e "\n\n\n";
  190. echo "Install Finished";