Merge "README clean up"
diff --git a/.travis.yml b/.travis.yml
index e58885b..2e5d4b1 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,3 +1,6 @@
+language: python
+python:
+- "2.7.13"
sudo: required
services:
- docker
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
diff --git a/aptly/files/gpg.conf b/aptly/files/gpg.conf
new file mode 100644
index 0000000..8ca3ebb
--- /dev/null
+++ b/aptly/files/gpg.conf
@@ -0,0 +1,2 @@
+cert-digest-algo SHA256
+digest-algo SHA256
diff --git a/aptly/server/init.sls b/aptly/server/init.sls
index d4ca164..5083035 100644
--- a/aptly/server/init.sls
+++ b/aptly/server/init.sls
@@ -1,6 +1,7 @@
{%- from "aptly/map.jinja" import server with context %}
{%- if server.enabled %}
+{% set gpgconffile = '{}/.gnupg/gpg.conf'.format(server.home_dir) %}
{% set gpgprivfile = '{}/.gnupg/secret.gpg'.format(server.home_dir) %}
{% set gpgpubfile = '{}/public/public.gpg'.format(server.root_dir) %}
@@ -138,6 +139,16 @@
- require:
- file: aptly_home_dir
+gpg_conf_file:
+ file.managed:
+ - name: {{ gpgconffile }}
+ - source: salt://aptly/files/gpg.conf
+ - user: {{ server.user.name }}
+ - group: {{ server.user.group }}
+ - mode: 644
+ - makedirs: true
+ - require:
+ - file: aptly_gpg_key_dir
gpg_priv_key:
file.managed:
@@ -163,7 +174,7 @@
import_gpg_pub_key:
cmd.run:
- name: gpg --no-tty{% if server.gpg.get('homedir', None) %} --homedir {{ server.gpg.homedir }}{% endif %} --import {{ gpgpubfile }}
- - user: {{ server.user.name }}
+ - runas: {{ server.user.name }}
- unless: gpg --no-tty{% if server.gpg.get('homedir', None) %} --homedir {{ server.gpg.homedir }}{% endif %} --list-keys | grep '{{ server.gpg.keypair_id }}'
- require:
- file: gpg_pub_key
@@ -172,7 +183,7 @@
import_gpg_priv_key:
cmd.run:
- name: gpg --no-tty --allow-secret-key-import{% if server.gpg.get('homedir', None) %} --homedir {{ server.gpg.homedir }}{% endif %} --import {{ gpgprivfile }}
- - user: {{ server.user.name }}
+ - runas: {{ server.user.name }}
- unless: gpg --no-tty{% if server.gpg.get('homedir', None) %} --homedir {{ server.gpg.homedir }}{% endif %} --list-secret-keys | grep '{{ server.gpg.keypair_id }}'
- require:
- file: aptly_gpg_key_dir
diff --git a/aptly/server/mirrors.sls b/aptly/server/mirrors.sls
index 24be665..8944522 100644
--- a/aptly/server/mirrors.sls
+++ b/aptly/server/mirrors.sls
@@ -45,7 +45,7 @@
gpg_add_keys_{{ mirror_name }}_{{ gpgkey }}:
cmd.run:
- name: gpg --no-tty {% if server.gpg.get('keyring', None) %} --no-default-keyring --keyring {{ server.gpg.keyring }} {% endif %}{% if server.gpg.get('homedir', None) %} --homedir {{ server.gpg.homedir }}{% endif %} --keyserver {{ mirror.keyserver|default(server.gpg.keyserver) }} {% if server.gpg.get('http_proxy', None) %} --keyserver-options http-proxy={{ server.gpg.get('http_proxy') }} {% endif %} --recv-keys {{ gpgkey }}
- - user: {{ server.user.name }}
+ - runas: {{ server.user.name }}
- cwd: {{ server.home_dir }}
- unless: gpg --no-tty {% if server.gpg.get('keyring', None) %} --no-default-keyring --keyring {{ server.gpg.keyring }} {% endif %}{% if server.gpg.get('homedir', None) %} --homedir {{ server.gpg.homedir }} {% endif %} {% if server.gpg.get('http_proxy', None) %} --keyserver-options http-proxy={{ server.gpg.get('http_proxy') }} {% endif %} --list-public-keys {{gpgkey}}
{%- if server.secure %}
@@ -64,7 +64,7 @@
cmd.run:
- name: aptly snapshot create {{ snapshot }} from mirror {{ mirror_name }}
{%- if server.source.engine != "docker" %}
- - user: {{ server.user.name }}
+ - runas: {{ server.user.name }}
{%- endif %}
- unless: aptly snapshot show {{ snapshot }}
- require:
@@ -79,7 +79,7 @@
cmd.run:
- name: aptly mirror create {% if mirror.get('udebs', False) %}-with-udebs=true {% endif %}{% if mirror.get('sources', False) %}-with-sources=true {% endif %}{% if mirror.get('filter') %}-filter="{{ mirror.filter }}" {% endif %}{% if mirror.get('filter_with_deps') %}-filter-with-deps {% endif %}-architectures={{ mirror.architectures }} {{ mirror_name }} {{ mirror.source }} {{ mirror.distribution }} {{ mirror.components }}
{%- if server.source.engine != "docker" %}
- - user: {{ server.user.name }}
+ - runas: {{ server.user.name }}
{%- endif %}
- unless: aptly mirror show {{ mirror_name }}
{%- if server.source.engine == "docker" %}
@@ -91,7 +91,7 @@
cmd.run:
- name: aptly mirror edit {% if mirror.get('udebs', False) %}-with-udebs=true {% endif %}{% if mirror.get('sources', False) %}-with-sources=true {% endif %}{% if mirror.get('filter') %}-filter="{{ mirror.filter }}" {% endif %}{% if mirror.get('filter_with_deps') %}-filter-with-deps {% endif %}-architectures={{ mirror.architectures }} {{ mirror_name }}
{%- if server.source.engine != "docker" %}
- - user: {{ server.user.name }}
+ - runas: {{ server.user.name }}
{%- endif %}
- onlyif: 'aptly mirror show {{ mirror_name }} | grep -v "^Filter: {{ mirror.get('filter', '') }}$" | grep -q "^Filter: "'
{%- if server.source.engine == "docker" %}
@@ -105,7 +105,7 @@
cmd.run:
- name: aptly mirror update {{ mirror_name }}
{%- if server.source.engine != "docker" %}
- - user: {{ server.user.name }}
+ - runas: {{ server.user.name }}
{%- endif %}
- require:
- cmd: aptly_{{ mirror_name }}_mirror
@@ -120,7 +120,7 @@
cmd.run:
- name: aptly publish snapshot -batch=true -gpg-key='{{ server.gpg.keypair_id }}' -passphrase='{{ server.gpg.passphrase }}' {{ server.mirror[mirror_name].publish }}
{%- if server.source.engine != "docker" %}
- - user: {{ server.user.name }}
+ - runas: {{ server.user.name }}
{%- endif %}
{%- if server.source.engine == "docker" %}
- require:
diff --git a/aptly/server/repos.sls b/aptly/server/repos.sls
index c486895..c18c981 100644
--- a/aptly/server/repos.sls
+++ b/aptly/server/repos.sls
@@ -7,7 +7,7 @@
- name: aptly repo create -distribution="{{ repo.distribution }}" -component="{{ repo.component }}" -architectures="{{ repo.architectures }}" -comment="{{ repo.comment }}" {{ repo_name }}
- unless: aptly repo show {{ repo_name }}
{%- if server.source.engine != "docker" %}
- - user: {{ server.user.name }}
+ - runas: {{ server.user.name }}
{%- endif %}
- require:
- file: aptly_conf
@@ -28,7 +28,7 @@
cmd.run:
- name: aptly repo add {{ repo_name }} {{ repo.pkg_dir }}
{%- if server.source.engine != "docker" %}
- - user: {{ server.user.name }}
+ - runas: {{ server.user.name }}
{%- endif %}
- require:
- cmd: aptly_{{ repo_name }}_repo_create
@@ -44,7 +44,7 @@
cmd.run:
- name: aptly publish repo -batch=true -gpg-key='{{ server.gpg.keypair_id }}' -passphrase='{{ server.gpg.passphrase }}' {{ repo_name }}
{%- if server.source.engine != "docker" %}
- - user: {{ server.user.name }}
+ - runas: {{ server.user.name }}
{%- endif %}
- unless: aptly publish update -batch=true -gpg-key='{{ server.gpg.keypair_id }}' -passphrase='{{ server.gpg.passphrase }}' {{ repo.distribution }}
{%- endif %}