-
Notifications
You must be signed in to change notification settings - Fork 0
/
deploy.sh
36 lines (35 loc) · 1.42 KB
/
deploy.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/bin/bash
echo "Deploy to '$1'"
if [ $1 = 'production' ]; then
DEP_ENV='PRODUCTION'
DEP_TARGET='rurihikohara@rurihikohara.sakura.ne.jp:/home/rurihikohara/www/niwa-archives.org'
DEP_PORT='22'
elif [ $1 = 'staging' ]; then
DEP_ENV='STAGING'
DEP_TARGET='rurihikohara@rurihikohara.sakura.ne.jp:/home/rurihikohara/www/stg.niwa-archives.org'
DEP_PORT='22'
elif [ $1 = 'ycam' ]; then
DEP_ENV='PRODUCTION'
DEP_TARGET='www@niwa2.ycam.jp:/home/www/html/niwa2'
DEP_PORT='10022'
else
echo "引数にデプロイ先( production | staging | ycam )を指定してください。"
exit 1
fi
if yarn generate; then
# Remove useless files
find ./dist/ -name '.DS_Store' -type f -delete
find ./dist/ -name '.nojekyll' -type f -delete
if npm run rename; then
# remove "DEP_XXX_RM "
ext=".temp_bakup" # extension of backup files which are created before replacement
find ./dist/ -name "*.htaccess" -exec sed -i$ext "s|#DEP_REMOTE_RM ||" {} \;
find ./dist/ -name "*.htaccess" -exec sed -i$ext "s|#DEP_"$DEP_ENV"_RM ||" {} \;
find ./dist/ -name "*.php" -exec sed -i$ext "s|//DEP_REMOTE_RM ||" {} \;
find ./dist/ -name "*.php" -exec sed -i$ext "s|//DEP_"$DEP_ENV"_RM ||" {} \;
find ./dist/ -name "*$ext" -exec rm {} \; # delete backup files
# Deploy
rsync -aIzh --perms --owner --group --stats --delete -e "ssh -p $DEP_PORT" "--exclude-from=$PWD/.depignore" ./dist/ $DEP_TARGET
npm run rename-back
fi
fi