carbon-core-system

Integration repository for versioned configuration and software on Carbon
git clone https://ccx.te2000.cz/git/carbon-core-system
Log | Files | Refs | Submodules

push-to-host (1925B)


      1 #!/bin/zsh
      2 setopt no_unset warn_create_global extended_glob
      3 zmodload -F zsh/stat b:zstat || exit $?
      4 zmodload -m -F zsh/files b:zf_\* || exit $?
      5 zmodload zsh/zutil || exit $?  # for zparseopts
      6 zmodload zsh/datetime || exit $?  # for $EPOCHREALTIME
      7 
      8 cd $0:h || exit $?
      9 
     10 ### Utility functions {{{1
     11 die_ret() {
     12 	local ret
     13 	ret=$1
     14 	shift
     15 	printf >&2 '%s\n' "$@"
     16 	exit $ret
     17 }
     18 die() {
     19 	die_ret 1 "$@"
     20 }
     21 die100() {  # 100: wrong usage
     22 	die_ret 100 "$@"
     23 }
     24 die111() {  # 111: system call failed
     25 	die_ret 111 "$@"
     26 }
     27 
     28 pretend() {
     29 	: "$@"
     30 }
     31 typeset -f -t pretend
     32 
     33 typeset -g brz=${commands[brz]:-bzr}
     34 
     35 process_submodules() {
     36 	local line sub_state sub_commit sub_name
     37 	local -a git_status
     38 
     39 	git_status=( ${(f)"$(git submodule status --cached --recursive)"}) \
     40 		|| die_ret $? "Fatal: 'git submodule status' failed"
     41 	for line in $git_status; do
     42 		sub_state=${line[1]}
     43 		sub_commit=${line[2,41]}
     44 		sub_name=${line[43,-1]% \(*}
     45 		=cd $sub_name git push ${remote}:git/core-system/$sub_name ${sub_commit}:refs/heads/core-system-$branch_name || exit $?
     46 	done
     47 }
     48 
     49 process_bzr() {
     50 	# local -a revision_list
     51 	local revision_list repo_name revid
     52 	#revision_list=( "${(@f)"$(git cat-file blob $branch_name:bzr/revisions)"}" ) \
     53 	#
     54 	revision_list="$(git cat-file blob $branch_name:bzr/revisions)" \
     55 		|| die_ret $? "Could not get the list of bzr revisions"
     56 	while IFS=$'\t' read -r repo_name revid ; do
     57 		$brz push -d ../../bzr/$repo_name bzr+ssh://$remote/~/bzr/$repo_name || exit $?
     58 	done <<<$revision_list
     59 }
     60 
     61 main() {
     62 	typeset -g remote branch_name
     63 	case "$#" in
     64 		(2)
     65 			branch_name=$2
     66 			;;
     67 		(1)
     68 			branch_name=$(git branch --show-current) || exit $?
     69 			;;
     70 		(*)
     71 			die100 "usage: push-to-host remote [branch_name]"
     72 			;;
     73 			
     74 	esac
     75 	[[ -z $branch_name ]] && die "Error: no branch"
     76 	remote=$1
     77 	process_submodules
     78 	git push ${remote}:git/core-system ${branch_name}:refs/heads/core-system-${branch_name}
     79 	process_bzr
     80 }
     81 typeset -f -t main
     82 
     83 main "$@"