|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# This script is used to create image directories using distgen, cp or ln |
| 4 | +# It requires manifest.sh file to be present in image repository |
| 5 | +# The manifest file should contain set of rules in form: |
| 6 | +# <rules_type>=" |
| 7 | +# src=<path to source> |
| 8 | +# dest=<path to destination> |
| 9 | +# mode=<destination file mode (optional)>; |
| 10 | +# ...; |
| 11 | +# " |
| 12 | +# |
| 13 | +# Supported type rules are now COPY_RULES, DISTGEN_RULES and SYMLINKS_RULES |
| 14 | +# for real example see https://github.com/sclorg/postgresql-container/blob/master/manifest.sh |
| 15 | + |
| 16 | +source manifest.sh |
| 17 | + |
| 18 | +test -f auto_targets.mk && rm auto_targets.mk |
| 19 | + |
| 20 | +DEST_DIR="${DEST_DIR:-$PWD}" |
| 21 | + |
| 22 | +clean_rule_variables(){ |
| 23 | + src="" |
| 24 | + dest="" |
| 25 | + mode="" |
| 26 | + link_target="" |
| 27 | + link_name="" |
| 28 | +} |
| 29 | + |
| 30 | +parse_rules() { |
| 31 | + targets="" |
| 32 | + OLD_IFS=$IFS |
| 33 | + IFS=";" |
| 34 | + for rule in $rules; do |
| 35 | + if [ -z $(echo "$rule"| tr -d '[:space:]') ]; then |
| 36 | + continue |
| 37 | + fi |
| 38 | + clean_rule_variables |
| 39 | + eval $rule |
| 40 | + |
| 41 | + case "$creator" in |
| 42 | + copy) |
| 43 | + [[ -z "$src" ]] && echo "src has to be specified in copy rule" && exit 1 |
| 44 | + [[ -z "$dest" ]] && echo "dest has to be specified in copy rule" && exit 1 |
| 45 | + core_subst=$core |
| 46 | + ;; |
| 47 | + distgen) |
| 48 | + [[ -z "$src" ]] && echo "src has to be specified in distgen rule" && exit 1 |
| 49 | + [[ -z "$dest" ]] && echo "dest has to be specified in distgen rule" && exit 1 |
| 50 | + core_subst=$core |
| 51 | + ;; |
| 52 | + link) |
| 53 | + [[ -z "$link_name" ]] && echo "link_name has to be specified in link rule" && exit 1 |
| 54 | + [[ -z "$link_target" ]] && echo "link_target has to be specified in link rule" && exit 1 |
| 55 | + dest="$link_name" |
| 56 | + link_target="$DEST_DIR/$version/$link_target" |
| 57 | + core_subst=$(echo $core | sed -e "s~__link_target__~"${link_target}"~g") |
| 58 | + ;; |
| 59 | + esac |
| 60 | + t=$(echo ${DEST_DIR}/${version}/${dest} | sed 's/ /\\ /g') |
| 61 | + src=$(echo $src | sed 's/ /\\ /g' ) |
| 62 | + echo "$t" |
| 63 | + targets+=" $t \\ |
| 64 | +" |
| 65 | + cat >> auto_targets.mk << EOF |
| 66 | +$t: $src manifest.sh |
| 67 | + @echo ${message} ; \\ |
| 68 | + mkdir -p "\$\$(dirname \$@)" || exit 1 ; \\ |
| 69 | + ${core_subst} |
| 70 | + ${mode:+"chmod ${mode} "\$@""} |
| 71 | +
|
| 72 | +EOF |
| 73 | + done |
| 74 | + IFS=$OLD_IFS |
| 75 | +} |
| 76 | + |
| 77 | +for version in ${VERSIONS}; do |
| 78 | + # copy targets |
| 79 | + rules="$COPY_RULES" |
| 80 | + core="cp \$< \$@ ; \\" |
| 81 | + message="Copying \"\$@\"" |
| 82 | + creator="copy" |
| 83 | + parse_rules |
| 84 | + COPY_TARGETS+="$targets" |
| 85 | + |
| 86 | + |
| 87 | + # distgen targets |
| 88 | + rules="$DISTGEN_RULES" |
| 89 | + core="${DG} --multispec specs/multispec.yml \\ |
| 90 | + --template \"\$<\" --distro \"$DG_CONF\" \\ |
| 91 | + --multispec-selector version=\"$version\" --output \"\$@\" ; \\" |
| 92 | + message="Generating \"\$@\" using distgen" |
| 93 | + creator="distgen" |
| 94 | + parse_rules |
| 95 | + DISTGEN_TARGETS+="$targets" |
| 96 | + |
| 97 | + |
| 98 | + rules=$SYMLINK_RULES |
| 99 | + core="ln -fs __link_target__ \$@ ; \\" |
| 100 | + message="Creating symlink \"\$@\"" |
| 101 | + creator="link" |
| 102 | + parse_rules |
| 103 | + SYMLINK_TARGETS+="$targets" |
| 104 | +done |
| 105 | + |
| 106 | + # adding COPY_TARGETS variable at the bottom of auto_targets.mk file |
| 107 | + cat -v >> auto_targets.mk << EOF |
| 108 | +COPY_TARGETS = \\ |
| 109 | +$COPY_TARGETS |
| 110 | +EOF |
| 111 | + |
| 112 | + # adding DISTGEN_TARGETS variable at the bottom of auto_targets.mk file |
| 113 | + cat -v >> auto_targets.mk << EOF |
| 114 | +DISTGEN_TARGETS = \\ |
| 115 | +$DISTGEN_TARGETS |
| 116 | +EOF |
| 117 | + |
| 118 | + cat -v >> auto_targets.mk << EOF |
| 119 | +SYMLINK_TARGETS = \\ |
| 120 | +$SYMLINK_TARGETS |
| 121 | +EOF |
0 commit comments