2018-04-19 10:35:41 +00:00
|
|
|
#!/bin/bash
|
|
|
|
set -e
|
|
|
|
|
|
|
|
if [ "$#" -eq "0" ]; then
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
projectName=$1
|
2018-08-29 13:56:12 +00:00
|
|
|
gitBranch=$2
|
|
|
|
|
|
|
|
. /etc/vn-repo/config
|
|
|
|
|
|
|
|
if [ -z "$gitUrl" ]; then
|
|
|
|
gitUrl=http://localhost
|
|
|
|
fi
|
|
|
|
if [ -z "$gitBranch" ]; then
|
|
|
|
gitBranch=master
|
|
|
|
fi
|
|
|
|
|
2018-04-19 10:35:41 +00:00
|
|
|
repoDir="/var/lib/git/$projectName"
|
|
|
|
srcDir="/tmp/vn-repo/$projectName/src"
|
2018-08-29 13:09:21 +00:00
|
|
|
logDir="/usr/share/vn-repo/web/logs"
|
2018-05-02 06:32:19 +00:00
|
|
|
logFile="$logDir/$projectName.out"
|
2018-04-19 10:35:41 +00:00
|
|
|
|
2018-05-02 06:32:19 +00:00
|
|
|
mkdir -p "$logDir"
|
2018-04-19 10:35:41 +00:00
|
|
|
rm -f "$logFile"
|
|
|
|
|
2018-04-19 12:05:16 +00:00
|
|
|
echo -e "\n# Deploying started\n" >> "$logFile"
|
2018-04-19 12:00:16 +00:00
|
|
|
echo " * Date: $(date)" >> "$logFile"
|
|
|
|
echo " * Project: $projectName" >> "$logFile"
|
|
|
|
echo " * Directory: $srcDir" >> "$logFile"
|
2018-04-19 12:05:16 +00:00
|
|
|
echo " * Host: $(hostname)" >> "$logFile"
|
2018-04-19 12:00:16 +00:00
|
|
|
|
2018-04-19 10:35:41 +00:00
|
|
|
mkdir -p "$srcDir"
|
2018-08-29 13:56:12 +00:00
|
|
|
|
|
|
|
if [ ! -d "$srcDir/.git" ]; then
|
2018-08-29 14:36:31 +00:00
|
|
|
(cd "$srcDir" && git init)
|
2018-08-29 13:56:12 +00:00
|
|
|
fi
|
|
|
|
|
2018-08-29 14:36:31 +00:00
|
|
|
(cd "$srcDir" && git config remote.origin.url "$gitUrl/$projectName")
|
|
|
|
(cd "$srcDir" && git pull origin "$gitBranch")
|
2018-04-19 10:35:41 +00:00
|
|
|
|
2018-05-02 06:32:19 +00:00
|
|
|
if [ -f "$srcDir/deploy" ]; then
|
2018-08-29 14:36:31 +00:00
|
|
|
(cd "$srcDir" && "$srcDir/deploy" >> "$logFile" 2>&1)
|
2018-04-19 10:35:41 +00:00
|
|
|
fi
|
2018-04-19 11:55:22 +00:00
|
|
|
|
2018-04-19 12:05:16 +00:00
|
|
|
echo -e "\n# Deploying ended\n" >> "$logFile"
|