|
1 | | -#!/bin/bash |
| 1 | +#!/usr/bin/env bash |
2 | 2 | # Copyright 2022-2025 Salesforce, Inc. |
3 | 3 | # |
4 | 4 | # Licensed under the Apache License, Version 2.0 (the "License"); |
|
12 | 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
13 | 13 | # See the License for the specific language governing permissions and |
14 | 14 | # limitations under the License. |
15 | | -set -eo |
| 15 | +set -e |
16 | 16 |
|
17 | 17 | # USAGE: |
18 | 18 | # ./scripts/archive.sh <artifact path> <release version> |
19 | 19 | # |
20 | 20 | # EXAMPLES: |
21 | | -# This script now executed inside goreleaser, if you need to run the script alone, make sure you have macOS and Linux original archives in your artificate path |
22 | | -# - ./scripts/archive.sh /artifacts 1.5.0 |
| 21 | +# Artifacts are built with GoReleaser and must exist before running this |
| 22 | +# script: |
| 23 | +# |
| 24 | +# $ make build-snapshot |
| 25 | +# $ ./scripts/archive.sh ./dist 3.3.0 |
23 | 26 | # |
24 | 27 | # DESCRIPTION: |
25 | | -# Create the development and production tar.gz archives used by the `install.sh` and `install-dev.sh`scripts. |
| 28 | +# Create the development and production tar.gz and zip archives. These are |
| 29 | +# used in the `install.sh` and `install-dev.sh` scripts. |
26 | 30 | # |
27 | | -# Generates macOS and Linux archives. |
28 | | - |
29 | | -# After generating the archive for macOS, the script will test the archive by |
30 | | -# extracting it and looking for `bin/slack` |
31 | | -# Linux archive is generated directorily from original binary, |
32 | | -# the script will check if `bin/slack` for Linux exits or not first |
| 31 | +# Tests for correct packaging is done with the `archive-test.sh` script. |
33 | 32 |
|
34 | 33 | DIST_DIR=${1} |
35 | 34 |
|
36 | 35 | main() { |
37 | 36 | if [ $# -lt 2 ]; then |
38 | | - echo "Missing parameters" |
| 37 | + echo "Missing parameters: $0 <path> <version>" |
39 | 38 | exit 1 |
40 | 39 | fi |
41 | 40 |
|
42 | 41 | VERSION=${2} |
43 | 42 |
|
44 | | - echo "Creating macOS archives:" |
45 | | - |
46 | | - mac_src_file_path="$DIST_DIR/slack_cli_${VERSION}_macOS_64-bit.zip" |
47 | | - echo "-> Source archive: $mac_src_file_path" |
48 | | - |
49 | | - mac_targz_dir_path="$DIST_DIR/slack_mac_64-bit" |
50 | | - macos_dev_targz_file_path="$DIST_DIR/slack_cli_dev_macOS_64-bit.tar.gz" |
51 | | - macos_prod_targz_file_path="$DIST_DIR/slack_cli_latest_macOS_64-bit.tar.gz" |
52 | | - macos_prod_targz_file_path_2="$DIST_DIR/slack_cli_${VERSION}_macOS_64-bit.tar.gz" |
53 | | - macos_prod_zip_file_path="$DIST_DIR/slack_cli_${VERSION}_macos.zip" |
54 | | - |
55 | | - echo "-> Creating dist directory: $mac_targz_dir_path" |
56 | | - mkdir -p "$mac_targz_dir_path" |
57 | | - |
58 | | - echo "-> Extracting: $mac_targz_dir_path" |
59 | | - unzip "$mac_src_file_path" -d "$mac_targz_dir_path" |
60 | | - |
61 | | - echo "-> Moving $mac_targz_dir_path/slack to $mac_targz_dir_path/bin/slack" |
62 | | - mkdir "$mac_targz_dir_path/bin" |
63 | | - mv "$mac_targz_dir_path/slack" "$mac_targz_dir_path/bin/slack" |
64 | | - |
65 | | - echo "-> Creating macOS development tar.gz file: $macos_dev_targz_file_path" |
66 | | - tar -C "$mac_targz_dir_path" -zcvf "$macos_dev_targz_file_path" . |
67 | | - |
68 | | - echo "-> Creating macOS production tar.gz file: $macos_prod_targz_file_path" |
69 | | - tar -C "$mac_targz_dir_path" -zcvf "$macos_prod_targz_file_path" . |
70 | | - tar -C "$mac_targz_dir_path" -zcvf "$macos_prod_targz_file_path_2" . |
71 | | - |
72 | | - echo "-> Creating macOS .zip file with old name for auto-update: |
73 | | - $macos_prod_zip_file_path" |
74 | | - cp -i "$mac_src_file_path" "$macos_prod_zip_file_path" |
75 | | - |
76 | | - echo "-> Cleaning up: $mac_targz_dir_path" |
77 | | - rm -R "$mac_targz_dir_path" |
78 | | - |
79 | | - echo "-> Testing macOs development tar.gz file..." |
80 | | - mkdir "$mac_targz_dir_path" |
81 | | - tar -zxvf "$macos_dev_targz_file_path" -C "$mac_targz_dir_path" |
82 | | - |
83 | | - if [ $(command -v "$mac_targz_dir_path/bin/slack") ]; then |
84 | | - echo "-> Found bin/slack" |
85 | | - rm -R "$mac_targz_dir_path" |
86 | | - else |
87 | | - echo "-> Missing development bin/slack" |
88 | | - fi |
89 | | - |
90 | | - echo "-> Testing macOs production tar.gz file..." |
91 | | - mkdir "$mac_targz_dir_path" |
92 | | - tar -zxvf "$macos_prod_targz_file_path" -C "$mac_targz_dir_path" |
93 | | - |
94 | | - if [ $(command -v "$mac_targz_dir_path/bin/slack") ]; then |
95 | | - echo "-> Found bin/slack" |
96 | | - rm -R "$mac_targz_dir_path" |
97 | | - else |
98 | | - echo "-> Missing production bin/slack" |
99 | | - fi |
100 | | - |
101 | | - echo "-> Everything looks good!" |
102 | | - echo "-> macOS archive: $targz_file_path" |
103 | | - |
104 | | - echo "Creating Linux archives:" |
105 | | - |
106 | | - linux_src_file_path="$DIST_DIR/slack_cli_${VERSION}_linux_64-bit.tar.gz" |
107 | | - linux_dev_targz_file_path="$DIST_DIR/slack_cli_dev_linux_64-bit.tar.gz" |
108 | | - linux_prod_targz_file_path="$DIST_DIR/slack_cli_latest_linux_64-bit.tar.gz" |
109 | | - |
110 | | - if [ -f "$linux_src_file_path" ]; then |
111 | | - echo "-> Found linux binary archive" |
112 | | - else |
113 | | - echo "-> Missing linux binary archive" |
114 | | - exit |
115 | | - fi |
116 | | - |
117 | | - echo "-> Creating development Linux tar.gz file: $linux_dev_targz_file_path" |
118 | | - cp "$linux_src_file_path" "$linux_dev_targz_file_path" |
119 | | - echo "-> Linux development archive: $linux_dev_targz_file_path" |
| 43 | + echo "Creating macOS archives" |
| 44 | + |
| 45 | + macos_targz_file_path_version_universal="$DIST_DIR/slack_cli_${VERSION}_macOS_64-bit.tar.gz" |
| 46 | + macos_targz_file_path_version_amd64="$DIST_DIR/slack_cli_${VERSION}_macOS_amd64.tar.gz" |
| 47 | + macos_targz_file_path_version_arm64="$DIST_DIR/slack_cli_${VERSION}_macOS_arm64.tar.gz" |
| 48 | + macos_targz_file_path_dev_universal="$DIST_DIR/slack_cli_dev_macOS_64-bit.tar.gz" |
| 49 | + macos_targz_file_path_dev_amd64="$DIST_DIR/slack_cli_dev_macOS_amd64.tar.gz" |
| 50 | + macos_targz_file_path_dev_arm64="$DIST_DIR/slack_cli_dev_macOS_arm64.tar.gz" |
| 51 | + macos_targz_file_path_latest_universal="$DIST_DIR/slack_cli_latest_macOS_64-bit.tar.gz" |
| 52 | + macos_targz_file_path_latest_amd64="$DIST_DIR/slack_cli_latest_macOS_amd64.tar.gz" |
| 53 | + macos_targz_file_path_latest_arm64="$DIST_DIR/slack_cli_latest_macOS_arm64.tar.gz" |
| 54 | + |
| 55 | + macos_zip_file_path_universal="$DIST_DIR/slack_cli_${VERSION}_macOS_64-bit.zip" |
| 56 | + macos_zip_file_path_amd64="$DIST_DIR/slack_cli_${VERSION}_macOS_amd64.zip" |
| 57 | + macos_zip_file_path_arm64="$DIST_DIR/slack_cli_${VERSION}_macOS_arm64.zip" |
| 58 | + macos_zip_file_path_universal_legacy="$DIST_DIR/slack_cli_${VERSION}_macos.zip" |
| 59 | + |
| 60 | + echo "-> Creating macOS versioned tar.gz files" |
| 61 | + unzip_tar "$macos_zip_file_path_universal" "$macos_targz_file_path_version_universal" |
| 62 | + unzip_tar "$macos_zip_file_path_amd64" "$macos_targz_file_path_version_amd64" |
| 63 | + unzip_tar "$macos_zip_file_path_arm64" "$macos_targz_file_path_version_arm64" |
| 64 | + ls -l "$DIST_DIR"/*_"$VERSION"_macOS* |
| 65 | + |
| 66 | + echo "-> Creating macOS development tar.gz files" |
| 67 | + cp "$macos_targz_file_path_version_universal" "$macos_targz_file_path_dev_universal" |
| 68 | + cp "$macos_targz_file_path_version_amd64" "$macos_targz_file_path_dev_amd64" |
| 69 | + cp "$macos_targz_file_path_version_arm64" "$macos_targz_file_path_dev_arm64" |
| 70 | + ls -l "$DIST_DIR"/*dev_macOS* |
| 71 | + |
| 72 | + echo "-> Creating macOS latest tar.gz files" |
| 73 | + cp "$macos_targz_file_path_version_universal" "$macos_targz_file_path_latest_universal" |
| 74 | + cp "$macos_targz_file_path_version_amd64" "$macos_targz_file_path_latest_amd64" |
| 75 | + cp "$macos_targz_file_path_version_arm64" "$macos_targz_file_path_latest_arm64" |
| 76 | + ls -l "$DIST_DIR"/*latest_macOS* |
| 77 | + |
| 78 | + echo "-> Creating macOS legacy .zip file for auto-update" |
| 79 | + cp "$macos_zip_file_path_universal" "$macos_zip_file_path_universal_legacy" |
| 80 | + ls -l "$DIST_DIR"/*_macos.zip |
| 81 | + |
| 82 | + echo "Creating Linux archives" |
| 83 | + |
| 84 | + linux_targz_file_path_version="$DIST_DIR/slack_cli_${VERSION}_linux_64-bit.tar.gz" |
| 85 | + linux_targz_file_path_dev="$DIST_DIR/slack_cli_dev_linux_64-bit.tar.gz" |
| 86 | + linux_targz_file_path_latest="$DIST_DIR/slack_cli_latest_linux_64-bit.tar.gz" |
| 87 | + |
| 88 | + echo "-> Creating Linux development tar.gz file" |
| 89 | + cp "$linux_targz_file_path_version" "$linux_targz_file_path_dev" |
| 90 | + ls -l "$DIST_DIR"/*dev_linux* |
| 91 | + |
| 92 | + echo "-> Creating Linux production tar.gz file" |
| 93 | + cp "$linux_targz_file_path_version" "$linux_targz_file_path_latest" |
| 94 | + ls -l "$DIST_DIR"/*latest_linux* |
| 95 | +} |
120 | 96 |
|
121 | | - echo "-> Creating production Linux tar.gz file: $linux_prod_targz_file_path" |
122 | | - cp "$linux_src_file_path" "$linux_prod_targz_file_path" |
123 | | - echo "-> Linux development archive: $linux_prod_targz_file_path" |
| 97 | +# Repackage tarballs with the signed zip |
| 98 | +unzip_tar() { |
| 99 | + tmpdir="$(mktemp -d)" |
| 100 | + trap 'rm -rf "$tmpdir"' EXIT |
| 101 | + unzip "$1" -d "$tmpdir" |
| 102 | + mkdir "$tmpdir/bin" |
| 103 | + mv "$tmpdir/slack" "$tmpdir/bin/slack" |
| 104 | + tar -C "$tmpdir" -zcvf "$2" . |
124 | 105 | } |
125 | 106 |
|
126 | 107 | main "$@" |
0 commit comments