From 5ca034543b5d5a061f2d27d05e6d95bd955a42e8 Mon Sep 17 00:00:00 2001
From: "Hahn Axel (hahn)" <axel.hahn@iml.unibe.ch>
Date: Fri, 23 Apr 2021 10:28:16 +0200
Subject: [PATCH] remove download client The download client is part of the
 deployment script now.

---
 readme.md                        |  87 +---------
 shellscripts/getfile.sh          | 290 -------------------------------
 shellscripts/getfile.sh.cfg.dist |   8 -
 3 files changed, 5 insertions(+), 380 deletions(-)
 delete mode 100755 shellscripts/getfile.sh
 delete mode 100644 shellscripts/getfile.sh.cfg.dist

diff --git a/readme.md b/readme.md
index 3d104b2..0d58d57 100644
--- a/readme.md
+++ b/readme.md
@@ -87,88 +87,11 @@ return array(
 
 TODO
 
-## Installation of a client
+## Getting files
 
-This repo comes with a bash script. It is not a must to use it. The 
-communication is via https. Have a look to the source to see the creation
-of the authorization string. It can be adapted in other clients too. 
+An example client to access files from this package server is available
+as bash script (using curl).
 
-On a target system with your application you need a bash shell and curl.
+See deployment project <https://git-repo.iml.unibe.ch/iml-open-source/imldeployment-client>
 
-Copy the files from [approot]/shellscripts/ somewhere in a project related
-directory.
-
-Copy getfile.sh.cfg.dist to getfile.sh.cfg and setup values:
-
-```text
-IMLCI_PKG_SECRET=our-package-server-secret
-IMLCI_URL=https://cipkg.example.com
-IMLCI_PHASE=preview
-IMLCI_PROJECT=myproject-id
-```
-
-Remark: using the cfg file is optional. It countains default values.
-all values can be set by command line parameters.
-
-Usage of getfile.sh:
-```
-SYNTAX:
-
-  getfile.sh [OPTIONS]
-
-OPTIONS:
-
-  -c CFGFILE  load custom config file after defaults in getfile.sh.cfg
-  -d          enable debug infos
-  -e PHASE    phase; overrides env variable IMLCI_PHASE
-  -f FILE     filename to get (without path); overrides env variable IMLCI_FILE
-  -l ITEM     list
-  -o OUTFILE  optional output file
-  -p PROJECT  ci project id; overrides env variable IMLCI_PROJECT
-  -s SECRET   override secret in IMLCI_PKG_SECRET
-  -u URL      URL of iml ci server without trailing /; overrides env variable IMLCI_URL
-
-VALUES:
-
-  CFGFILE     custom config file. It is useful to handle files of different 
-              projects on a server.
-  PHASE       is a phase of the ci server; one of preview|stage|live
-  FILE        is a filename without path that was created by ci server.
-  OUTFILE     Output file. It can countain a path. If none is given the filename
-              will be taken from FILE and stored in current directory
-  PROJECT     project id of the ci server
-  SECRET      secret to access project data on package server. Your given secret
-              must match the secret on package server to get access to any url.
-  ITEM        type what to list; one of phases|projects|files
-              To list projects a phase must be set.
-              To list files a phase and a project must be set.
-
-DEFAULTS:
-
-  You don't need to set all values by command line. Use a config to set defaults
-  ./getfile.sh.cfg
-
-EXAMPLES:
-
-  If url, secret, project and phase are set in the config you can operate by
-  setting the filename to request.
-
-  getfile.sh -f FILE 
-    downloads FILE to the current dir.
-
-  getfile.sh -f FILE -o my-own-filename.tgz 
-    downloads FILE as my-own-filename.tgz
-
-  getfile.sh -f ALL 
-    there is a special file ALL; it fetches all filenames by executing a directory 
-    listing and then downloads all remote files with their original name
-
-  getfile.sh -e preview -l projects
-    list existing projects in phase preview
-
-  getfile.sh -l files
-    list existing files of current project
-
-  Remark: The directory listing can be turned off on the package server and
-  results in a 403 status.
-```
\ No newline at end of file
+The download script is bin/getfile.sh.
\ No newline at end of file
diff --git a/shellscripts/getfile.sh b/shellscripts/getfile.sh
deleted file mode 100755
index 381db6c..0000000
--- a/shellscripts/getfile.sh
+++ /dev/null
@@ -1,290 +0,0 @@
-#!/usr/bin/env bash
-# ======================================================================
-#
-# API CLIENT :: GET A CI FILE FROM PACKAGE SERVER
-#
-# ----------------------------------------------------------------------
-# 2021-03-31  v1.0  <axel.hahn@iml.unibe.ch>  init
-# 2021-04-13  v1.1  <axel.hahn@iml.unibe.ch>  add support for custom config
-# 2021-04-15  v1.2  <axel.hahn@iml.unibe.ch>  added debugging of curl request
-# ======================================================================
-
-# ----------------------------------------------------------------------
-# CONFIG
-# ----------------------------------------------------------------------
-
-line="----------------------------------------------------------------------"
-bDebug=0
-customconfig=
-
-. $0.cfg
-
-# ----------------------------------------------------------------------
-# FUNCTIONS
-# ----------------------------------------------------------------------
-
-function showhelp(){
-self=$( basename $0 )
-echo "
-CIPGK GETTER
-
-Get packages from a software sattelite of IML ci server.
-
-SYNTAX:
-
-  $self [OPTIONS]
-
-OPTIONS:
-
-  -c CFGFILE  load custom config file after defaults in $self.cfg
-  -d          enable debug infos
-  -e PHASE    phase; overrides env variable IMLCI_PHASE
-  -f FILE     filename to get (without path); overrides env variable IMLCI_FILE
-  -l ITEM     list
-  -o OUTFILE  optional output file
-  -p PROJECT  ci project id; overrides env variable IMLCI_PROJECT
-  -s SECRET   override secret in IMLCI_PKG_SECRET
-  -u URL      URL of iml ci server without trailing /; overrides env variable IMLCI_URL
-
-VALUES:
-
-  CFGFILE     custom config file. It is useful to handle files of different 
-              projects on a server.
-  PHASE       is a phase of the ci server; one of preview|stage|live
-  FILE        is a filename without path that was created by ci server.
-  OUTFILE     Output file. It can countain a path. If none is given the filename
-              will be taken from FILE and stored in current directory
-  PROJECT     project id of the ci server
-  SECRET      secret to access project data on package server. Your given secret
-              must match the secret on package server to get access to any url.
-  ITEM        type what to list; one of phases|projects|files
-              To list projects a phase must be set.
-              To list files a phase and a project must be set.
-
-DEFAULTS:
-
-  You don't need to set all values by command line. Use a config to set defaults
-  $0.cfg
-
-EXAMPLES:
-
-  If url, secret, project and phase are set in the config you can operate by
-  setting the filename to request.
-
-  $self -f FILE 
-    downloads FILE to the current dir.
-
-  $self -f FILE -o my-own-filename.tgz 
-    downloads FILE as my-own-filename.tgz
-
-  $self -f ALL 
-    there is a special file ALL; it fetches all filenames by executing a directory 
-    listing and then downloads all remote files with their original name
-
-  $self -e preview -l projects
-    list existing projects in phase preview
-
-  $self -l files
-    list existing files of current project
-
-  Remark: The directory listing can be turned off on the package server and
-  results in a 403 status.
-"
-}
-
-
-function makeRequest(){
-
-  local apiMethod=$1
-  local apiRequest=$2
-  local outfile=$3
-  local secret=$4
-
-  # local outfile=$( mktemp )
-
-  if [ $bDebug = 1 ]; then
-    echo $line
-    echo $apiMethod ${apiHost}${apiRequest}
-    echo $line
-  fi
-
-  if [ ! -z "$secret" ]; then
-
-    # --- date in http format
-    LANG=en_EN
-    # export TZ=GMT
-    apiTS=`date "+%a, %d %b %Y %H:%M:%S %Z"`
-
-
-# --- generate data to hash: method + uri + timestamp; delimited with line break
-data="${apiMethod}
-${apiRequest}
-${apiTS}
-"
-
-    # generate hash - split in 2 commands (piping "cut" sends additional line break)
-    myHash=`echo -n "$data" | openssl sha1 -hmac "${secret}" | cut -f 2 -d" "`
-    myHash=`echo -n "$myHash" | base64`
-
-    moreheaders="--fail"
-    test $bDebug = 1 && moreheaders="-i"
-
-    tmpdownloadfile="${outfile}.downloading"
-
-    curl \
-      -H "Accept: application/json" -H "Content-Type: application/json" \
-      -H "Date: ${apiTS}" \
-      -H "Authorization: demo-bash-client:${myHash}" \
-      -X $apiMethod \
-      -o "${tmpdownloadfile}" \
-      $moreheaders \
-      -s \
-      ${IMLCI_URL}${apiRequest}
-
-    rc=$?
-    if [ "$bDebug" = "1" ]; then
-        cat "${tmpdownloadfile}"
-        rm -f "${tmpdownloadfile}"
-        exit 0
-    fi
-
-    if [ $rc -eq 0 ]; then
-        # echo OK.
-
-        # no outfile (= request to a directory)
-        if [ -z "$outfile" ]; then
-            # echo
-            # echo ----- RESPONSE BODY:
-            cat "${tmpdownloadfile}"
-            rm -f "${tmpdownloadfile}" 
-        else
-            mv "${tmpdownloadfile}" "${outfile}"
-            ls -l "${outfile}"
-        fi
-    else
-        echo ERROR: Download failed.
-    fi
-  else
-    curl\
-      -H "Accept: application/json" -H "Content-Type: application/json" \
-      -X $apiMethod \
-      -o "${tmpdownloadfile}" \
-      ${IMLCI_URL}${apiRequest}
-  fi
-
-}
-
-
-# ----------------------------------------------------------------------
-# MAIN
-# ----------------------------------------------------------------------
-
-if  [ $# -lt 1 ]; then
-  showhelp
-  exit 1
-fi
-
-
-while getopts "c:de:f:l:o:p:s:u:" option; do 
-    case ${option} in
-      c) customconfig="$OPTARG" ;;
-      d) bDebug=1 ;;
-      e) export IMLCI_PHASE=$OPTARG ;;
-      f) export IMLCI_FILE=$OPTARG ;;
-      l) case $OPTARG in
-            phases)
-                IMLCI_PHASE=''
-                IMLCI_PROJECT=''
-                IMLCI_FILE=''
-                ;;
-            projects)
-                IMLCI_PROJECT=''
-                IMLCI_FILE=''
-                ;;
-            files)
-                IMLCI_FILE=''
-                ;;
-            *)
-                echo ERROR: invalid value for option [-l]
-                echo
-                showhelp
-                exit 2
-         esac
-            ;;
-      o) export IMLCI_OUTFILE=$OPTARG ;;
-      p) export IMLCI_PROJECT=$OPTARG ;;
-      s) export IMLCI_PKG_SECRET=$OPTARG ;;
-      u) export IMLCI_URL=$OPTARG ;;
-      *)
-        echo ERROR: invalid option [${option}]
-        echo
-        showhelp
-        exit 2
-    esac
-done
-
-if [ ! -z "$customconfig" ]; then
-    if [ -r "$customconfig" ]; then
-        . "$customconfig" || exit 2
-     else
-        echo "ERROR: unable to read custom config [$customconfig]."
-        exit 2
-     fi
-fi
-
-test -z ${IMLCI_OUTFILE} && IMLCI_OUTFILE=$IMLCI_FILE
-
-if [ $bDebug = 1 ]; then
-    pre=">>>>>> "
-    echo $line
-    echo
-    echo DEBUG INFOS
-    echo
-    echo "${pre} defaults in $0.cfg"
-    cat $0.cfg 2>/dev/null
-    echo
-    if [ ! -z "$customconfig" ]; then 
-        echo "${pre} custom config $customconfig"
-        cat "$customconfig"
-        echo
-    fi
-    echo "${pre} Params (override default values)"
-    echo $*
-    echo
-    echo "${pre} effective values"
-    echo "IMLCI_URL = $IMLCI_URL"
-    echo "IMLCI_PKG_SECRET = $IMLCI_PKG_SECRET"
-    echo "IMLCI_PROJECT = $IMLCI_PROJECT"
-    echo "IMLCI_PHASE = $IMLCI_PHASE"
-    echo "IMLCI_FILE = $IMLCI_FILE"
-    echo "IMLCI_OUTFILE = $IMLCI_OUTFILE"
-
-    echo
-fi
-
-if [ "$IMLCI_FILE" = "ALL" ]; then
-    # echo ALL files were requested ...
-    printf "%-30s" "get list of all files... "
-    tmpfilelist=$( mktemp )
-    $0 -u "${IMLCI_URL}" \
-        -p "${IMLCI_PROJECT}" \
-        -e "${IMLCI_PHASE}" \
-        -s "${IMLCI_PKG_SECRET}" \
-        -l files \
-        -o "${tmpfilelist}"
-    
-    # cat "${tmpfilelist}"
-    cat "${tmpfilelist}" | grep "^file:" | while read fileline
-    do
-        # echo $line
-        myfile=$( echo $fileline | cut -f 2- -d ':' )
-        printf "%-30s" "GET $myfile... "
-        $0 -u "${IMLCI_URL}" \
-            -p "${IMLCI_PROJECT}" \
-            -e "${IMLCI_PHASE}" \
-            -s "${IMLCI_PKG_SECRET}" \
-            -f "${myfile}"
-    done
-else 
-    makeRequest GET "/packages/$IMLCI_PHASE/$IMLCI_PROJECT/$IMLCI_FILE" "$IMLCI_OUTFILE" "$IMLCI_PKG_SECRET"
-fi
\ No newline at end of file
diff --git a/shellscripts/getfile.sh.cfg.dist b/shellscripts/getfile.sh.cfg.dist
deleted file mode 100644
index e649827..0000000
--- a/shellscripts/getfile.sh.cfg.dist
+++ /dev/null
@@ -1,8 +0,0 @@
-# ----------------------------------------------------------------------
-# defaults 
-# ----------------------------------------------------------------------
-
-IMLCI_PKG_SECRET=our-package-server-secret
-IMLCI_URL=https://cipkg.example.com
-IMLCI_PHASE=preview
-IMLCI_PROJECT=myproject-id
-- 
GitLab