Skip to content

Commit 4e44baa

Browse files
authored
feat(installer): add ASDF installer script with README, LICENSE and GitHub workflows
1 parent 0b2bab0 commit 4e44baa

File tree

6 files changed

+203
-1
lines changed

6 files changed

+203
-1
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
---
2+
name: Bug Report
3+
about: Report a bug to help us improve
4+
title: "[BUG] "
5+
labels: bug
6+
assignees: ''
7+
---
8+
9+
**Describe the bug**
10+
A clear and concise description of what the bug is.
11+
12+
**To Reproduce**
13+
Steps to reproduce the behavior:
14+
1. Run `...`
15+
2. See error
16+
17+
**Expected behavior**
18+
A clear and concise description of what you expected to happen.
19+
20+
**Environment:**
21+
- OS: [e.g., Ubuntu 22.04, macOS Ventura]
22+
- ASDF Installer version: [e.g., v1.0]
23+
24+
**Additional context**
25+
Add any other context about the problem here.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
name: Feature Request
3+
about: Suggest a new feature for this project
4+
title: "[FEATURE] "
5+
labels: enhancement
6+
assignees: ''
7+
---
8+
9+
**Is your feature request related to a problem?**
10+
A clear and concise description of the problem.
11+
12+
**Describe the solution you'd like**
13+
What you would like to see implemented.
14+
15+
**Additional context**
16+
Add any other context or screenshots about the feature request here.

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Pull Request
2+
3+
**What does this PR do?**
4+
- [ ] Fix a bug
5+
- [ ] Add a feature
6+
- [ ] Improve documentation
7+
- [ ] Other (please describe)
8+
9+
**Summary**
10+
A brief summary of the changes.
11+
12+
**Testing steps**
13+
Steps performed to validate the changes:
14+
1. ...
15+
16+
**Related Issues**
17+
Closes # (issue number if applicable).

.github/workflows/shellcheck.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: Lint Shell Scripts
2+
3+
on:
4+
push:
5+
paths:
6+
- '**.sh'
7+
pull_request:
8+
paths:
9+
- '**.sh'
10+
11+
jobs:
12+
shellcheck:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- name: Checkout repository
16+
uses: actions/checkout@v4
17+
18+
- name: Run ShellCheck
19+
uses: ludeeus/action-shellcheck@v2
20+
with:
21+
severity: style

README.md

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,16 @@
1-
# asdf-installer
1+
# ASDF Installer – Latest Version
2+
3+
This repository provides a **simple, automated installer** for the latest version of [ASDF](https://asdf-vm.com/), a powerful version manager for multiple runtimes such as **Python, Java, Node.js, Ruby, and more**.
4+
5+
The script automatically:
6+
- Detects your **operating system** and **architecture**.
7+
- Downloads the **latest ASDF release** from GitHub.
8+
- Validates the **MD5 checksum**.
9+
- Installs ASDF into `/usr/local/bin` (or `$HOME/.local/bin` if no root access).
10+
11+
---
12+
13+
## **Quick Install**
14+
Run the command below to install ASDF:
15+
```bash
16+
curl -fsSL https://raw.githubusercontent.com/codeinloop/asdf-installer/main/install-latest-asdf.sh | bash

install-latest-asdf.sh

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
INSTALL_DIR="/usr/local/bin"
5+
6+
# --- Funções utilitárias ---
7+
log() { echo -e "\033[1;32m[INFO]\033[0m $*"; }
8+
err() { echo -e "\033[1;31m[ERROR]\033[0m $*" >&2; exit 1; }
9+
10+
# --- Instala dependências ---
11+
install_dependencies() {
12+
local pkgs=("curl" "jq" "tar" "coreutils")
13+
local missing=()
14+
for pkg in "${pkgs[@]}"; do
15+
if ! command -v "$pkg" &>/dev/null; then
16+
missing+=("$pkg")
17+
fi
18+
done
19+
20+
if [ ${#missing[@]} -gt 0 ]; then
21+
log "Instalando dependências: ${missing[*]}"
22+
if command -v apt &>/dev/null; then
23+
sudo apt update && sudo apt install -y "${missing[@]}"
24+
elif command -v yum &>/dev/null; then
25+
sudo yum install -y "${missing[@]}"
26+
elif command -v brew &>/dev/null; then
27+
brew install "${missing[@]}"
28+
else
29+
err "Gerenciador de pacotes não detectado. Instale manualmente: ${missing[*]}"
30+
fi
31+
fi
32+
}
33+
34+
# --- Detecta SO e Arquitetura ---
35+
detect_platform() {
36+
OS=$(uname | tr '[:upper:]' '[:lower:]')
37+
case "$OS" in
38+
linux*) OS="linux" ;;
39+
darwin*) OS="darwin" ;;
40+
*) err "SO não suportado: $OS" ;;
41+
esac
42+
43+
ARCH=$(uname -m)
44+
case "$ARCH" in
45+
x86_64) ARCH="amd64" ;;
46+
arm64|aarch64) ARCH="arm64" ;;
47+
*) err "Arquitetura não suportada: $ARCH" ;;
48+
esac
49+
}
50+
51+
# --- Obtém a última versão ---
52+
get_latest_tag() {
53+
curl -s https://api.github.com/repos/asdf-vm/asdf/releases/latest | jq -r '.tag_name'
54+
}
55+
56+
# --- Download e verificação de integridade ---
57+
download_asdf() {
58+
local tag="$1"
59+
ASSET_NAME="asdf-${tag}-${OS}-${ARCH}.tar.gz"
60+
ASSET_URL="https://github.com/asdf-vm/asdf/releases/download/${tag}/${ASSET_NAME}"
61+
62+
log "Baixando ${ASSET_NAME}..."
63+
curl -L -o "${ASSET_NAME}" "${ASSET_URL}"
64+
curl -L -o "${ASSET_NAME}.md5" "${ASSET_URL}.md5"
65+
66+
validate_checksum "${ASSET_NAME}" "${ASSET_NAME}.md5"
67+
}
68+
69+
# --- Valida o checksum ---
70+
validate_checksum() {
71+
local file="$1"
72+
local md5_file="$2"
73+
local expected_md5
74+
expected_md5=$(tr -d '\n\r' < "$md5_file")
75+
76+
local file_md5
77+
if [[ "$OS" == "darwin" ]]; then
78+
file_md5=$(md5 -q "$file")
79+
else
80+
file_md5=$(md5sum "$file" | awk '{print $1}')
81+
fi
82+
83+
if [[ "$expected_md5" != "$file_md5" ]]; then
84+
err "Falha na validação do checksum MD5! Esperado: $expected_md5 | Obtido: $file_md5"
85+
fi
86+
log "Checksum MD5 validado com sucesso!"
87+
}
88+
89+
# --- Instalação ---
90+
install_asdf() {
91+
log "Instalando em ${INSTALL_DIR}..."
92+
sudo tar --strip-components=1 -xzf "${ASSET_NAME}" -C "${INSTALL_DIR}"
93+
log "ASDF instalado em ${INSTALL_DIR}/asdf"
94+
}
95+
96+
# --- Fluxo principal ---
97+
main() {
98+
install_dependencies
99+
detect_platform
100+
local latest_tag
101+
latest_tag=$(get_latest_tag)
102+
log "Instalando ASDF versão ${latest_tag} para ${OS}-${ARCH}"
103+
download_asdf "$latest_tag"
104+
install_asdf
105+
log "Verifique a instalação com: asdf --version"
106+
}
107+
108+
main "$@"

0 commit comments

Comments
 (0)