Skip to content

Commit

Permalink
feature: add installation scripts for various toolchains and generate…
Browse files Browse the repository at this point in the history
… Swagger UI

Signed-off-by: Schubert Anselme <[email protected]>
  • Loading branch information
sanselme committed Dec 7, 2024
1 parent 5f73285 commit 32f9239
Show file tree
Hide file tree
Showing 6 changed files with 189 additions and 18 deletions.
36 changes: 18 additions & 18 deletions scripts/configure.sh
Original file line number Diff line number Diff line change
Expand Up @@ -51,46 +51,46 @@ if [[ ! -d "${HOME}/.oh-my-zsh" ]]; then
fi

items=(
"modules/dotfiles/.devcontainer"
"modules/dotfiles/.editorconfig"
"modules/dotfiles/.gitignore"
"modules/dotfiles/.ssh"
"modules/dotfiles/.trunk"
"modules/dotfiles/compose-dev.yaml"
"modules/config/.devcontainer"
"modules/config/.editorconfig"
"modules/config/.gitignore"
"modules/config/.ssh"
"modules/config/.trunk"
"modules/config/compose-dev.yaml"
)
for item in "${items[@]}"; do
# copy if not present in the root directory
ls -l $(basename "${item}") >/dev/null 2>&1 || cp -r "${item}" .
done

ln -sf \
modules/dotfiles/.bashrc \
modules/dotfiles/.zshrc \
modules/dotfiles/.commitlintrc \
modules/dotfiles/.idea \
modules/dotfiles/.vscode \
modules/config/.bashrc \
modules/config/.zshrc \
modules/config/.commitlintrc \
modules/config/.idea \
modules/config/.vscode \
.

if [[ -d modules/tooling ]]; then
if [[ -d modules/toolchain ]]; then
mkdir -p config hack scripts tools

cp -f modules/tooling/.gitignore .
cp -f modules/tooling/.devcontainer/devcontainer.json .devcontainer/devcontainer.json
cp -f modules/toolchain/.gitignore .
cp -f modules/toolchain/.devcontainer/devcontainer.json .devcontainer/devcontainer.json

