Browse Source

Add shellcheck

Andrey Volkov 6 months ago
parent
commit
55d34437ad
3 changed files with 35 additions and 93 deletions
  1. 17
    0
      Makefile
  2. 0
    75
      assets/update_mirror_debian.sh
  3. 18
    18
      assets/update_mirror_ubuntu.sh

+ 17
- 0
Makefile View File

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

+ 0
- 75
assets/update_mirror_debian.sh View File

@@ -1,75 +0,0 @@
1
-#! /usr/bin/env bash
2
-set -e
3
-
4
-# Automate the initial creation and update of a Debian package mirror in aptly
5
-
6
-# The variables (as set below) will create a mirror of the Debian jessie repo 
7
-# with the main and update components. If you do mirror these, you'll want to
8
-# include "deb http://security.debian.org jessie/updates main" in your sources.list
9
-# file or mirror it similarly as done below to keep up with security updates.
10
-
11
-DEBIAN_RELEASE=stretch
12
-UPSTREAM_URL="http://deb.debian.org/debian/"
13
-COMPONENTS=( main )
14
-REPOS=( ${DEBIAN_RELEASE} ${DEBIAN_RELEASE}-updates )
15
-
16
-# Create repository mirrors if they don't exist
17
-set +e
18
-for component in ${COMPONENTS[@]}; do
19
-  for repo in ${REPOS[@]}; do
20
-    aptly mirror list -raw | grep "^${repo}$"
21
-    if [[ $? -ne 0 ]]; then
22
-      echo "Creating mirror of ${repo} repository."
23
-      aptly mirror create \
24
-        -architectures=amd64 ${repo} ${UPSTREAM_URL} ${repo} ${component}
25
-    fi
26
-  done
27
-done
28
-set -e
29
-
30
-# Update all repository mirrors
31
-for component in ${COMPONENTS[@]}; do
32
-  for repo in ${REPOS[@]}; do
33
-    echo "Updating ${repo} repository mirror.."
34
-    aptly mirror update ${repo}
35
-  done
36
-done
37
-
38
-# Create snapshots of updated repositories
39
-for component in ${COMPONENTS[@]}; do
40
-  for repo in ${REPOS[@]}; do
41
-    echo "Creating snapshot of ${repo} repository mirror.."
42
-    SNAPSHOTARRAY+="${repo}-`date +%Y%m%d%H` "
43
-    aptly snapshot create ${repo}-`date +%Y%m%d%H` from mirror ${repo}
44
-  done
45
-done
46
-
47
-echo ${SNAPSHOTARRAY[@]}
48
-
49
-# Merge snapshots into a single snapshot with updates applied
50
-echo "Merging snapshots into one.." 
51
-aptly snapshot merge -latest                 \
52
-  ${DEBIAN_RELEASE}-merged-`date +%Y%m%d%H`  \
53
-  ${SNAPSHOTARRAY[@]}
54
-
55
-# Publish the latest merged snapshot
56
-set +e
57
-aptly publish list -raw | awk '{print $2}' | grep "^${DEBIAN_RELEASE}$"
58
-if [[ $? -eq 0 ]]; then
59
-  aptly publish switch            \
60
-    -passphrase="${GPG_PASSWORD}" \
61
-    ${DEBIAN_RELEASE} ${DEBIAN_RELEASE}-merged-`date +%Y%m%d%H`
62
-else
63
-  aptly publish snapshot \
64
-    -passphrase="${GPG_PASSWORD}" \
65
-    -distribution=${DEBIAN_RELEASE} ${DEBIAN_RELEASE}-merged-`date +%Y%m%d%H`
66
-fi
67
-set -e
68
-
69
-# Export the GPG Public key
70
-if [[ ! -f /opt/aptly/public/aptly_repo_signing.key ]]; then
71
-  gpg --export --armor > /opt/aptly/public/aptly_repo_signing.key
72
-fi
73
-
74
-# Generate Aptly Graph
75
-aptly graph -output /opt/aptly/public/aptly_graph.png

+ 18
- 18
assets/update_mirror_ubuntu.sh View File

@@ -16,65 +16,65 @@ if [ "$MODE" = "packages" ]; then
16 16
         echo "File with a package list is not found"
17 17
         exit 1
18 18
     fi
