Update and refactory protoc

main
Buddy 1 week ago
parent c1f74f2cb7
commit e54315b4bf

@ -5,47 +5,19 @@ set -euo pipefail
# shellcheck disable=SC1091 # shellcheck disable=SC1091
source "${XDG_DATA_HOME}/buddy-up/includes/utils.sh" source "${XDG_DATA_HOME}/buddy-up/includes/utils.sh"
VERSION=${VERSION:-29.2}
APP=protoc APP=protoc
APPS_DIR=${XDG_DATA_HOME}/apps/releases/${APP} VERSION=${VERSION:-29.3}
VER_DIR=${APPS_DIR}/${VERSION} DEST=${XDG_DATA_HOME}/apps/releases/${APP}
main() ( main() (
ZIP=protoc-${VERSION}-$(get_os)-$(get_arch).zip URL=https://github.com/protocolbuffers/protobuf/releases/download/v${VERSION}/protoc-${VERSION}-$(get_os)-$(get_arch).zip
TMP_DIR=$(mktemp -d) XDG_INCLUDE_HOME="${XDG_INCLUDE_HOME:=$HOME/.local/include}"
DEST_FILE=$TMP_DIR/$ZIP mkdir_if_missing "${XDG_INCLUDE_HOME}"
URL=https://github.com/protocolbuffers/protobuf/releases/download/v${VERSION}/${ZIP}
extract_zip "${URL}" "${DEST}/${VERSION}"
if [[ ! -d ${VER_DIR} ]]; then set_current_link "${DEST}" "${VERSION}"
curl --output "${DEST_FILE}" --location "${URL}" set_link "${XDG_BIN_HOME}/${APP}" "${DEST}" "bin/${APP}"
mkdir -p "${VER_DIR}" set_link "${XDG_INCLUDE_HOME}/google" "${DEST}" include/google
unzip -o "${DEST_FILE}" -d "${VER_DIR}"
find "${VER_DIR}" -type f -exec chmod 644 {} \;
find "${VER_DIR}" -type d -exec chmod 755 {} \;
find "${VER_DIR}/bin" -type f -exec chmod 755 {} \;
fi
rm -rfv "$TMP_DIR"
set_current_link "${APPS_DIR}" "${VERSION}"
apps=$(find "${APPS_DIR}/current/bin" -maxdepth 1 -type f -exec basename {} \;)
pushd "${XDG_BIN_HOME}"
for bin in $apps; do
if [[ ! -s $bin ]]; then
ln -s \
"$(relative_path "${XDG_BIN_HOME}" "${APPS_DIR}/current/bin/${bin}")" \
"${bin}"
fi
done
popd
pushd "${XDG_INCLUDE_HOME}"
if [[ ! -s google ]]; then
ln -s \
"$(relative_path "${XDG_INCLUDE_HOME}" "${APPS_DIR}/current/include/google")" \
google
fi
popd
) )
get_os() ( get_os() (
@ -54,13 +26,17 @@ get_os() (
Darwin*) echo osx ;; Darwin*) echo osx ;;
*) *)
echo >&2 "unsupported os" echo >&2 "unsupported os"
return exit 1
;; ;;
esac esac
) )
get_arch() ( get_arch() (
uname -m ARCH=$(uname -m)
if [[ $ARCH == arm64 ]]; then
ARCH=aarch_64
fi
echo "$ARCH"
) )
main "${@}" main

Loading…
Cancel
Save