install.sh 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. #!/bin/bash
  2. set -e
  3. CURRENT_DIR=$( cd "$(dirname "${BASH_SOURCE[0]}")" ; pwd -P )
  4. source ${CURRENT_DIR}/../common/common.sh
  5. [ $(id -u) != "0" ] && { ansi -n --bold --bg-red "请用 root 账户执行本脚本"; exit 1; }
  6. MYSQL_ROOT_PASSWORD=`random_string`
  7. function init_system {
  8. export LC_ALL="en_US.UTF-8"
  9. echo "LC_ALL=en_US.UTF-8" >> /etc/default/locale
  10. locale-gen en_US.UTF-8
  11. locale-gen zh_CN.UTF-8
  12. ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
  13. apt-get update
  14. apt-get install -y software-properties-common
  15. init_alias
  16. }
  17. function init_alias {
  18. alias sudowww > /dev/null 2>&1 || {
  19. echo "alias sudowww='sudo -H -u ${WWW_USER} sh -c'" >> ~/.bash_aliases
  20. }
  21. }
  22. function init_repositories {
  23. add-apt-repository -y ppa:ondrej/php
  24. add-apt-repository -y ppa:nginx/stable
  25. add-apt-repository -y ppa:chris-lea/redis-server
  26. grep -rl ppa.launchpad.net /etc/apt/sources.list.d/ | xargs sed -i 's/http:\/\/ppa.launchpad.net/https:\/\/launchpad.proxy.ustclug.org/g'
  27. #curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add -
  28. #echo "deb https://dl.yarnpkg.com/debian/ stable main" > /etc/apt/sources.list.d/yarn.list
  29. #curl -s https://deb.nodesource.com/gpgkey/nodesource.gpg.key | apt-key add -
  30. #echo 'deb https://mirrors.tuna.tsinghua.edu.cn/nodesource/deb_10.x xenial main' > /etc/apt/sources.list.d/nodesource.list
  31. #echo 'deb-src https://mirrors.tuna.tsinghua.edu.cn/nodesource/deb_10.x xenial main' >> /etc/apt/sources.list.d/nodesource.list
  32. apt-get update
  33. }
  34. function install_basic_softwares {
  35. apt-get install -y curl git build-essential unzip supervisor
  36. }
  37. function install_node_yarn {
  38. apt-get install -y nodejs yarn
  39. sudo -H -u ${WWW_USER} sh -c 'cd ~ && yarn config set registry https://registry.npm.taobao.org'
  40. }
  41. function install_php {
  42. apt-get install -y php7.4-bcmath php7.4-cli php7.4-curl php7.4-fpm php7.4-gd php7.4-mbstring php7.4-mysql php7.4-opcache php7.4-pgsql php7.4-readline php7.4-xml php7.4-zip php7.4-sqlite3 php7.4-redis
  43. }
  44. function install_others {
  45. apt-get remove -y apache2
  46. debconf-set-selections <<< "mysql-server mysql-server/root_password password ${MYSQL_ROOT_PASSWORD}"
  47. debconf-set-selections <<< "mysql-server mysql-server/root_password_again password ${MYSQL_ROOT_PASSWORD}"
  48. apt-get install -y nginx mysql-server redis-server
  49. chown -R ${WWW_USER}.${WWW_USER_GROUP} /var/www/
  50. systemctl enable nginx.service
  51. }
  52. function install_composer {
  53. curl https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin/ --filename=composer
  54. chmod +x /usr/local/bin/composer
  55. sudo -H -u ${WWW_USER} sh -c 'cd ~ && composer config -g repo.packagist composer https://mirrors.aliyun.com/composer/'
  56. }
  57. call_function init_system "正在初始化系统" ${LOG_PATH}
  58. call_function init_repositories "正在初始化软件源" ${LOG_PATH}
  59. call_function install_basic_softwares "正在安装基础软件" ${LOG_PATH}
  60. call_function install_php "正在安装 PHP" ${LOG_PATH}
  61. call_function install_others "正在安装 Mysql / Nginx / Redis / Memcached / Beanstalkd / Sqlite3" ${LOG_PATH}
  62. #call_function install_node_yarn "正在安装 Nodejs / Yarn" ${LOG_PATH}
  63. call_function install_composer "正在安装 Composer" ${LOG_PATH}
  64. ansi --green --bold -n "安装完毕"
  65. ansi --green --bold "Mysql root 密码:"; ansi -n --bold --bg-yellow --black ${MYSQL_ROOT_PASSWORD}
  66. ansi --green --bold -n "请手动执行 source ~/.bash_aliases 使 alias 指令生效。"