diff --git a/scripts/configure.sh b/scripts/configure.sh index 5c941a2..1e36b06 100755 --- a/scripts/configure.sh +++ b/scripts/configure.sh @@ -51,12 +51,12 @@ 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 @@ -64,33 +64,33 @@ for item in "${items[@]}"; do 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 diff --git a/scripts/genswaggerui.sh b/scripts/genswaggerui.sh new file mode 100755 index 0000000..5b3ca4b --- /dev/null +++ b/scripts/genswaggerui.sh @@ -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}" diff --git a/scripts/install/go.sh b/scripts/install/go.sh new file mode 100755 index 0000000..49b733f --- /dev/null +++ b/scripts/install/go.sh @@ -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 diff --git a/scripts/install/rust.sh b/scripts/install/rust.sh new file mode 100755 index 0000000..c4ea0ab --- /dev/null +++ b/scripts/install/rust.sh @@ -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 diff --git a/scripts/install/swift.sh b/scripts/install/swift.sh new file mode 100755 index 0000000..9c314b3 --- /dev/null +++ b/scripts/install/swift.sh @@ -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 diff --git a/scripts/install/toolchain.sh b/scripts/install/toolchain.sh new file mode 100755 index 0000000..3a2814d --- /dev/null +++ b/scripts/install/toolchain.sh @@ -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