| 
									
										
										
										
											2020-05-15 01:23:03 +03:00
										 |  |  | #!/usr/bin/env bash | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | err() { printf '%s\n' "$*" >&2; } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-06 06:41:56 +03:00
										 |  |  | build_remote() { makepkg-ci "$@"; } | 
					
						
							| 
									
										
										
										
											2020-05-15 01:23:03 +03:00
										 |  |  | cleanup() { rm -f "$lockfile"; } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | lock() { | 
					
						
							|  |  |  | 	[[ -f "$lockfile" ]] && { | 
					
						
							|  |  |  | 		printf 'Lockfile found: %s\n' "$lockfile" >&2 | 
					
						
							|  |  |  | 		return 1 | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	echo $$ > "$lockfile" | 
					
						
							|  |  |  | 	lock_pid=$(<"$lockfile") | 
					
						
							|  |  |  | 	[[ $$ == "$lock_pid" ]] || return 1 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | # Ensure one instance | 
					
						
							|  |  |  | lockfile="$HOME/.cache/pkgbuilder/.lock" | 
					
						
							|  |  |  | lock || exit 1 | 
					
						
							|  |  |  | trap cleanup EXIT | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | declare -A pkg_dests | 
					
						
							| 
									
										
										
										
											2020-05-15 01:47:43 +03:00
										 |  |  | source "$HOME/.config/pkgbuilder/config" | 
					
						
							| 
									
										
										
										
											2020-05-15 01:23:03 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | wrkdir="$HOME/.cache/pkgbuilder/repositories" | 
					
						
							|  |  |  | mkdir -p "$wrkdir" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | set -- "${repos[@]}" | 
					
						
							|  |  |  | while (($#>1)); do | 
					
						
							|  |  |  | 	pkg_repo=$2 | 
					
						
							|  |  |  | 	pkg_dest="${pkg_dests[$1]}" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	repo_name="${pkg_repo##*/}" | 
					
						
							|  |  |  | 	repo_path="${pkg_repo##*://}" | 
					
						
							|  |  |  | 	repo_local="$wrkdir/${repo_path%.git}" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	err "repo: $repo_local" | 
					
						
							|  |  |  | 	err " - url: $pkg_repo" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	# Check if the repo already exists | 
					
						
							|  |  |  | 	if ! [[ -d "$repo_local" ]]; then | 
					
						
							|  |  |  | 		mkdir -p "$wrkdir/${repo_path%$repo_name}" | 
					
						
							|  |  |  | 		git clone "$pkg_repo" "$repo_local" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-27 02:47:54 +03:00
										 |  |  | 		build_remote "$pkg_dest" "$pkg_repo" | 
					
						
							| 
									
										
										
										
											2020-05-15 01:23:03 +03:00
										 |  |  | 	else | 
					
						
							|  |  |  | 		git -C "$repo_local" remote update | 
					
						
							|  |  |  | 		if git -C "$repo_local" status --porcelain -bu | grep -q behind; then | 
					
						
							| 
									
										
										
										
											2021-02-27 02:47:54 +03:00
										 |  |  | 			build_remote "$pkg_dest" "$pkg_repo" | 
					
						
							| 
									
										
										
										
											2020-05-15 01:23:03 +03:00
										 |  |  | 			git -C "$repo_local" pull | 
					
						
							|  |  |  | 		fi | 
					
						
							|  |  |  | 	fi | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	shift 2 | 
					
						
							|  |  |  | done |