|
2 | 2 |
|
3 | 3 | set -e #exit on error |
4 | 4 |
|
5 | | -api_key=$1 |
6 | | -command=$2 |
7 | | -format=$3 |
8 | | -org=$4 |
9 | | -repo=$5 |
10 | | -file=$6 |
11 | | -distro=$7 |
12 | | -release=$8 |
| 5 | +DEFAULT="none" # a way to handle ordered empty arguments of bash |
13 | 6 |
|
| 7 | +api_key=${1} |
| 8 | +command=${2} |
| 9 | +format=${3} |
| 10 | +owner=${4} |
| 11 | +repo=${5} |
| 12 | +file=${6} |
| 13 | +distro=${7} |
| 14 | +release=${8} |
| 15 | +version=${9} |
| 16 | +name=${10} |
| 17 | +summary=${11} |
| 18 | +description=${12} |
| 19 | +republish=${13} |
14 | 20 |
|
15 | 21 | # requires a CLOUDSMITH_API_KEY env variable to push |
16 | | -if [[ -z $api_key ]]; then |
| 22 | +if [[ -z $api_key || $api_key == $DEFAULT ]]; then |
17 | 23 | echo "CLOUDSMITH_API_KEY is required" |
18 | 24 | exit 1 |
19 | 25 | fi |
20 | 26 |
|
21 | | -export CLOUDSMITH_API_KEY=$api_key |
| 27 | +if [[ -z $command || $command == $DEFAULT ]]; then |
| 28 | + echo "command is required" |
| 29 | + exit 1 |
| 30 | +fi |
| 31 | +if [[ -z $format || $format == $DEFAULT ]]; then |
| 32 | + echo "format is required" |
| 33 | + exit 1 |
| 34 | +fi |
| 35 | +if [[ -z $owner || $owner == $DEFAULT ]]; then |
| 36 | + echo "owner is required" |
| 37 | + exit 1 |
| 38 | +fi |
| 39 | +if [[ -z $repo || $repo == $DEFAULT ]]; then |
| 40 | + echo "repo is required" |
| 41 | + exit 1 |
| 42 | +fi |
| 43 | +if [[ -z "$file" || $file == $DEFAULT ]]; then |
| 44 | + echo "file is required." |
| 45 | + exit 3 |
| 46 | +fi |
22 | 47 |
|
23 | 48 | if [[ "$command" != "push" ]]; then |
24 | | - echo "command $comand not yet implemented." |
| 49 | + echo "command $command not yet implemented." |
25 | 50 | exit 3 |
26 | 51 | fi |
27 | 52 |
|
28 | | -pip install cloudsmith-cli |
29 | 53 |
|
30 | 54 |
|
31 | | -if [[ "$format" == "deb" ]]; then |
32 | | - cloudsmith push $action $format $org/$repo/$distro/$release $file |
33 | | -else |
| 55 | +case "$format" in |
| 56 | + "deb"|"raw") |
| 57 | + |
| 58 | + if [[ -n "$distro" && "$distro" != $DEFAULT ]]; then |
| 59 | + distro_path="/$distro" |
| 60 | + if [[ -n "$release" && $release != $DEFAULT ]]; then |
| 61 | + distro_path="$distro_path/$release" |
| 62 | + fi |
| 63 | + fi |
| 64 | + |
| 65 | + # these optional args provided only if valid |
| 66 | + # notice the spaces are built into the args |
| 67 | + if [[ -n "$version" && "$version" != $DEFAULT ]]; then |
| 68 | + version_arg=" --version=\"$version\"" |
| 69 | + fi |
| 70 | + if [[ -n "$name" && "$name" != "$DEFAULT" ]]; then |
| 71 | + name_arg=" --name=\"$name\"" |
| 72 | + fi |
| 73 | + if [[ -n "$summary" && "$summary" != $DEFAULT ]]; then |
| 74 | + summary_arg=" --summary=\"$summary\"" |
| 75 | + fi |
| 76 | + if [[ -n "$description" && "$description" != $DEFAULT ]]; then |
| 77 | + description_arg=" --description=\"$description\"" |
| 78 | + fi |
| 79 | + if [[ "$republish" == "true" || $republish == true ]]; then |
| 80 | + republish_arg=" --republish" |
| 81 | + fi |
| 82 | + ;; |
| 83 | + *) |
34 | 84 | echo "format $format not yet implemented." |
35 | 85 | exit 2 |
36 | | -fi |
| 86 | + ;; |
| 87 | +esac |
| 88 | + |
| 89 | +export CLOUDSMITH_API_KEY=$api_key |
| 90 | + |
| 91 | +pip install cloudsmith-cli |
| 92 | + |
| 93 | +request="cloudsmith push $action $format $owner/$repo$distro_path$version_arg$name_arg$summary_arg$description_arg$republish_arg $file" |
| 94 | + |
| 95 | +echo $request |
| 96 | + |
| 97 | +eval $request |
0 commit comments