install.sh 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. #!/bin/bash
  2. # Config
  3. ENVIROMENT="dev";
  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. rm -f $2;
  60. wget --progress=dot $url -O $path 2>&1 | grep --line-buffered "%" | sed -u -e "s,\.,,g" | awk '{printf("\b\b\b\b%4s", $2)}';
  61. echo -ne "\b\b\b\b";
  62. }
  63. clone(){
  64. git clone -q $1 $2;
  65. }
  66. # Make sure the script is running as root
  67. if [ "$(id -u)" != "0" ];then
  68. echo "Running with sudo";
  69. sudo $0;
  70. exit;
  71. fi;
  72. # Actually run the install
  73. section "Prep";
  74. TMP="$TMP/temp/";
  75. mkdir -p $TMP;
  76. rm -rf $TMP/*;
  77. section "Registering";
  78. log "Getting IDs";
  79. sublog "Hostname";
  80. download "$REGISTER_URL/hostname" $TMP/hostname;
  81. if [[ "$(cat $TMP/hostname)" == "" ]];then
  82. download "$REGISTER_URL/name/$(hostname)" $TMP/hostname;
  83. if [[ "$(cat $TMP/hostname)" == "" ]];then
  84. hostname > $TMP/hostname;
  85. fi;
  86. fi;
  87. info "HOSTNAME SET TO $(cat $TMP/hostname)";
  88. download "$REGISTER_URL/replication_id" $TMP/replication_id;
  89. info "REPLICATION ID SET TO $(cat $TMP/replication_id)";
  90. hostname $(cat $TMP/hostname);
  91. 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";
  92. cp $TMP/hostname /etc/hostname;
  93. section "Package Installation";
  94. log "LAMP Stack";
  95. install lamp-server^;
  96. log "Node.js"
  97. install nodejs;
  98. log "SSH Server";
  99. install ssh;
  100. log "Git";
  101. install git;
  102. log "htop";
  103. install htop;
  104. log "zsh";
  105. install zsh;
  106. log "openssl";
  107. install openssl;
  108. log "build tools";
  109. install build-essential;
  110. install libcurl4-openssl-dev;
  111. section "Custom Packages";
  112. log "Omnimaga-Server-Utils";
  113. sublog "Creating directories";
  114. mkdir /opt/omnimaga/bin -p;
  115. chown root:users /opt/omnimaga/bin;
  116. sublog "Adding to path";
  117. echo "export PATH=\$PATH:/opt/omnimaga/bin;" > /etc/profile.d/omnimaga-server-utils.sh;
  118. . /etc/profile.d/omnimaga-server-utils.sh;
  119. sublog "getting files";
  120. rm -rf /opt/omnimaga/bin;
  121. clone https://github.com/Omnimaga/server-utils.git /opt/omnimaga/bin/;
  122. chmod a+x /opt/omnimaga/bin/*;
  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. sed -i "s/__SERVER_ID__/$(cat $TMP/replication_id)/" /etc/mysql/conf.d/replication.cnf;
  164. service mysql reload;
  165. sublog "apache2";
  166. a2enmod -q vhost_alias;
  167. a2enmod -q rewrite;
  168. site omnimaga;
  169. site pma;
  170. sed -i "s/__SERVER_HOSTNAME__/$(cat $TMP/hostname)/" /etc/apache2/sites-available/pma.conf;
  171. service apache2 reload;
  172. log "Core";
  173. sublog "shell";
  174. cp data/etc/adduser.conf /etc/adduser.conf;
  175. cp data/etc/default/useradd /etc/default/useradd;
  176. 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
  177. if [[ "$user" != "root" ]];then
  178. chsh -s /bin/zsh $user;
  179. info "Changed shell for $user";
  180. done;
  181. sublog "hosts";
  182. host omnimaga.org;
  183. host www.omnimaga.org;
  184. host $(hostname).omnimaga.org;
  185. host pma.$(hostname).omnimaga.org;
  186. echo -e $HOSTS > /etc/hosts;
  187. sublog "phpmyadmin";
  188. echo -n "root@localhost mysql pass:";
  189. read -s pass;
  190. cat /var/www/phpmyadmin/examples/create_tables.sql | mysql -u root -p"$pass";
  191. echo -e "\n\n\n";
  192. echo "Install Finished";