Add shellcheck

This commit is contained in:
Andrey Volkov 2018-10-24 10:17:28 -07:00
parent b80214540c
commit 55d34437ad
3 changed files with 35 additions and 93 deletions

17
Makefile Normal file
View File

@ -0,0 +1,17 @@
# Copyright 2018 The Openstack-Helm Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
.PHONY: lint
lint:
shellcheck assets/*.sh

View File

@ -1,75 +0,0 @@
#! /usr/bin/env bash
set -e
# Automate the initial creation and update of a Debian package mirror in aptly
# The variables (as set below) will create a mirror of the Debian jessie repo
# with the main and update components. If you do mirror these, you'll want to
# include "deb http://security.debian.org jessie/updates main" in your sources.list
# file or mirror it similarly as done below to keep up with security updates.
DEBIAN_RELEASE=stretch
UPSTREAM_URL="http://deb.debian.org/debian/"
COMPONENTS=( main )
REPOS=( ${DEBIAN_RELEASE} ${DEBIAN_RELEASE}-updates )
# Create repository mirrors if they don't exist
set +e
for component in ${COMPONENTS[@]}; do
for repo in ${REPOS[@]}; do
aptly mirror list -raw | grep "^${repo}$"
if [[ $? -ne 0 ]]; then
echo "Creating mirror of ${repo} repository."
aptly mirror create \
-architectures=amd64 ${repo} ${UPSTREAM_URL} ${repo} ${component}
fi
done
done
set -e
# Update all repository mirrors
for component in ${COMPONENTS[@]}; do
for repo in ${REPOS[@]}; do
echo "Updating ${repo} repository mirror.."
aptly mirror update ${repo}
done
done
# Create snapshots of updated repositories
for component in ${COMPONENTS[@]}; do
for repo in ${REPOS[@]}; do
echo "Creating snapshot of ${repo} repository mirror.."
SNAPSHOTARRAY+="${repo}-`date +%Y%m%d%H` "
aptly snapshot create ${repo}-`date +%Y%m%d%H` from mirror ${repo}
done
done
echo ${SNAPSHOTARRAY[@]}
# Merge snapshots into a single snapshot with updates applied
echo "Merging snapshots into one.."
aptly snapshot merge -latest \
${DEBIAN_RELEASE}-merged-`date +%Y%m%d%H` \
${SNAPSHOTARRAY[@]}
# Publish the latest merged snapshot
set +e
aptly publish list -raw | awk '{print $2}' | grep "^${DEBIAN_RELEASE}$"
if [[ $? -eq 0 ]]; then
aptly publish switch \
-passphrase="${GPG_PASSWORD}" \
${DEBIAN_RELEASE} ${DEBIAN_RELEASE}-merged-`date +%Y%m%d%H`
else
aptly publish snapshot \
-passphrase="${GPG_PASSWORD}" \
-distribution=${DEBIAN_RELEASE} ${DEBIAN_RELEASE}-merged-`date +%Y%m%d%H`
fi
set -e
# Export the GPG Public key
if [[ ! -f /opt/aptly/public/aptly_repo_signing.key ]]; then
gpg --export --armor > /opt/aptly/public/aptly_repo_signing.key
fi
# Generate Aptly Graph
aptly graph -output /opt/aptly/public/aptly_graph.png

View File

@ -16,65 +16,65 @@ if [ "$MODE" = "packages" ]; then
echo "File with a package list is not found" echo "File with a package list is not found"
exit 1 exit 1
fi fi
FILTER_OPTS=(-filter="$(cat /opt/packages/$PACKAGE_FILE | paste -sd \| -)" -filter-with-deps) FILTER_VAL=$(paste -sd \| "/opt/packages/$PACKAGE_FILE")
FILTER_OPTS=("-filter=$FILTER_VAL" "-filter-with-deps")
else else
FILTER_OPTS=() FILTER_OPTS=()
fi fi
REPO_DATE=$(date +%Y%m%d%H)
# Create repository mirrors if they don't exist # Create repository mirrors if they don't exist
set +e
for component in ${COMPONENTS}; do for component in ${COMPONENTS}; do
for repo in ${REPOS}; do for repo in ${REPOS}; do
aptly mirror list -raw | grep "^${repo}-${component}$" if ! aptly mirror list -raw | grep "^${repo}-${component}$"
if [[ $? -ne 0 ]]; then then
echo "Creating mirror of ${repo}-${component} repository." echo "Creating mirror of ${repo}-${component} repository."
aptly mirror create \ aptly mirror create \
-architectures=amd64 "${FILTER_OPTS[@]}" ${repo}-${component} ${UPSTREAM_URL} ${repo} ${component} -architectures=amd64 "${FILTER_OPTS[@]}" "${repo}-${component}" "${UPSTREAM_URL}" "${repo}" "${component}"
fi fi
done done
done done
set -e
# Update all repository mirrors # Update all repository mirrors
for component in ${COMPONENTS}; do for component in ${COMPONENTS}; do
for repo in ${REPOS}; do for repo in ${REPOS}; do
echo "Updating ${repo}-${component} repository mirror.." echo "Updating ${repo}-${component} repository mirror.."
aptly mirror update ${repo}-${component} aptly mirror update "${repo}-${component}"
done done
done done
SNAPSHOTARRAY=()
# Create snapshots of updated repositories # Create snapshots of updated repositories
for component in ${COMPONENTS}; do for component in ${COMPONENTS}; do
for repo in ${REPOS}; do for repo in ${REPOS}; do
echo "Creating snapshot of ${repo}-${component} repository mirror.." echo "Creating snapshot of ${repo}-${component} repository mirror.."
SNAPSHOTARRAY+="${repo}-${component}-`date +%Y%m%d%H` " SNAPSHOTARRAY+=("${repo}-${component}-$REPO_DATE")
aptly snapshot create ${repo}-${component}-`date +%Y%m%d%H` from mirror ${repo}-${component} aptly snapshot create "${repo}-${component}-$REPO_DATE" from mirror "${repo}-${component}"
done done
done done
echo ${SNAPSHOTARRAY[@]} echo "${SNAPSHOTARRAY[@]}"
# Merge snapshots into a single snapshot with updates applied # Merge snapshots into a single snapshot with updates applied
echo "Merging snapshots into one.." echo "Merging snapshots into one.."
aptly snapshot merge -latest \ aptly snapshot merge -latest \
${UBUNTU_RELEASE}-merged-`date +%Y%m%d%H` \ "${UBUNTU_RELEASE}-merged-$REPO_DATE" \
${SNAPSHOTARRAY[@]} "${SNAPSHOTARRAY[@]}"
# Publish the latest merged snapshot # Publish the latest merged snapshot
set +e if aptly publish list -raw | awk '{print $2}' | grep "^${UBUNTU_RELEASE}$"
aptly publish list -raw | awk '{print $2}' | grep "^${UBUNTU_RELEASE}$" then
if [[ $? -eq 0 ]]; then
aptly publish switch \ aptly publish switch \
-batch=true \ -batch=true \
-passphrase="${GPG_PASSWORD}" \ -passphrase="${GPG_PASSWORD}" \
${UBUNTU_RELEASE} ${UBUNTU_RELEASE}-merged-`date +%Y%m%d%H` "${UBUNTU_RELEASE}" "${UBUNTU_RELEASE}-merged-$REPO_DATE"
else else
aptly publish snapshot \ aptly publish snapshot \
-batch=true \ -batch=true \
-passphrase="${GPG_PASSWORD}" \ -passphrase="${GPG_PASSWORD}" \
-distribution=${UBUNTU_RELEASE} ${UBUNTU_RELEASE}-merged-`date +%Y%m%d%H` -distribution="${UBUNTU_RELEASE}" "${UBUNTU_RELEASE}-merged-$REPO_DATE"
fi fi
set -e
# Export the GPG Public key # Export the GPG Public key
if [[ ! -f /opt/aptly/public/aptly_repo_signing.key ]]; then if [[ ! -f /opt/aptly/public/aptly_repo_signing.key ]]; then