add git project template
This commit is contained in:
		
							parent
							
								
									2fc2133f99
								
							
						
					
					
						commit
						e6631a053c
					
				| @ -15,11 +15,23 @@ my_www=${my_www:-"/srv/www"} | |||||||
| echo "" | echo "" | ||||||
| 
 | 
 | ||||||
| set -x | set -x | ||||||
|  | # user | ||||||
| sudo adduser --disabled-password --gecos "Git Site Deploys" --home "$my_repos" --no-create-home $my_user >/dev/null | sudo adduser --disabled-password --gecos "Git Site Deploys" --home "$my_repos" --no-create-home $my_user >/dev/null | ||||||
|  | 
 | ||||||
|  | # ssh | ||||||
| sudo mkdir -p "$my_repos/.ssh" "$my_www" | sudo mkdir -p "$my_repos/.ssh" "$my_www" | ||||||
| sudo chmod 0700 "$my_repos/.ssh" | sudo chmod 0700 "$my_repos/.ssh" | ||||||
| sudo ssh-keygen -t rsa -N "" -C "$my_user@$(hostname)" -f "$my_repos/.ssh/id_rsa" | sudo ssh-keygen -t rsa -N "" -C "$my_user@$(hostname)" -f "$my_repos/.ssh/id_rsa" | ||||||
| sudo install -m 0600 /dev/null "$my_repos/.ssh/authorized_keys" | sudo install -m 0600 /dev/null "$my_repos/.ssh/authorized_keys" | ||||||
|  | 
 | ||||||
|  | # git templates | ||||||
|  | sudo rsync -a git-templates/project/ "$my_repos/git-template/" | ||||||
|  | sudo install -m 0644 /dev/null "$my_repos/.gitconfig" | ||||||
|  | my_config='[init] | ||||||
|  |   templatedir = '"$my_repos/git-template" | ||||||
|  | sudo bash -c "echo '$my_config' >> '$my_repos/.gitconfig'" | ||||||
|  | 
 | ||||||
|  | # fix permissions | ||||||
| sudo chown -R $my_user:$my_user "$my_repos" "$my_www" | sudo chown -R $my_user:$my_user "$my_repos" "$my_www" | ||||||
| set +x | set +x | ||||||
| 
 | 
 | ||||||
|  | |||||||
							
								
								
									
										8
									
								
								git-templates/project-test.sh
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										8
									
								
								git-templates/project-test.sh
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,8 @@ | |||||||
|  | #!/usr/bin/env bash | ||||||
|  | rsync -a project/ project-test/ | ||||||
|  | my_input='old1 new1 name1 | ||||||
|  | 000 fff refs/heads/master | ||||||
|  | ' | ||||||
|  | echo "$my_input" | ./project-test/hooks/pre-receive | ||||||
|  | ./project-test/hooks/update ref_name old_rev new_rev | ||||||
|  | echo "$my_input" | ./project-test/hooks/post-receive | ||||||
							
								
								
									
										8
									
								
								git-templates/project-test/hooks/post-receive.d/03-fail
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										8
									
								
								git-templates/project-test/hooks/post-receive.d/03-fail
									
									
									
									
									
										Executable file
									
								
							| @ -0,0 +1,8 @@ | |||||||
|  | #!/usr/bin/env bash | ||||||
|  | set -e | ||||||
|  | set -u | ||||||
|  | 
 | ||||||
|  | my_input=$(cat) | ||||||
|  | echo "$my_input" | while read my_line; do | ||||||
|  | 	exit 159 | ||||||
|  | done | ||||||
							
								
								
									
										8
									
								
								git-templates/project-test/hooks/post-receive.d/04-fail
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										8
									
								
								git-templates/project-test/hooks/post-receive.d/04-fail
									
									
									
									
									
										Executable file
									
								
							| @ -0,0 +1,8 @@ | |||||||
|  | #!/usr/bin/env bash | ||||||
|  | set -e | ||||||
|  | set -u | ||||||
|  | 
 | ||||||
|  | my_input=$(cat) | ||||||
|  | echo "$my_input" | while read my_line; do | ||||||
|  | 	exit 160 | ||||||
|  | done | ||||||
							
								
								
									
										8
									
								
								git-templates/project-test/hooks/post-receive.d/98-succeed
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										8
									
								
								git-templates/project-test/hooks/post-receive.d/98-succeed
									
									
									
									
									
										Executable file
									
								
							| @ -0,0 +1,8 @@ | |||||||
|  | #!/usr/bin/env bash | ||||||
|  | set -u | ||||||
|  | set -e | ||||||
|  | 
 | ||||||
|  | my_input=$(cat) | ||||||
|  | echo "$my_input" | while read my_line; do | ||||||
|  | 	echo "Success $my_line" | ||||||
|  | done | ||||||
							
								
								
									
										8
									
								
								git-templates/project-test/hooks/pre-receive.d/02-pass
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										8
									
								
								git-templates/project-test/hooks/pre-receive.d/02-pass
									
									
									
									
									
										Executable file
									
								
							| @ -0,0 +1,8 @@ | |||||||
