Rewrite update script:
Fix nonexistent $SCRIPT variable.
Better parameters handling.
Add usage info.
diff --git a/aptly/files/aptly_publish_update.sh b/aptly/files/aptly_publish_update.sh
index 4441d82..4ff2dd3 100644
--- a/aptly/files/aptly_publish_update.sh
+++ b/aptly/files/aptly_publish_update.sh
@@ -1,39 +1,92 @@
#!/bin/bash
+############################################
+# Aptly publish update helper
+#
+############################################
+
+## Variables ## ============================
+############### ============================
CLEANUP=0
VERBOSE=0
START_API=0
RECREATE=0
FORCE_OVERWRITE=0
PUBLISHER_OPTIONS=""
+COMMAND=`basename $0`
+## Functions ## ============================
+############### ============================
log_info() {
- logger -p user.info -t ${SCRIPT} "$*"
- [ $VERBOSE -eq 1 ] && echo "[INFO] $*"
+ logger -p user.info -t ${COMMAND} "$*"
+ [ $VERBOSE -gt 0 ] && echo "[INFO] $*"
}
log_error() {
- logger -p user.error -t ${SCRIPT} "$*"
+ logger -p user.error -t ${COMMAND} "$*"
echo "[ERROR] $*" >&2
}
at_exit() {
pgrep -f "aptly api serve" | xargs kill -15
}
-trap at_exit EXIT
-while getopts "a?c?f?r?v?:u:" option;do
- case "${option}"
- in
- a|\?) START_API=1;;
- c|\?) CLEANUP=1;;
- f|\?) FORCE_OVERWRITE=1;;
- r|\?) RECREATE=1;;
- v|\?) VERBOSE=1;;
- u|\?) URL=$OPTARG;;
- esac
+
+## Usage ## --------------------------------
+Usage() {
+ cat <<EOF
+
+Usage:
+ $COMMAND [-h] [-qv] [-acrf]
+
+Updates aptly publishes.
+
+Parameters:
+ -h ... this help
+ -v ... more verbosity
+ -q ... less verbosity
+ -a ... start aptly api server
+ -c ... cleanup unused snapshots
+ -r ... drop publish and create it again, the only way to add new components
+ -f ... overwrite files in pool directory without notice
+
+EOF
+ exit
+}
+## Usage end ## ----------------------------
+
+## Main ## =================================
+########## =================================
+
+## Getparam ## -----------------------------
+while [[ -n "$1" ]]; do
+ i=$(expr substr $1 1 1)
+ if [[ $i == '-' ]]; then
+ r=$(expr substr $1 2 255)
+ while [[ -n "$r" ]]; do
+ i=$(expr substr $r 1 1)
+ case "$i" in
+ h) Usage ;;
+ q) let "VERBOSE -= 1" ;;
+ v) let "VERBOSE += 1" ;;
+ a) START_API=1 ;;
+ c) CLEANUP=1 ;;
+ r) RECREATE=1 ;;
+ f) FORCE_OVERWRITE=1 ;;
+ u) URL=$2; shift ;;
+ esac
+ r=$(expr substr $r 2 255)
+ done
+ else
+ parms="$parms $1"
+ fi
+ shift
done
+## Getparam end ## -------------------------
+
+: ${URL:="http://127.0.0.1:8080"}
if [[ $START_API -eq 1 ]]; then
+ trap at_exit EXIT
nohup aptly api serve --no-lock > /dev/null 2>&1 </dev/null &
fi
if [[ $RECREATE -eq 1 ]]; then
@@ -43,21 +96,20 @@
PUBLISHER_OPTIONS+=" --force-overwrite"
fi
-URL=${URL:-"http://127.0.0.1:8080"}
aptly-publisher --timeout=1200 publish -v -c /etc/aptly/publisher.yaml --url ${URL} --architectures amd64 $PUBLISHER_OPTIONS
if [[ $? -ne 0 ]]; then
- echo "Aptly Publisher failed."
+ log_error "Aptly publisher failed."
exit 1
fi
if [[ $CLEANUP -eq 1 ]]; then
SNAPSHOT_LIST="$(aptly snapshot list --raw)"
if [[ "$SNAPSHOT_LIST" != "" ]]; then
- log_info "Deleting unpublished snapshots"
+ log_info "Deleting unpublished snapshots."
echo $SNAPSHOT_LIST | grep -E '*' | xargs -n 1 aptly snapshot drop
fi
- log_info "Cleaning Aptly DB"
+ log_info "Cleaning Aptly DB."
aptly db cleanup
fi
exit 0