forked from ungleich-public/cdist
		
	[type/__git] Fix if --owner / --group is numeric
Before, if --owner and/or --group was numeric, gencode-remote would generate `chown` code every time.
This commit is contained in:
		
					parent
					
						
							
								10ca1c12fd
							
						
					
				
			
			
				commit
				
					
						167c2ad7ea
					
				
			
		
					 2 changed files with 34 additions and 6 deletions
				
			
		| 
						 | 
					@ -1,5 +1,19 @@
 | 
				
			||||||
#!/bin/sh
 | 
					#!/bin/sh -e
 | 
				
			||||||
 | 
					
 | 
				
			||||||
destination="/$__object_id/.git"
 | 
					destination="/${__object_id:?}/.git"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
stat --print "%G" "${destination}" 2>/dev/null || exit 0
 | 
					# shellcheck disable=SC2012
 | 
				
			||||||
 | 
					group_gid=$(ls -ldn "${destination}" | awk '{ print $4 }')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# NOTE: +1 because $((notanum)) prints 0.
 | 
				
			||||||
 | 
					if test $((group_gid + 1)) -ge 0
 | 
				
			||||||
 | 
					then
 | 
				
			||||||
 | 
						group_should=$(cat "${__object:?}/parameter/group")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if expr "${group_should}" : '[0-9]*$' >/dev/null
 | 
				
			||||||
 | 
						then
 | 
				
			||||||
 | 
							printf '%u\n' "${group_gid}"
 | 
				
			||||||
 | 
						else
 | 
				
			||||||
 | 
							printf '%s\n' "$(id -u -n "${group_gid}")"
 | 
				
			||||||
 | 
						fi
 | 
				
			||||||
 | 
					fi
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,5 +1,19 @@
 | 
				
			||||||
#!/bin/sh
 | 
					#!/bin/sh -e
 | 
				
			||||||
 | 
					
 | 
				
			||||||
destination="/$__object_id/.git"
 | 
					destination="/${__object_id:?}/.git"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
stat --print "%U" "${destination}" 2>/dev/null || exit 0
 | 
					# shellcheck disable=SC2012
 | 
				
			||||||
 | 
					owner_uid=$(ls -ldn "${destination}" | awk '{ print $3 }')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# NOTE: +1 because $((notanum)) prints 0.
 | 
				
			||||||
 | 
					if test $((owner_uid + 1)) -ge 0
 | 
				
			||||||
 | 
					then
 | 
				
			||||||
 | 
						owner_should=$(cat "${__object:?}/parameter/owner")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if expr "${owner_should}" : '[0-9]*$' >/dev/null
 | 
				
			||||||
 | 
						then
 | 
				
			||||||
 | 
							printf '%u\n' "${owner_uid}"
 | 
				
			||||||
 | 
						else
 | 
				
			||||||
 | 
							printf '%s\n' "$(id -u -n "${owner_uid}")"
 | 
				
			||||||
 | 
						fi
 | 
				
			||||||
 | 
					fi
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue