Suggest a feature
×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: Bash
Posted by: Сергей Шевченко
Added: Dec 24, 2019 12:43 PM
Modified: Dec 25, 2019 11:52 AM
Views: 126
  1. #!/bin/bash
  2.  
  3. set -eux
  4.  
  5. NC='\e[0m' # No Color
  6. BLACK='\e[0;30m'
  7. BLUE='\e[0;34m'
  8. BROWN='\e[0;33m'
  9. CYAN='\e[0;36m'
  10. GRAY='\e[0;30m'
  11. GREEN='\e[0;32m'
  12. PURPLE='\e[0;35m'
  13. RED='\e[0;31m'
  14. WHITE='\e[1;37m'
  15. YELLOW='\e[1;33m'
  16.  
  17.  
  18. function addLogMessage {
  19.     set +x
  20.     MESSAGE=${1}
  21.     COLOR=''
  22.  
  23.     if [[ ! -n ${2+set} ]]; then
  24.         COLOR=${CYAN}
  25.     else
  26.         COLOR=${2}
  27.     fi
  28.  
  29.     # Делаем красивую рамку вокруг сообщения
  30.     COUNT_SYMBOLS=$(echo ${MESSAGE} | wc -m)
  31.     PAST_BORDER_SYMBOLS=''
  32.     PAST_SPACES_SYMBOLS=''
  33.     for ((i=1; i<=${COUNT_SYMBOLS}; i++)); do
  34.         PAST_BORDER_SYMBOLS="${PAST_BORDER_SYMBOLS}*";
  35.         PAST_SPACES_SYMBOLS="${PAST_SPACES_SYMBOLS} ";
  36.     done
  37.  
  38.     echo -e "\n\n\n"
  39.     echo -e "${COLOR}*************${PAST_BORDER_SYMBOLS}*************${NC}"
  40.     echo -e "${COLOR}*            ${PAST_SPACES_SYMBOLS}            *${NC}"
  41.     echo -e "${COLOR}*            ${MESSAGE}            *${NC}"
  42.     echo -e "${COLOR}*            ${PAST_SPACES_SYMBOLS}            *${NC}"
  43.     echo -e "${COLOR}*************${PAST_BORDER_SYMBOLS}*************${NC}\n"
  44.     set -x
  45. }
  46.  
  47.  
  48. export GIT_SSL_NO_VERIFY=1
  49.  
  50. # Install laravel core
  51. addLogMessage 'Установка "laravel/laravel:5.8"...'
  52.     if [[ ! -f ./.env ]]; then
  53.         composer create-project -n --prefer-source laravel/laravel /tmp/laravel_core/ "5.8.*"
  54.         mv -v /tmp/laravel_core/* ${LARAVEL_CORE_PATH}/
  55.         addLogMessage '"laravel/laravel:5.8" установлен успешно!' ${GREEN}
  56.     else
  57.         addLogMessage '"laravel/laravel:5.8" уже был установлен ранее!' ${YELLOW}
  58.     fi
  59.  
  60.  
  61. # Install gfx kernel
  62. addLogMessage 'Установка "Gfx\\Kernel"'
  63.     if [[ ! -f ./vendor/gfx/kernel/.env ]]; then
  64.         rm -rfv ./vendor/gfx/kernel
  65.         mkdir -vp ./vendor/gfx/kernel
  66.         git clone -b "${GIT_KERNEL_BRANCH}" ${GIT_KERNEL_LINK} ${KERNEL_PATH}
  67.         composer config repositories.gfx/kernel path ${KERNEL_PATH}
  68.         composer require gfx/kernel
  69.         addLogMessage '"Gfx\\Kernel" успешно установлен!' "${GREEN}"
  70.     else
  71.         addLogMessage '"Gfx\\Kernel" уже был установлен ранее!' "${YELLOW}"
  72.     fi
  73.  
  74.  
  75. # Install gfx personal-area
  76. addLogMessage 'Установка "Gfx\\PersonalArea"...'
  77.     if [[ ! -f ./vendor/gfx/personal-area/.env.personal-area ]]; then
  78.         rm -frv ./vendor/gfx/personal-area
  79.         mkdir -vp ./vendor/gfx/personal-area
  80.         git clone -b "${GIT_PERSONAL_AREA_BRANCH}" ${GIT_PERSONAL_AREA_LINK} ${PERSONAL_AREA_PATH}
  81.         composer config repositories.gfx/personal-area path ${PERSONAL_AREA_PATH}
  82.         composer require gfx/personal-area
  83.  
  84.         if [[ -f ./app/User.php && ! -f ./app/Models/User.php ]]; then
  85.             NAMESPACE_PATTERN_SEARCH='namespace App;'
  86.             NAMESPACE_PATTERN_REPLACE='namespace App\\Models;'
  87.             TRAIT_PATTERN_SEARCH='use Notifiable;'
  88.             TRAIT_PATTERN_REPLACE='use Notifiable;\n    use \\Backpack\\CRUD\\CrudTrait;\n    use \\Spatie\\Permission\\Traits\\HasRoles;'
  89.             sed -i "s/${NAMESPACE_PATTERN_SEARCH}/${NAMESPACE_PATTERN_REPLACE}/" ./app/User.php
  90.             sed -i "s/${TRAIT_PATTERN_SEARCH}/${TRAIT_PATTERN_REPLACE}/" ./app/User.php
  91.             mv -v ./app/User.php ./app/Models/
  92.         fi
  93.         addLogMessage '"Gfx\\PersonalArea" успешно установлен!' "${GREEN}"
  94.     else
  95.         addLogMessage '"Gfx\\PersonalArea" уже был установлен ранее!' "${YELLOW}"
  96.     fi
  97.  
  98.  
  99. # Edit configs
  100. addLogMessage 'Изменение файлов конфигурации...'
  101.     cp -v ${KERNEL_PATH}/.env.kernel .env
  102.     echo '' >> ./.env
  103.     echo '# >>>>> Personal area configs (start) >>>>>' >> ./.env
  104.     cat ${PERSONAL_AREA_PATH}/.env.personal-area >> .env
  105.     echo '# <<<<< Personal area configs (end) <<<<<' >> ./.env
  106.     sed -i 's/APP_NAME=/APP_NAME=laravel-kernel-personal-area/g' ./.env
  107.     sed -i 's/APP_ENV=local/APP_ENV=development/g' ./.env
  108.     sed -i 's/APP_KEY=/APP_KEY=base64:Yc29mMsvjbmYryiHK1bkNeQ1ak1gdW+T\/LjDOI9IEzE=/g' ./.env
  109.     sed -i 's/DB_HOST=127.0.0.1/DB_HOST=bbh-mysql/g' ./.env
  110.     sed -i 's/DB_PORT=3306/DB_PORT=3306/g' ./.env
  111.     sed -i 's/DB_DATABASE=/DB_DATABASE=bbh/g' ./.env
  112.     sed -i 's/DB_USERNAME=/DB_USERNAME=bbh/g' ./.env
  113.     sed -i 's/DB_PASSWORD=/DB_PASSWORD=bbh-password/g' ./.env
  114.     LARAVEL_LOG_DIR="${LARAVEL_CORE_PATH}/var/log"
  115.     LARAVEL_LOG_DIR_SHIELDED_SLASHES=$(echo ${LARAVEL_LOG_DIR} | sed 's/\//\\\//g')
  116.     sed -i "s/LOG_DIR=/LOG_DIR=${LARAVEL_LOG_DIR_SHIELDED_SLASHES}/g" ./.env
  117.     mkdir -pv ${LARAVEL_LOG_DIR}
  118.     sed -i "s/'timezone' => 'UTC'/'timezone' => 'Europe\/Moscow'/g" ./config/app.php
  119.     sed -i "s/'driver' => 'daily'/'driver' => 'daily', 'permission' => 0644/g" ./config/app.php
  120.  
  121.     cp -v ./.env ./.env.testing
  122.     echo '# >>>>> Personal area configs for tests (start) >>>>>' >> ./.env.testing
  123.     echo 'MAIL_DRIVER=log' >> ./.env.testing
  124.     echo 'CACHE_DRIVER=array' >> ./.env.testing
  125.     echo '# <<<<< Personal area configs for tests (end) <<<<<' >> ./.env.testing
  126.     sed -i 's/APP_ENV=development/APP_ENV=testing/g' ./.env.testing
  127.     sed -i 's/DB_CONNECTION=mysql/DB_CONNECTION=personal-area-testing/g' ./.env.testing
  128.    
  129.  
  130. # Configuration Artisan
  131. addLogMessage 'Запуск artisan...'
  132.     chmod -v +x ./artisan
  133.     php artisan -n -v key:generate
  134.     php artisan -n -v config:cache --env=testing
  135.     php artisan -n -v backpack:base:install
  136.     php artisan -n -v backpack:crud:install
  137.     php artisan -n -v gfx:kernel:install
  138.     php artisan -n -v gfx:kernel:create-structure
  139.     php artisan -n -v gfx:kernel:publish-model
  140.     php artisan -n -v migrate
  141.     php artisan -n -v vendor:publish --force --provider="Gfx\PersonalArea\PersonalAreaServiceProvider"
  142.     php artisan -n -v config:cache --env=testing
  143.    
  144.  
  145. # Set permissions
  146. addLogMessage 'Установка прав и разрешений...'
  147.     chown -v www-data:www-data -R ./
  148.     chmod -v 766 -R ./
  149.  
  150.  
  151. composer install -n
  152.  
  153. php-fpm
  154.  
  155.