Skip to content

Commit

Permalink
Merge pull request #16120 from MinaProtocol/dw/easy-shell-changes-dev…
Browse files Browse the repository at this point in the history
…elop

[easy/develop] Make shellcheck happier on scripts/debian/*.sh
  • Loading branch information
dannywillems authored Sep 25, 2024
2 parents 7abd4a1 + c338c26 commit 6bc80ac
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 73 deletions.
53 changes: 26 additions & 27 deletions scripts/debian/aptly.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ CLEAR='\033[0m'
RED='\033[0;31m'

# global variables
declare CLI_VERSION='1.0.0';
declare CLI_NAME='aptly.sh';
declare PS4='debug($LINENO) ${FUNCNAME[0]:+${FUNCNAME[0]}}(): ';

Expand All @@ -34,28 +33,28 @@ function start_aptly() {
local __background=$3
local __clean=$4
local __component=$5
local __repo="$__distribution-$__component"
local __repo="${__distribution}"-"${__component}"
local __port=$6

if [ $__clean = 1 ]; then
if [ "${__clean}" = 1 ]; then
rm -rf ~/.aptly
fi

aptly repo create -component $__component -distribution $__distribution $__repo

aptly repo add $__repo $__debs
aptly repo create -component "${__component}" -distribution "${__distribution}" "${__repo}"

aptly snapshot create $__component from repo $__repo
aptly repo add "${__repo}" "${__debs}"

aptly publish snapshot -distribution=$__distribution -skip-signing $__component
aptly snapshot create "${__component}" from repo "${__repo}"

if [ $__background = 1 ]; then
aptly serve -listen localhost:$__port &
else
aptly serve -listen localhost:$__port
aptly publish snapshot -distribution="${__distribution}" -skip-signing "${__component}"

if [ "${__background}" = 1 ]; then
aptly serve -listen localhost:"${__port}" &
else
aptly serve -listen localhost:"${__port}"
fi


}


Expand Down Expand Up @@ -91,15 +90,15 @@ function start(){
local __clean=0
local __component="unstable"
local __port=$PORT


while [ ${#} -gt 0 ]; do
error_message="Error: a value is needed for '$1'";
case $1 in
-h | --help )
start_help;
;;
-b | --background )
-b | --background )
__background=1
shift;
;;
Expand Down Expand Up @@ -130,13 +129,13 @@ function start(){
;;
esac
done
start_aptly $__distribution \
$__debs \
$__background \
$__clean \
$__component \
$__port

start_aptly "${__distribution}" \
"${__debs}" \
"${__background}" \
"${__clean}" \
"${__component}" \
"${__port}"


}
Expand All @@ -156,9 +155,9 @@ function stop_help(){
}

function stop(){

local __clean=0

while [ ${#} -gt 0 ]; do
case $1 in
-h | --help )
Expand All @@ -175,9 +174,9 @@ function stop(){
;;
esac
done

pkill aptly
if [ $__clean = 1 ]; then
if [ "${__clean}" = 1 ]; then
rm -rf ~/.aptly
fi
}
Expand Down Expand Up @@ -215,4 +214,4 @@ function main(){
esac
}

main "$@";
main "$@";
22 changes: 11 additions & 11 deletions scripts/debian/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@ SCRIPTPATH="$( cd "$(dirname "$0")" ; pwd -P )"

# In case of running this script on detached head, script has difficulties in finding out
# what is the current branch.
if [[ -n "$BRANCH_NAME" ]]; then
BRANCH_NAME="$BRANCH_NAME" source ${SCRIPTPATH}/../export-git-env-vars.sh
if [[ -n "${BRANCH_NAME}" ]]; then
BRANCH_NAME="${BRANCH_NAME}" source "${SCRIPTPATH}"/../export-git-env-vars.sh
else
source ${SCRIPTPATH}/../export-git-env-vars.sh
fi
source "${SCRIPTPATH}"/../export-git-env-vars.sh
fi

echo "after export"

source ${SCRIPTPATH}/builder-helpers.sh
source "${SCRIPTPATH}"/builder-helpers.sh

if [ $# -eq 0 ]
then
echo "No arguments supplied. Building all known debian packages"
Expand All @@ -31,15 +31,15 @@ if [ $# -eq 0 ]
build_functional_test_suite_deb
build_zkapp_test_transaction_deb

else
else
for i in "$@"; do
if [[ $(type -t "build_${i}_deb") == function ]]
then
if [[ $(type -t "build_${i}_deb") == function ]]
then
echo "Building $i debian package"
"build_${i}_deb"
else
else
echo "invalid debian package name '$i'"
exit 1
fi
done
fi
fi
43 changes: 22 additions & 21 deletions scripts/debian/builder-helpers.sh
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ if [[ -v DUNE_INSTRUMENT_WITH ]]; then
INSTRUMENTED_SUFFIX=instrumented
MINA_DEB_NAME="${MINA_DEB_NAME}-${INSTRUMENTED_SUFFIX}"
DEB_SUFFIX="${DEB_SUFFIX}-${INSTRUMENTED_SUFFIX}"
fi
fi

BUILDDIR="deb_build"

Expand Down Expand Up @@ -123,9 +123,9 @@ build_deb() {

# Build the package
echo "------------------------------------------------------------"
fakeroot dpkg-deb --build "${BUILDDIR}" ${1}_${MINA_DEB_VERSION}.deb
fakeroot dpkg-deb --build "${BUILDDIR}" "${1}"_"${MINA_DEB_VERSION}".deb
echo "build_deb outputs:"
ls -lh ${1}_*.deb
ls -lh "${1}"_*.deb
echo "deleting BUILDDIR ${BUILDDIR}"
rm -rf "${BUILDDIR}"

Expand All @@ -148,7 +148,7 @@ copy_common_daemon_configs() {
cp ./default/src/app/validate_keypair/validate_keypair.exe "${BUILDDIR}/usr/local/bin/mina-validate-keypair"

# Copy signature-based Binaries (based on signature type $2 passed into the function)
cp ./default/src/app/cli/src/mina_${2}_signatures.exe "${BUILDDIR}/usr/local/bin/mina"
cp ./default/src/app/cli/src/mina_"${2}"_signatures.exe "${BUILDDIR}/usr/local/bin/mina"

# Copy over Build Configs (based on $2)
mkdir -p "${BUILDDIR}/etc/coda/build_config"
Expand All @@ -162,7 +162,7 @@ copy_common_daemon_configs() {
cp ../genesis_ledgers/mainnet.json "${BUILDDIR}/var/lib/coda/mainnet.json"
cp ../genesis_ledgers/devnet.json "${BUILDDIR}/var/lib/coda/devnet.json"
# Set the default configuration based on Network name ($1)
cp ../genesis_ledgers/${1}.json "${BUILDDIR}/var/lib/coda/config_${GITHASH_CONFIG}.json"
cp ../genesis_ledgers/"${1}".json "${BUILDDIR}/var/lib/coda/config_${GITHASH_CONFIG}.json"
cp ../scripts/hardfork/create_runtime_config.sh "${BUILDDIR}/usr/local/bin/mina-hf-create-runtime-config"
cp ../scripts/mina-verify-packaged-fork-config "${BUILDDIR}/usr/local/bin/mina-verify-packaged-fork-config"
# Update the mina.service with a new default PEERS_URL based on Seed List URL $3
Expand Down Expand Up @@ -240,7 +240,7 @@ build_functional_test_suite_deb() {

mkdir -p "${BUILDDIR}/etc/mina/test/archive"

cp -r ../src/test/archive/* ${BUILDDIR}/etc/mina/test/archive/
cp -r ../src/test/archive/* "${BUILDDIR}"/etc/mina/test/archive/

# Binaries
cp ./default/src/test/command_line_tests/command_line_tests.exe "${BUILDDIR}/usr/local/bin/mina-command-line-tests"
Expand All @@ -252,11 +252,11 @@ build_functional_test_suite_deb() {
##################################### END TEST SUITE PACKAGE #######################################

function copy_common_rosetta_configs () {
# Copy rosetta-based Binaries
cp ./default/src/app/rosetta/rosetta_${1}_signatures.exe "${BUILDDIR}/usr/local/bin/mina-rosetta"
cp ./default/src/app/rosetta/ocaml-signer/signer_${1}_signatures.exe "${BUILDDIR}/usr/local/bin/mina-ocaml-signer"

# Copy rosetta-based Binaries
cp ./default/src/app/rosetta/rosetta_"${1}"_signatures.exe "${BUILDDIR}/usr/local/bin/mina-rosetta"
cp ./default/src/app/rosetta/ocaml-signer/signer_"${1}"_signatures.exe "${BUILDDIR}/usr/local/bin/mina-ocaml-signer"

mkdir -p "${BUILDDIR}/etc/mina/rosetta"
mkdir -p "${BUILDDIR}/etc/mina/rosetta/rosetta-cli-config"
mkdir -p "${BUILDDIR}/etc/mina/rosetta/scripts"
Expand All @@ -266,38 +266,38 @@ function copy_common_rosetta_configs () {
cp ../src/app/rosetta/rosetta-cli-config/*.json "${BUILDDIR}/etc/mina/rosetta/rosetta-cli-config"
cp ../src/app/rosetta/rosetta-cli-config/*.ros "${BUILDDIR}/etc/mina/rosetta/rosetta-cli-config"
cp ./default/src/app/rosetta/indexer_test/indexer_test.exe "${BUILDDIR}/usr/local/bin/mina-rosetta-indexer-test"

}

##################################### ROSETTA MAINNET PACKAGE #######################################
build_rosetta_mainnet_deb() {

echo "------------------------------------------------------------"
echo "--- Building mainnet rosetta deb"

create_control_file mina-rosetta-mainnet "${SHARED_DEPS}" 'Mina Protocol Rosetta Client' "${SUGGESTED_DEPS}"

copy_common_rosetta_configs "mainnet"

build_deb mina-rosetta-mainnet
}

##################################### ROSETTA MAINNET PACKAGE #######################################
build_rosetta_devnet_deb() {

echo "------------------------------------------------------------"
echo "--- Building devnet rosetta deb"

create_control_file mina-rosetta-devnet "${SHARED_DEPS}" 'Mina Protocol Rosetta Client' "${SUGGESTED_DEPS}"

copy_common_rosetta_configs "testnet"

build_deb mina-rosetta-devnet
}

##################################### MAINNET PACKAGE #######################################
build_daemon_mainnet_deb() {

echo "------------------------------------------------------------"
echo "--- Building mainnet deb without keys:"

Expand All @@ -311,7 +311,7 @@ build_daemon_mainnet_deb() {

##################################### DEVNET PACKAGE #######################################
build_daemon_devnet_deb() {

echo "------------------------------------------------------------"
echo "--- Building testnet signatures deb without keys:"

Expand All @@ -337,12 +337,13 @@ build_archive_deb () {
cp ./default/src/app/archive/archive.exe "${BUILDDIR}/usr/local/bin/mina-archive"
cp ./default/src/app/archive_blocks/archive_blocks.exe "${BUILDDIR}/usr/local/bin/mina-archive-blocks"
cp ./default/src/app/extract_blocks/extract_blocks.exe "${BUILDDIR}/usr/local/bin/mina-extract-blocks"

mkdir -p "${BUILDDIR}/etc/mina/archive"
cp ../scripts/archive/missing-blocks-guardian.sh "${BUILDDIR}/usr/local/bin/mina-missing-blocks-guardian"

cp ./default/src/app/missing_blocks_auditor/missing_blocks_auditor.exe "${BUILDDIR}/usr/local/bin/mina-missing-blocks-auditor"
cp ./default/src/app/replayer/replayer.exe "${BUILDDIR}/usr/local/bin/mina-replayer"

cp ../src/app/archive/create_schema.sql "${BUILDDIR}/etc/mina/archive"
cp ../src/app/archive/drop_tables.sql "${BUILDDIR}/etc/mina/archive"

Expand All @@ -360,6 +361,6 @@ build_zkapp_test_transaction_deb () {
# Binaries
cp ./default/src/app/zkapp_test_transaction/zkapp_test_transaction.exe "${BUILDDIR}/usr/local/bin/mina-zkapp-test-transaction"

build_deb mina-zkapp-test-transaction
build_deb mina-zkapp-test-transaction
}
##################################### END ZKAPP TEST TXN PACKAGE #######################################
18 changes: 8 additions & 10 deletions scripts/debian/publish.sh
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ DEBS3_UPLOAD="deb-s3 upload $BUCKET_ARG $S3_REGION_ARG \
echo "Publishing debs: ${DEB_NAMES} to Release: ${DEB_RELEASE} and Codename: ${DEB_CODENAME}"
# Upload the deb files to s3.
# If this fails, attempt to remove the lockfile and retry.
for i in {1..10}; do (
for _i in {1..10}; do (
${DEBS3_UPLOAD} \
--component "${DEB_RELEASE}" \
--codename "${DEB_CODENAME}" \
Expand All @@ -62,23 +62,21 @@ for i in {1..10}; do (
# Verify integrity of debs on remote repo
function verify_o1test_repo_has_package {
sudo apt-get update
${DEBS3_SHOW} ${1} ${DEB_VERSION} $ARCH -c $DEB_CODENAME -m $DEB_RELEASE
${DEBS3_SHOW} "${1}" "${DEB_VERSION}" ${ARCH} -c "${DEB_CODENAME}" -m "${DEB_RELEASE}"
return $?
}

for deb in $DEB_NAMES
do
echo "Adding packages.o1test.net $DEB_CODENAME $DEB_RELEASE"
sudo echo "deb [trusted=yes] http://packages.o1test.net $DEB_CODENAME $DEB_RELEASE" | sudo tee /etc/apt/sources.list.d/mina.list
echo "Adding packages.o1test.net ${DEB_CODENAME} ${DEB_RELEASE}"
sudo echo "deb [trusted=yes] http://packages.o1test.net ${DEB_CODENAME} ${DEB_RELEASE}" | sudo tee /etc/apt/sources.list.d/mina.list

DEBS3_SHOW="deb-s3 show $BUCKET_ARG $S3_REGION_ARG"

deb_split=(${deb//_/ })
deb_split=("${deb//_/ }")
deb="${deb_split[0]}"
deb=$(basename $deb)

for i in {1..10}; do (verify_o1test_repo_has_package $deb) && break || sleep 60; done

done
deb=$(basename "${deb}")

for _i in {1..10}; do (verify_o1test_repo_has_package "${deb}") && break || sleep 60; done

done
6 changes: 3 additions & 3 deletions scripts/debian/reversion.sh
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ if [[ -z "$SUITE" ]]; then NEW_SUITE=$SUITE; fi;
function rebuild_deb() {
rm -f "${DEB}_${VERSION}.deb"
rm -rf "${NEW_NAME}_${NEW_VERSION}"
wget https://s3.us-west-2.amazonaws.com/packages.o1test.net/pool/${CODENAME}/m/mi/${DEB}_${VERSION}.deb

wget https://s3.us-west-2.amazonaws.com/packages.o1test.net/pool/"${CODENAME}"/m/mi/"${DEB}"_"${VERSION}".deb
dpkg-deb -R "${DEB}_${VERSION}.deb" "${NEW_NAME}_${NEW_VERSION}"
sed -i 's/Version: '"${VERSION}"'/Version: '"${NEW_VERSION}"'/g' "${NEW_NAME}_${NEW_VERSION}/DEBIAN/control"
sed -i 's/Package: '"${DEB}"'/Package: '"${NEW_NAME}"'/g' "${NEW_NAME}_${NEW_VERSION}/DEBIAN/control"
Expand All @@ -60,4 +60,4 @@ function rebuild_deb() {

rebuild_deb

source scripts/debian/publish.sh --names "${NEW_NAME}_${NEW_VERSION}.deb" --version ${NEW_VERSION} --codename ${CODENAME} --release ${NEW_RELEASE}
source scripts/debian/publish.sh --names "${NEW_NAME}_${NEW_VERSION}.deb" --version "${NEW_VERSION}" --codename "${CODENAME}" --release "${NEW_RELEASE}"
2 changes: 1 addition & 1 deletion scripts/debian/verify.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ while [[ "$#" -gt 0 ]]; do case $1 in
*) echo "Unknown parameter passed: $1"; exit 1;;
esac; shift; done

if [ -z $PACKAGE ]; then
if [ -z "${PACKAGE}" ]; then
echo "No package defined. exiting.."; exit 1;
fi

Expand Down

0 comments on commit 6bc80ac

Please sign in to comment.