setup.sh 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. #!/bin/bash
  2. set -e
  3. apt -y upgrade
  4. apt -y install debian-keyring debian-archive-keyring apt-transport-https software-properties-common curl wget gnupg
  5. apt -y install zsh git locales locales-all rsync openssh-client sshpass \
  6. vim tzdata pwgen zip unzip tree tmux dialog asciidoc doxygen \
  7. net-tools dnsutils net-tools iputils-arping iputils-ping telnet \
  8. imagemagick ffmpeg fonts-dejavu-extra texlive-full \
  9. build-essential cmake pkg-config libtool automake autoconf \
  10. python3 python3-distutils python3-dev python3-pip virtualenv \
  11. php-fpm php-mbstring php-json php-xml php-pear php-bcmath php-curl php-zip \
  12. php-mysql php-pgsql php-sqlite3 php-redis php-mongodb php-amqp php-zmq \
  13. php-imagick php-gd \
  14. nginx rabbitmq-server redis postgresql
  15. apt -y autoremove
  16. apt -y clean
  17. echo "en_US.UTF-8 UTF-8" > /etc/locale.gen
  18. locale-gen
  19. update-locale LANG=en_US.UTF-8
  20. update-alternatives --set editor /usr/bin/vim.basic
  21. mkdir -p $HOME/downloads $HOME/build $HOME/local $HOME/tmp
  22. # https://github.com/ohmyzsh/ohmyzsh
  23. if [ ! -d $HOME/.oh-my-zsh ]
  24. then
  25. git clone https://github.com/ohmyzsh/ohmyzsh.git $HOME/.oh-my-zsh
  26. cp $HOME/.oh-my-zsh/templates/zshrc.zsh-template $HOME/.zshrc
  27. echo 'export LANG=en_US.UTF-8' >> $HOME/.zshrc
  28. echo 'export LC_ALL=en_US.UTF-8' >> $HOME/.zshrc
  29. echo 'export PATH=$HOME/.local/bin:$PATH' >> $HOME/.zshrc
  30. fi
  31. chsh -s /bin/zsh
  32. git config --global core.quotepath false
  33. git config --global http.version HTTP/1.1
  34. git config --global pull.rebase false
  35. git config --global url."https://".insteadOf git://
  36. echo 'set-option -g history-limit 102400' > $HOME/.tmux.conf
  37. echo 'set-option -g default-shell "/bin/zsh"' >> $HOME/.tmux.conf
  38. # https://getcomposer.org/doc/00-intro.md#installation-linux-unix-macos
  39. if [ ! -f $HOME/.local/bin/composer ]
  40. then
  41. wget -q -O $HOME/downloads/composer https://getcomposer.org/installer
  42. cd $HOME/downloads
  43. php composer
  44. mv composer.phar $HOME/.local/bin/composer
  45. fi
  46. # https://github.com/nvm-sh/nvm
  47. if [ ! -d $HOME/.nvm ]
  48. then
  49. export NVM_VERSION="v0.39.3"
  50. git clone -b ${NVM_VERSION} https://github.com/nvm-sh/nvm.git $HOME/.nvm
  51. echo 'export NVM_DIR="$HOME/.nvm"' >> $HOME/.zshrc
  52. echo '[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"' >> $HOME/.zshrc
  53. echo '[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"' >> $HOME/.zshrc
  54. zsh -c "source $HOME/.zshrc \
  55. && nvm install node \
  56. && nvm use node \
  57. && npm i yarn -g"
  58. echo 'export PATH=$HOME/.yarn/bin:$PATH' >> $HOME/.zshrc
  59. fi
  60. # https://opensearch.org/downloads.html#opensearch
  61. export OPENSEARCH_VERSION="2.4.1"
  62. if [ ! -d /opt/opensearch-${OPENSEARCH_VERSION} ]
  63. then
  64. wget -q -P $HOME/downloads \
  65. https://artifacts.opensearch.org/releases/bundle/opensearch/${OPENSEARCH_VERSION}/opensearch-${OPENSEARCH_VERSION}-linux-x64.tar.gz
  66. tar xf $HOME/downloads/opensearch-${OPENSEARCH_VERSION}-linux-x64.tar.gz -C /opt
  67. # https://opensearch.org/docs/latest/opensearch/install/tar/
  68. echo "network.host: 0.0.0.0" >> /opt/opensearch-${OPENSEARCH_VERSION}/config/opensearch.yml
  69. echo "discovery.type: single-node" >> /opt/opensearch-${OPENSEARCH_VERSION}/config/opensearch.yml
  70. echo "plugins.security.disabled: true" >> /opt/opensearch-${OPENSEARCH_VERSION}/config/opensearch.yml
  71. chown -R nobody /opt/opensearch-${OPENSEARCH_VERSION}
  72. fi
  73. # https://min.io/download#/linux
  74. if [ ! -f /usr/bin/minio ]
  75. then
  76. wget -q -O /usr/bin/minio \
  77. https://dl.min.io/server/minio/release/linux-amd64/minio
  78. chmod +x /usr/bin/minio
  79. mkdir -p /var/lib/minio/data
  80. chown -R nobody /var/lib/minio
  81. fi
  82. echo 'init postgresql data folder'
  83. if [ ! -d /var/lib/postgresql/data ]
  84. then
  85. su - postgres -c "/usr/lib/postgresql/14/bin/initdb -D /var/lib/postgresql/data"
  86. echo "listen_addresses = '0.0.0.0'" >> /var/lib/postgresql/data/postgresql.conf
  87. echo "host all all 0.0.0.0/0 md5" >> /var/lib/postgresql/data/pg_hba.conf
  88. fi
  89. ADD etc/redis/* /etc/redis/
  90. cd /var/lib \
  91. && mkdir redis-s redis-1 redis-2 redis-3 redis-4 redis-5 redis-6 \
  92. && chown redis:redis redis-s redis-1 redis-2 redis-3 redis-4 redis-5 redis-6 \
  93. && chmod 750 redis-s redis-1 redis-2 redis-3 redis-4 redis-5 redis-6
  94. mkdir /run/php \
  95. && echo "<?php phpinfo(); ?>" > /var/www/html/info.php \
  96. && echo "daemon off;" >> /etc/nginx/nginx.conf
  97. ADD etc/nginx.conf /etc/nginx/sites-enabled/default
  98. cat > /etc/nginx/sites-enabled/default <<EOF
  99. server {
  100. listen 80;
  101. server_name _;
  102. index index.html index.php;
  103. root /var/www/html;
  104. access_log /var/log/nginx/localhost.access.log custom;
  105. error_log /var/log/nginx/localhost.error.log warn;
  106. location / {
  107. try_files \$uri \$uri/ =404;
  108. }
  109. location ~ \.php\$ {
  110. include snippets/fastcgi-php.conf;
  111. fastcgi_pass unix:/run/php/php8.1-fpm.sock;
  112. }
  113. }
  114. EOF
  115. echo '20221226' > /VERSION
  116. echo 'done.'