|  | #!/usr/bin/env bash | ||||||
|  | set -e | ||||||
|  | set -u | ||||||
|  | 
 | ||||||
|  | my_input=$(cat) | ||||||
|  | echo "$my_input" | while read my_line; do | ||||||
|  | 	echo "$my_line" | ||||||
|  | done | ||||||
							
								
								
									
										8
									
								
								git-templates/project-test/hooks/pre-receive.d/07-fail
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										8
									
								
								git-templates/project-test/hooks/pre-receive.d/07-fail
									
									
									
									
									
										Executable file
									
								
							| @ -0,0 +1,8 @@ | |||||||
|  | #!/usr/bin/env bash | ||||||
|  | set -e | ||||||
|  | set -u | ||||||
|  | 
 | ||||||
|  | my_input=$(cat) | ||||||
|  | echo "$my_input" | while read my_line; do | ||||||
|  | 	exit 160 | ||||||
|  | done | ||||||
							
								
								
									
										2
									
								
								git-templates/project-test/hooks/update.d/01-hello
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										2
									
								
								git-templates/project-test/hooks/update.d/01-hello
									
									
									
									
									
										Executable file
									
								
							| @ -0,0 +1,2 @@ | |||||||
|  | #!/usr/bin/env bash | ||||||
|  | echo "Hello $1 $2 $3" | ||||||
							
								
								
									
										3
									
								
								git-templates/project-test/hooks/update.d/50-fail
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										3
									
								
								git-templates/project-test/hooks/update.d/50-fail
									
									
									
									
									
										Executable file
									
								
							| @ -0,0 +1,3 @@ | |||||||
|  | #!/usr/bin/env bash | ||||||
|  | echo "Fail $1 $2 $3" | ||||||
|  | exit 158 | ||||||
							
								
								
									
										2
									
								
								git-templates/project-test/hooks/update.d/99-goodbye
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										2
									
								
								git-templates/project-test/hooks/update.d/99-goodbye
									
									
									
									
									
										Executable file
									
								
							| @ -0,0 +1,2 @@ | |||||||
|  | #!/usr/bin/env bash | ||||||
|  | echo "Goodbye $1 $2 $3" | ||||||
							
								
								
									
										36
									
								
								git-templates/project/hooks/post-receive
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										36
									
								
								git-templates/project/hooks/post-receive
									
									
									
									
									
										Executable file
									
								
							| @ -0,0 +1,36 @@ | |||||||
|  | #!/usr/bin/env bash | ||||||
|  | set -u | ||||||
|  | set -e | ||||||
|  | 
 | ||||||
|  | # post-receive | ||||||
|  | # this accepts multiple lines of input at a time | ||||||
|  | # it defers exit on failure until after all scripts have run | ||||||
|  | 
 | ||||||
|  | my_input=$(cat) | ||||||
|  | my_dir=$(dirname $0) | ||||||
|  | my_success="true" | ||||||
|  | 
 | ||||||
