Skip to content

Commit 6d35068

Browse files
committed
chore: init repo
0 parents  commit 6d35068

File tree

6 files changed

+218
-0
lines changed

6 files changed

+218
-0
lines changed

.github/workflows/ci.yml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
---
2+
name: CI
3+
4+
permissions: {}
5+
6+
on:
7+
push:
8+
branches:
9+
- '**'
10+
paths-ignore:
11+
- "**.md"
12+
pull_request:
13+
branches:
14+
- '**'
15+
paths-ignore:
16+
- "**.md"
17+
schedule:
18+
- cron: '0 4 1 * *'
19+
# Run workflow manually
20+
workflow_dispatch:
21+
22+
jobs:
23+
test:
24+
strategy:
25+
fail-fast: false
26+
matrix:
27+
os:
28+
- ubuntu-latest
29+
- ubuntu-24.04-arm
30+
- macos-latest
31+
- macos-26-intel
32+
33+
runs-on: ${{ matrix.os }}
34+
35+
steps:
36+
- name: Test plugin
37+
uses: asdf-vm/actions/plugin-test@v3
38+
with:
39+
command: netbox-extractor --version
40+
env:
41+
GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }}

LICENSE

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
The MIT License (MIT)
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy
4+
of this software and associated documentation files (the "Software"), to deal
5+
in the Software without restriction, including without limitation the rights
6+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
copies of the Software, and to permit persons to whom the Software is
8+
furnished to do so, subject to the following conditions:
9+
10+
The above copyright notice and this permission notice shall be included in
11+
all copies or substantial portions of the Software.
12+
13+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19+
THE SOFTWARE.

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# asdf-netbox-extractor
2+
3+
[![CI](https://github.com/jbox-web/asdf-netbox-extractor/workflows/CI/badge.svg)](https://github.com/jbox-web/asdf-netbox-extractor/actions)
4+
5+
A plugin for the [asdf version manager](https://asdf-vm.com/) to install [netbox-extractor](https://github.com/jbox-web/netbox-extractor)
6+
7+
## Install
8+
9+
```
10+
asdf plugin-add netbox-extractor https://github.com/jbox-web/asdf-netbox-extractor.git
11+
```

bin/install

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/usr/bin/env bash
2+
3+
# See: https://kvz.io/bash-best-practices.html
4+
set -o errexit
5+
set -o nounset
6+
set -o pipefail
7+
8+
current_script_path=${BASH_SOURCE[0]}
9+
plugin_dir=$(dirname "$(dirname "${current_script_path}")")
10+
11+
# shellcheck source=./lib/utils.sh
12+
source "${plugin_dir}/lib/utils.sh"
13+
14+
########
15+
# MAIN #
16+
########
17+
18+
TMP_DOWNLOAD_DIR="$(mktemp -d -t \"asdf_${TOOL_NAME}_XXXXXXXX\")"
19+
20+
trap 'rm -rf "${TMP_DOWNLOAD_DIR}"' EXIT
21+
22+
install_tool "${ASDF_INSTALL_TYPE}" "${ASDF_INSTALL_VERSION}" "${ASDF_INSTALL_PATH}" "${TMP_DOWNLOAD_DIR}" "${TOOL_NAME}"

bin/list-all

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/usr/bin/env bash
2+
3+
# See: https://kvz.io/bash-best-practices.html
4+
set -o errexit
5+
set -o nounset
6+
set -o pipefail
7+
8+
current_script_path=${BASH_SOURCE[0]}
9+
plugin_dir=$(dirname "$(dirname "${current_script_path}")")
10+
11+
# shellcheck source=./lib/utils.sh
12+
source "${plugin_dir}/lib/utils.sh"
13+
14+
########
15+
# MAIN #
16+
########
17+
18+
list_all_versions

lib/utils.sh

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
TOOL_NAME="netbox-extractor"
2+
GITHUB_COORDINATES="jbox-web/${TOOL_NAME}"
3+
4+
function install_tool() {
5+
local version=${2}
6+
local install_path=${3}
7+
local tmp_download_dir=${4}
8+
local binary_name=${5}
9+
10+
local bin_install_path="${install_path}/bin"
11+
local binary_path="${bin_install_path}/${binary_name}"
12+
13+
local platform
14+
local architecture
15+
local download_url
16+
local download_path
17+
18+
platform="$(get_platform)"
19+
architecture="$(get_architecture)"
20+
filename=$(get_filename "${version}" "${platform}" "${architecture}" "${binary_name}")
21+
download_url=$(get_download_url "${version}" "${platform}" "${architecture}" "${binary_name}")
22+
download_path="${tmp_download_dir}/${filename}"
23+
24+
echo "Downloading [${binary_name}] (from ${download_url} to ${download_path})"
25+
curl -Lo "${download_path}" "${download_url}"
26+
27+
echo "Creating bin directory (${bin_install_path})"
28+
mkdir -p "${bin_install_path}"
29+
30+
echo "Cleaning previous binaries (${binary_path})"
31+
rm -f "${binary_path}" 2>/dev/null || true
32+
33+
echo "Copying binary"
34+
cp "${download_path}" "${binary_path}"
35+
chmod +x "${binary_path}"
36+
}
37+
38+
function get_filename() {
39+
local version="${1}"
40+
local platform="${2}"
41+
local architecture="${3}"
42+
local binary_name="${4}"
43+
44+
echo "${binary_name}-${platform}-${architecture}"
45+
}
46+
47+
function get_download_url() {
48+
local version="${1}"
49+
local platform="${2}"
50+
local architecture="${3}"
51+
local binary_name="${4}"
52+
53+
local filename
54+
filename="$(get_filename "${version}" "${platform}" "${architecture}" "${binary_name}")"
55+
56+
echo "https://github.com/${GITHUB_COORDINATES}/releases/download/v${version}/${filename}"
57+
}
58+
59+
function get_platform() {
60+
local platform
61+
62+
case "${OSTYPE}" in
63+
darwin*) platform="darwin" ;;
64+
linux*) platform="linux" ;;
65+
*) fail "Unsupported platform" ;;
66+
esac
67+
68+
echo "${platform}"
69+
}
70+
71+
function get_architecture() {
72+
local architecture
73+
architecture="$(uname -m)"
74+
75+
case "${architecture}" in
76+
x86_64) architecture="amd64" ;;
77+
aarch64) architecture="arm64" ;;
78+
arm64) architecture="arm64" ;;
79+
*) fail "Unsupported architecture" ;;
80+
esac
81+
82+
echo "${architecture}"
83+
}
84+
85+
# stolen from https://github.com/rbenv/ruby-build/pull/631/files#diff-fdcfb8a18714b33b07529b7d02b54f1dR942
86+
function sort_versions() {
87+
sed 'h; s/[+-]/./g; s/.p\([[:digit:]]\)/.z\1/; s/$/.z/; G; s/\n/ /' | \
88+
LC_ALL=C sort -t. -k 1,1 -k 2,2n -k 3,3n -k 4,4n -k 5,5n | awk '{print $2}'
89+
}
90+
91+
function list_all_versions() {
92+
local releases_path
93+
releases_path="https://api.github.com/repos/${GITHUB_COORDINATES}/releases"
94+
95+
local cmd
96+
cmd="curl -s"
97+
98+
if [ -n "${GITHUB_API_TOKEN:-}" ]; then
99+
cmd="${cmd} -H 'Authorization: token ${GITHUB_API_TOKEN}'"
100+
fi
101+
102+
cmd="${cmd} ${releases_path}"
103+
104+
# Fetch all tag names, and get only second column. Then remove all unnecesary characters.
105+
versions=$(eval ${cmd} | grep -oE "tag_name\": *\".{1,15}\"," | sed 's/tag_name\": *\"v//;s/\",//' | sort_versions)
106+
echo "${versions}"
107+
}

0 commit comments

Comments
 (0)