19
-    FILTER_OPTS=(-filter="$(cat /opt/packages/$PACKAGE_FILE | paste -sd \| -)" -filter-with-deps)
19
+    FILTER_VAL=$(paste -sd \| "/opt/packages/$PACKAGE_FILE")
20
+    FILTER_OPTS=("-filter=$FILTER_VAL" "-filter-with-deps")
20 21
 else
21 22
     FILTER_OPTS=()
22 23
 fi
23 24
 
25
+REPO_DATE=$(date +%Y%m%d%H)
26
+
24 27
 # Create repository mirrors if they don't exist
25
-set +e
26 28
 for component in ${COMPONENTS}; do
27 29
   for repo in ${REPOS}; do
28
-    aptly mirror list -raw | grep "^${repo}-${component}$"
29
-    if [[ $? -ne 0 ]]; then
30
+    if ! aptly mirror list -raw | grep "^${repo}-${component}$"
31
+    then
30 32
       echo "Creating mirror of ${repo}-${component} repository."
31 33
       aptly mirror create \
32
-        -architectures=amd64 "${FILTER_OPTS[@]}" ${repo}-${component} ${UPSTREAM_URL} ${repo} ${component}
34
+        -architectures=amd64 "${FILTER_OPTS[@]}" "${repo}-${component}" "${UPSTREAM_URL}" "${repo}" "${component}"
33 35
     fi
34 36
   done
35 37
 done
36
-set -e
37 38
 
38 39
 # Update all repository mirrors
39 40
 for component in ${COMPONENTS}; do
40 41
   for repo in ${REPOS}; do
41 42
     echo "Updating ${repo}-${component} repository mirror.."
42
-    aptly mirror update ${repo}-${component}
43
+    aptly mirror update "${repo}-${component}"
43 44
   done
44 45
 done
45 46
 
47
+SNAPSHOTARRAY=()
46 48
 # Create snapshots of updated repositories
47 49
 for component in ${COMPONENTS}; do
48 50
   for repo in ${REPOS}; do
49 51
     echo "Creating snapshot of ${repo}-${component} repository mirror.."
50
-    SNAPSHOTARRAY+="${repo}-${component}-`date +%Y%m%d%H` "
51
-    aptly snapshot create ${repo}-${component}-`date +%Y%m%d%H` from mirror ${repo}-${component}
52
+    SNAPSHOTARRAY+=("${repo}-${component}-$REPO_DATE")
53
+    aptly snapshot create "${repo}-${component}-$REPO_DATE" from mirror "${repo}-${component}"
52 54
   done
53 55
 done
54 56
 
55
-echo ${SNAPSHOTARRAY[@]}
57
+echo "${SNAPSHOTARRAY[@]}"
56 58
 
57 59
 # Merge snapshots into a single snapshot with updates applied
58 60
 echo "Merging snapshots into one.."
59 61
 aptly snapshot merge -latest                 \
60
-  ${UBUNTU_RELEASE}-merged-`date +%Y%m%d%H`  \
61
-  ${SNAPSHOTARRAY[@]}
62
+  "${UBUNTU_RELEASE}-merged-$REPO_DATE"  \
63
+  "${SNAPSHOTARRAY[@]}"
62 64
 
63 65
 # Publish the latest merged snapshot
64
-set +e
65
-aptly publish list -raw | awk '{print $2}' | grep "^${UBUNTU_RELEASE}$"
66
-if [[ $? -eq 0 ]]; then
66
+if aptly publish list -raw | awk '{print $2}' | grep "^${UBUNTU_RELEASE}$"
67
+then
67 68
   aptly publish switch            \
68 69
     -batch=true \
69 70
     -passphrase="${GPG_PASSWORD}" \
70
-    ${UBUNTU_RELEASE} ${UBUNTU_RELEASE}-merged-`date +%Y%m%d%H`
71
+    "${UBUNTU_RELEASE}" "${UBUNTU_RELEASE}-merged-$REPO_DATE"
71 72
 else
72 73
   aptly publish snapshot \
73 74
     -batch=true \
74 75
     -passphrase="${GPG_PASSWORD}" \
75
-    -distribution=${UBUNTU_RELEASE} ${UBUNTU_RELEASE}-merged-`date +%Y%m%d%H`
76
+    -distribution="${UBUNTU_RELEASE}" "${UBUNTU_RELEASE}-merged-$REPO_DATE"
76 77
 fi
77
-set -e
78 78
 
79 79
 # Export the GPG Public key
80 80
 if [[ ! -f /opt/aptly/public/aptly_repo_signing.key ]]; then

Loading…
Cancel
Save