|  | for my_hook in ${my_dir}/post-receive.d/*; do | ||||||
|  | 
 | ||||||
|  | 	# Let the user know if the hook isn't executable, but don't bail | ||||||
|  | 	if [ ! -x "${my_hook}" ] || [ ! -f "${my_hook}" ]; then | ||||||
|  | 		>&2 echo "${my_hook} is not (or does not point to) an executable file" | ||||||
|  | 	fi | ||||||
|  | 
 | ||||||
|  | 	# Allow the script to fail so we can bubble the exit code and ensure an error message | ||||||
|  | 	set +e | ||||||
|  | 	echo "${my_input}" | ("${my_hook}") | ||||||
|  | 	my_exit_code=$? | ||||||
|  | 	set -e | ||||||
|  | 
 | ||||||
|  | 	# Don't bail on script failure | ||||||
|  | 	if [ "0" != "${my_exit_code}" ]; then | ||||||
|  | 		my_success="" | ||||||
|  | 		>&2 echo "${my_hook} failed with exit code ${my_exit_code}" | ||||||
|  | 	fi | ||||||
|  | done | ||||||
|  | 
 | ||||||
|  | if [ -z "${my_success}" ]; then | ||||||
|  | 	echo "some post-receives failed" | ||||||
|  | 	exit 156 | ||||||
|  | fi | ||||||
							
								
								
									
										0
									
								
								git-templates/project/hooks/post-receive.d/.gitkeep
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										0
									
								
								git-templates/project/hooks/post-receive.d/.gitkeep
									
									
									
									
									
										Normal file
									
								
							
							
								
								
									
										37
									
								
								git-templates/project/hooks/pre-receive
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										37
									
								
								git-templates/project/hooks/pre-receive
									
									
									
									
									
										Executable file
									
								
							| @ -0,0 +1,37 @@ | |||||||
|  | #!/usr/bin/env bash | ||||||
|  | set -u | ||||||
|  | set -e | ||||||
|  | 
 | ||||||
|  | # pre-receive | ||||||
|  | # this accepts multiple lines of input at a time | ||||||
|  | # it fails at the first of any child script failing | ||||||
|  | 
 | ||||||
|  | my_input=$(cat) | ||||||
|  | my_dir=$(dirname $0) | ||||||
|  | 
 | ||||||
|  | for my_hook in ${my_dir}/pre-receive.d/*; do | ||||||
|  | 
 | ||||||
|  | 	# Bail and let the user know if the hook isn't executable | ||||||
|  | 	if [ ! -x "${my_hook}" ] || [ ! -f "${my_hook}" ]; then | ||||||
|  | 		>&2 echo "${my_hook} is not (or does not point to) an executable file" | ||||||
|  | 		exit 155 | ||||||
|  | 	fi | ||||||
|  | 
 | ||||||
|  | 	# Allow the script to fail so we can bubble the exit code and ensure an error message | ||||||
|  | 	# and subscript it so that any set -e won't cause this to fail | ||||||
|  | 	set +e | ||||||
|  | 
 | ||||||
|  | 	# foo="$(echo bar; exit 3)"; echo $?; echo $foo | ||||||
|  | 	#my_output="$(echo "${my_input}" | "${my_hook}")" | ||||||
|  | 	echo "${my_input}" | ("${my_hook}") | ||||||
|  | 	my_exit_code=$? | ||||||
|  | 	set -e | ||||||
|  | 
 | ||||||
|  | 	#echo my_output: $my_output | ||||||
|  | 
 | ||||||
|  | 	# Bail on the first script failure | ||||||
|  | 	if [ "0" != "${my_exit_code}" ]; then | ||||||
|  | 		>&2 echo "${my_hook} failed with exit code ${my_exit_code}" | ||||||
|  |  		exit ${my_exit_code} | ||||||
|  | 	fi | ||||||
|  | done | ||||||
							
								
								
									
										0
									
								
								git-templates/project/hooks/pre-receive.d/.gitkeep
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										0
									
								
								git-templates/project/hooks/pre-receive.d/.gitkeep
									
									
									
									
									
										Normal file
									
								
							
							
								
								
									
										31
									
								
								git-templates/project/hooks/update
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										31
									
								
								git-templates/project/hooks/update
									
									
									
									
									
										Executable file
									
								
							| @ -0,0 +1,31 @@ | |||||||
|  | #!/usr/bin/env bash | ||||||
|  | set -u | ||||||
|  | set -e | ||||||
|  | 
 | ||||||
|  | # update script | ||||||
|  | # this accepts a single line up input in three args | ||||||
|  | # it fails at the first of any child script failing (and that branch fails to update) | ||||||
|  | 
 | ||||||
|  | my_dir=$(dirname $0) | ||||||
|  | my_exit_code="" | ||||||
|  | 
 | ||||||
|  | for my_hook in ${my_dir}/update.d/*; do | ||||||
|  | 
 | ||||||
|  | 	# Bail and let the user know if the hook isn't executable | ||||||
|  | 	if [ ! -x "${my_hook}" ] || [ ! -f "${my_hook}" ]; then | ||||||
|  | 		>&2 echo "${my_hook} is not (or does not point to) an executable file" | ||||||
|  | 		exit 155 | ||||||
|  | 	fi | ||||||
|  | 
 | ||||||
|  | 	# Allow the script to fail so we can bubble the exit code and ensure an error message | ||||||
|  | 	set +e | ||||||
|  | 	("${my_hook}" $1 $2 $3) | ||||||
|  | 	my_exit_code=$? | ||||||
|  | 	set -e | ||||||
|  | 
 | ||||||
|  | 	# Bail on the first script failure | ||||||
|  | 	if [ "0" != "${my_exit_code}" ]; then | ||||||
|  | 		>&2 echo "${my_hook} failed with exit code ${my_exit_code}" | ||||||
|  |  		exit ${my_exit_code} | ||||||
|  | 	fi | ||||||
|  | done | ||||||
							
								
								
									
										0
									
								
								git-templates/project/hooks/update.d/.gitkeep
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										0
									
								
								git-templates/project/hooks/update.d/.gitkeep
									
									
									
									
									
										Normal file
									
								
							
							
								
								
									
										0
									
								
								git-templates/user/.gitconfig
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										0
									
								
								git-templates/user/.gitconfig
									
									
									
									
									
										Normal file
									
								
							
							
								
								
									
										1
									
								
								git-templates/user/gitconfig.symlink
									
									
									
									
									
										Symbolic link
									
								
							
							
						
						
									
										1
									
								
								git-templates/user/gitconfig.symlink
									
									
									
									
									
										Symbolic link
									
								
							| @ -0,0 +1 @@ | |||||||
|  | .gitconfig | ||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user