├── LICENSE ├── README.md ├── deploy.sh └── exclude-list.txt /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 Darklg 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # git Deployer 2 | 3 | A simple way to deploy a website on a shared hosting with git 4 | -------------------------------------------------------------------------------- /deploy.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | echo '################'; 4 | echo '# Git Deployer'; 5 | echo '# v 0.2.2'; 6 | echo '# By @Darklg'; 7 | echo '################'; 8 | echo ''; 9 | 10 | ################################### 11 | ## Change config values here 12 | ################################### 13 | 14 | # - Project name 15 | PROJID='myprojectname'; 16 | 17 | # - Public subfolder ( usually www ) 18 | PRODDIR='wwwfoldername'; 19 | 20 | # - 1-step deploy ('y' to activate) 21 | ONESTEPDEPLOY='n'; 22 | 23 | ################################### 24 | ## Install 25 | ################################### 26 | 27 | # Vars 28 | MAINPATH="$(pwd)/"; 29 | GITPATH="${MAINPATH}${PROJID}.git/"; 30 | HOOKPATH="${GITPATH}hooks/post-receive"; 31 | SRCPATH="${MAINPATH}src/"; 32 | PRODPATH="${MAINPATH}${PRODDIR}/"; 33 | EXCLUDEFILENAME="exclude-list.txt"; 34 | EXCLUDEFILEPATH="${MAINPATH}${EXCLUDEFILENAME}"; 35 | 36 | # Install git repository if not available 37 | cd "${MAINPATH}"; 38 | if [[ ! -d "${GITPATH}" ]]; then 39 | mkdir "${GITPATH}"; 40 | cd "${GITPATH}"; 41 | git init --bare; 42 | echo "- [${PROJID}] GIT Repository is initialized"; 43 | if [[ "${ONESTEPDEPLOY}" == 'y' ]]; then 44 | touch "${HOOKPATH}"; 45 | chmod +x "${HOOKPATH}"; 46 | echo "#!/bin/sh" >> "${HOOKPATH}"; 47 | echo "GIT_DIR='${SRCPATH}.git';" >> "${HOOKPATH}"; 48 | echo "GIT_WORK_TREE='${SRCPATH}';" >> "${HOOKPATH}"; 49 | echo "cd ${MAINPATH}" >> "${HOOKPATH}"; 50 | echo "/bin/bash ${MAINPATH}deploy.sh" >> "${HOOKPATH}"; 51 | fi; 52 | fi; 53 | 54 | # Install src dir if not available 55 | cd "${MAINPATH}"; 56 | if [[ ! -d "${SRCPATH}" ]]; then 57 | git clone "${GITPATH}" src; 58 | echo "- [${PROJID}] Source folder is initialized"; 59 | fi; 60 | 61 | # Install exclude file 62 | cd "${MAINPATH}"; 63 | if [[ ! -f "${EXCLUDEFILEPATH}" ]]; then 64 | touch "${EXCLUDEFILEPATH}"; 65 | echo ".git" >> "${EXCLUDEFILEPATH}"; 66 | echo ".gitignore" >> "${EXCLUDEFILEPATH}"; 67 | echo ".gitmodules" >> "${EXCLUDEFILEPATH}"; 68 | echo "- [${PROJID}] Exclude file is initialized"; 69 | fi; 70 | 71 | # Pull latest version 72 | cd "${SRCPATH}"; 73 | git pull; 74 | git submodule init; 75 | git submodule update; 76 | git pull; 77 | echo "- [${PROJID}] Latest project files are pulled"; 78 | 79 | # Rsync to prod director 80 | cd "${MAINPATH}"; 81 | rsync -ruv --exclude-from "${EXCLUDEFILENAME}" "${SRCPATH}" "${PRODPATH}"; 82 | echo "- [${PROJID}] Project is synchronized !"; 83 | 84 | # Scripts post deployment 85 | if [[ -f "${MAINPATH}post-deploy.sh" ]]; then 86 | . "${MAINPATH}post-deploy.sh"; 87 | fi; 88 | -------------------------------------------------------------------------------- /exclude-list.txt: -------------------------------------------------------------------------------- 1 | *.scss 2 | *.sh 3 | .git 4 | .gitignore 5 | .gitmodules 6 | .travis.yml 7 | config.rb 8 | Gruntfile.js 9 | package.json 10 | phpunit.xml 11 | --------------------------------------------------------------------------------