cd config
ln -sf ../modules/tooling/config/* .
ln -sf ../modules/toolchain/config/* .
cd -

cd hack
ln -sf ../modules/tooling/hack/* .
ln -sf ../modules/toolchain/hack/* .
cd -

cd scripts
ln -sf ../modules/tooling/scripts/* .
ln -sf ../modules/toolchain/scripts/* .
cd -

cd tools
ln -sf ../modules/tooling/tools/* .
ln -sf ../modules/toolchain/tools/* .
cd -
fi

Expand Down
57 changes: 57 additions & 0 deletions scripts/genswaggerui.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#!/bin/bash
# SPDX-License-Identifier: GPL-3.0
# ref: https://github.com/johanbrandhorst/grpc-gateway-boilerplate/blob/main/scripts/generate-swagger-ui.sh
# source scripts/aliases.sh
# source scripts/environment.sh

cache_dir=".cache/swagger-ui"
output_dir="docs/openapi"
swagger_ui_repo="https://github.com/swagger-api/swagger-ui.git"
swagger_ui_version="${1:-v5.18.2}"

escape_str() {
echo "$1" | sed -e 's/[]\/$*.^[]/\\&/g'
}

if [[ -z ${swagger_ui_version} ]]; then
echo "missing ${swagger_ui_version}"
exit 1
fi

[[ ! -d ${output_dir} ]] && mkdir -p "${output_dir}"

# cache swagger-ui dist
if [[ ! -d ${cache_dir} ]]; then
mkdir -p "${cache_dir}"
tmp="$(mktemp -d)"
git clone --depth 1 --branch "${swagger_ui_version}" "${swagger_ui_repo}" "${tmp}"
cp -r "${tmp}/dist/"* "${cache_dir}"
cp -r "${tmp}/LICENSE" "${cache_dir}"
rm -rf "${tmp}"
fi

# fixme: populate swagger.json
buf generate
tmp=" urls: ["
for i in $(find "${output_dir}" -name "*.swagger.json"); do
escaped_gen_dir="$(escape_str "${output_dir}/")"
path="${i//${escaped_gen_dir}/}"
tmp="${tmp}{\"url\":\"${path}\",\"name\":\"${path}\"},"
done
# delete last characters from $tmp
tmp="${tmp//.$/}"
tmp="${tmp}],"

# generate swagger-ui
#find "${output_dir}" -type f -name "*.swagger.json" -delete
mkdir -p "${output_dir}"
cp -r "${cache_dir}/"* "${output_dir}"

# fixme: replace the default URL
line="$(cat "${output_dir}/swagger-initializer.js" | grep -n "url" | cut -f1 -d:)"
escaped_tmp="$(escape_str "${tmp}")"
sed -i'' -e "${line} s/^.*$/${escaped_tmp}/" "${output_dir}/swagger-initializer.js"
rm -f "${output_dir}/swagger-initializer.js-e"

# fixme: optionally trunk.io
trunk fmt "${output_dir}"
20 changes: 20 additions & 0 deletions scripts/install/go.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/bash
# SPDX-License-Identifier: GPL-3.0
# source ../alias.sh
source ../environment.sh

# install golang
if [[ -z $(command -v go) ]]; then
sudo apt-get update -yq
sudo apt-get install -yq --no-install-recommends golang
fi

# install sbctl
if [[ -z $(command -v sbctl) ]]; then
# version: 0.16
# https://github.com/Foxboron/sbctl/commit/53e074d6934f5ecfffa81a576293219c717f7d19
go install github.com/foxboron/sbctl/cmd/sbctl@53e074d6934f5ecfffa81a576293219c717f7d19
fi

go version
sbctl status
23 changes: 23 additions & 0 deletions scripts/install/rust.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/bash
# SPDX-License-Identifier: GPL-3.0
# source ../alias.sh
source ../environment.sh

# install rust
if [[ -z $(command -v rustup) ]]; then
sudo apt-get update -yq
sudo apt-get install -yq --no-install-recommends rustup
fi

# set rust toolchain
if [[ -n $(command -v rustc) ]]; then
rustup default stable
rustup component add rust-src
fi

# install bindgen-cli
[[ -n $(command -v bindgen-cli) ]] || cargo install bindgen-cli

rustc --version
cargo --version
bindgen --version
28 changes: 28 additions & 0 deletions scripts/install/swift.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/bin/bash
# SPDX-License-Identifier: GPL-3.0
# source ../alias.sh
source ../environment.sh

ARCH="$(uname -m)"
SWIFT_VERSION="6.0.2"
SWIFT_STATIC_SDK_CHECKSUM="aa5515476a403797223fc2aad4ca0c3bf83995d5427fb297cab1d93c68cee075"

# install swift
if [[ -z $(command -v swift) ]]; then
curl -fsSLo /tmp/swift.tgz "https://download.swift.org/swift-${SWIFT_VERSION}-release/ubuntu2404-${ARCH}/swift-${SWIFT_VERSION}-RELEASE/swift-${SWIFT_VERSION}-RELEASE-ubuntu24.04-${ARCH}.tar.gz"
# fixme: verify download
# curl -fsSLo /tmp/swift.tgz.sig "https://download.swift.org/swift-${SWIFT_VERSION}-release/ubuntu2404-${ARCH}/swift-${SWIFT_VERSION}-RELEASE/swift-${SWIFT_VERSION}-RELEASE-ubuntu24.04-${ARCH}.tar.gz.sig"
# curl https://swift.org/keys/all-keys.asc | gpg --import -
# gpg --keyserver hkp://keyserver.ubuntu.com --refresh-keys Swift
# gpg --verify /tmp/swift.tgz.sig /tmp/swift.tgz
tar -xzf /tmp/swift.tgz -C / --strip-components=1
rm -f /tmp/swift.tgz*
fi

# static sdk
grep -q "swift-${SWIFT_VERSION}-RELEASE_static-linux-0.0.1" <(swift sdk list) || swift sdk install \
--checksum "${SWIFT_STATIC_SDK_CHECKSUM}" \
"https://download.swift.org/swift-${SWIFT_VERSION}-release/static-sdk/swift-${SWIFT_VERSION}-RELEASE/swift-${SWIFT_VERSION}-RELEASE_static-linux-0.0.1.artifactbundle.tar.gz"

swift --version
swift sdk list
43 changes: 43 additions & 0 deletions scripts/install/toolchain.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/bin/bash
# SPDX-License-Identifier: GPL-3.0
# source scripts/alias.sh
# source scripts/environment.sh

apt-get update -yq
apt-get install -yq --no-install-recommends \
binutils \
bison \
build-essential \
ccache \
clang \
cmake \
dfu-util \
flex \
gcc \
git \
gnupg2 \
gperf \
libc6-dev \
libcurl4 \
libedit2 \
libelf-dev \
libffi-dev \
libgcc-9-dev \
libncurses6 \
libsqlite3-0 \
libssl-dev \
libstdc++-9-dev \
libusb-1.0-0 \
libxml2 \
libz3-dev \
lld \
llvm \
ninja-build \
pkg-config \
python3 \
python3-pip \
python3-venv \
tzdata \
uuid-dev \
wget \
zlib1g-dev

0 comments on commit 32f9239

Please sign in to comment.