install.sh 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  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. cp -R $TMP/phpMyAdmin-*/{*,.[a-zA-Z0-9]*} /var/www/phpmyadmin/;
  128. cp data/var/www/phpmyadmin/config.inc.php /var/www/phpmyadmin/;
  129. chown www-data:www-data /var/www/phpmyadmin -R;
  130. log "unrealircd";
  131. download $UNREALIRCD_URL $TMP/unreal.tar.gz;
  132. adduser --system --no-create-home ircd;
  133. mkdir -p /opt/unrealircd;
  134. tar -C $TMP/ -xf $TMP/unreal.tar.gz
  135. cp -R $TMP/Unreal*/{*,.[a-zA-Z0-9]*} /opt/unrealircd;
  136. cp data/opt/unrealircd/config.settings /opt/unrealircd;
  137. pushd;
  138. cd /opt/unrealircd;
  139. ./Config -quick -nointro;
  140. make;
  141. popd;
  142. section "Config";
  143. log "Sudoers";
  144. updatesudo sudoers;
  145. log "Groups";
  146. sublog "web";
  147. groupadd -f web;
  148. updatesudo sudoers.d/web;
  149. sublog "ircd";
  150. groupadd -f ircd;
  151. updatesudo sudoers.d/ircd;
  152. log "Services";
  153. sublog "mysqld";
  154. cp data/etc/mysql/conf.d/replication.cnf /etc/mysql/conf.d/replication.cnf;
  155. service mysql reload;
  156. sublog "apache2";
  157. a2enmod -q vhost_alias;
  158. a2enmod -q rewrite;
  159. site omnimaga;
  160. site pma;
  161. sed -i "s/__SERVER_HOSTNAME__/$(cat $TMP/hostname)/" /etc/apache2/sites-available/pma.conf;
  162. service apache2 reload;
  163. log "Core";
  164. sublog "shell";
  165. cp data/etc/adduser.conf /etc/adduser.conf;
  166. cp data/etc/default/useradd /etc/default/useradd;
  167. 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
  168. chsh -s /bin/zsh $user;
  169. info "Changed shell for $user";
  170. done;
  171. sublog "hosts";
  172. host omnimaga.org;
  173. host www.omnimaga.org;
  174. host $(hostname).omnimaga.org;
  175. host pma.$(hostname).omnimaga.org;
  176. echo -e $HOSTS > /etc/hosts;
  177. sublog "phpmyadmin";
  178. echo -n "root@localhost mysql pass:";
  179. read -s pass;
  180. cat /var/www/phpmyadmin/examples/create_tables.sql | mysql -u root -p"$pass";
  181. echo -e "\n\n\n";
  182. echo "Install Finished";