mirror of
https://github.com/mr0xb/scripts.git
synced 2026-08-27 19:34:57 -04:00
initial commit
This commit is contained in:
commit
2f723ac7ee
5 changed files with 165 additions and 0 deletions
2
README.md
Normal file
2
README.md
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
# scripts
|
||||
Random scripts for personal use
|
||||
10
install/install-gh
Executable file
10
install/install-gh
Executable file
|
|
@ -0,0 +1,10 @@
|
|||
#!/bin/sh
|
||||
|
||||
curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | \
|
||||
sudo dd of=/etc/apt/trusted.gpg.d/githubcli-archive-keyring.gpg
|
||||
|
||||
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/trusted.gpg.d/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | \
|
||||
sudo tee /etc/apt/sources.list.d/github-cli.list > /dev/null
|
||||
|
||||
sudo apt update
|
||||
sudo apt install gh
|
||||
52
install/install-go
Executable file
52
install/install-go
Executable file
|
|
@ -0,0 +1,52 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
# Installs the latest Go release into $TARGETDIR (default: ~/.local)
|
||||
# without requiring root access. Assumes the following suggested
|
||||
# environment variables (which need to be set or changed in this script
|
||||
# or after install completes):
|
||||
#
|
||||
# PATH="~/.local/bin:~/.local/bin/go/bin:$PATH"
|
||||
# GOOS=linux
|
||||
# GOARCH=amd64
|
||||
# GOPATH="~/.local/go"
|
||||
# GOBIN="~/.local/go/bin"
|
||||
#
|
||||
# Note that the downloaded tar file is not removed and can be found in
|
||||
# either $DOWNLOADS or /tmp.
|
||||
|
||||
true "${TARGETDIR:="$HOME/.local"}"
|
||||
|
||||
# change this to your target (detecting not always reliable)
|
||||
declare GOOS=linux
|
||||
declare GOARCH=amd64
|
||||
|
||||
lookup_file() {
|
||||
curl -sSL "https://go.dev/dl/?mode=json" |
|
||||
jq -r '.[0].files[]
|
||||
| select(.os == "'"$GOOS"'")
|
||||
| select(.arch == "'"$GOARCH"'")
|
||||
| .filename'
|
||||
}
|
||||
|
||||
fetch() {
|
||||
local filename
|
||||
filename="$(lookup_file)"
|
||||
[[ -z "$filename" ]] && echo "unable to fetch filename" 1>&2 && return 1
|
||||
local path="/tmp/$filename"
|
||||
[[ -n "$DOWNLOADS" ]] && [[ -d "$DOWNLOADS" ]] && path="$DOWNLOADS/$filename"
|
||||
curl -L "https://go.dev/dl/$filename" -o "$path"
|
||||
echo "$path"
|
||||
}
|
||||
|
||||
install_latest_go() {
|
||||
local dir="$1" path
|
||||
[[ -z "$dir" ]] && dir="$TARGETDIR"
|
||||
[[ -z "$dir" ]] && dir="$HOME/.local"
|
||||
mkdir -p "$dir" 2>/dev/null
|
||||
path="$(fetch)"
|
||||
[[ -z "$path" ]] && echo "unable to fetch go tarball" 1>&2 && return 1
|
||||
rm -rf "$dir/go" && tar -C "$dir" -xzf "$path" # rm is required by instructions
|
||||
echo "Add $dir/go/bin to your path and optionally set GOBIN=~/.local/bin" 1>&2
|
||||
}
|
||||
|
||||
install_latest_go "$@"
|
||||
83
install/install-nodejs
Executable file
83
install/install-nodejs
Executable file
|
|
@ -0,0 +1,83 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
# Installs the latest NodeJS release into $TARGETDIR (default: ~/.local)
|
||||
|
||||
true "${TARGETDIR:="$HOME/.local"}"
|
||||
|
||||
UNAME=$(uname -s)
|
||||
case "${UNAME}" in
|
||||
Linux*) CURR_OS=LINUX;;
|
||||
Darwin*) CURR_OS=MAC;;
|
||||
*) CURR_OS=UNK;;
|
||||
esac
|
||||
|
||||
get_latest_release() {
|
||||
curl --silent "https://api.github.com/repos/$1/releases/latest" | # Get latest release from GitHub api
|
||||
jq -r '.tag_name'
|
||||
}
|
||||
|
||||
get_latest_release_tarball() {
|
||||
curl --silent "https://api.github.com/repos/$1/releases/latest" | # Get latest release from GitHub api
|
||||
jq -r '.tarball_url'
|
||||
}
|
||||
|
||||
fetch() {
|
||||
local filename
|
||||
filename="$(lookup_file)"
|
||||
[[ -z "$filename" ]] && echo "unable to fetch filename" 1>&2 && return 1
|
||||
local path="/tmp/$filename"
|
||||
[[ -n "$DOWNLOADS" ]] && [[ -d "$DOWNLOADS" ]] && path="$DOWNLOADS/$filename"
|
||||
curl -L "https://go.dev/dl/$filename" -o "$path"
|
||||
echo "$path"
|
||||
}
|
||||
|
||||
install_latest_nodejs() {
|
||||
#local dir="$1" path
|
||||
#[[ -z "$dir" ]] && dir="$TARGETDIR"
|
||||
#[[ -z "$dir" ]] && dir="$HOME/.local"
|
||||
#mkdir -p "$dir" 2>/dev/null
|
||||
#path="$(fetch)"
|
||||
#[[ -z "$path" ]] && echo "unable to fetch go tarball" 1>&2 && return 1
|
||||
#rm -rf "$dir/go" && tar -C "$dir" -xzf "$path" # rm is required by instructions
|
||||
#echo "Add $dir/go/bin to your path and optionally set GOBIN=~/.local/bin" 1>&2
|
||||
RELVERS=$(get_latest_release "nodejs/node")
|
||||
TARBALL=$(get_latest_release_tarball "nodejs/node")
|
||||
TMPDIR=$(mktemp -d)
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "Error creating temp directory.."
|
||||
exit 1;
|
||||
fi
|
||||
|
||||
echo "Latest NodeJS from Github release is ${RELVERS}..."
|
||||
|
||||
echo "Downloading NodeJS ${RELVERS} from ${TARBALL}..."
|
||||
curl -L "https://github.com/nodejs/node/archive/refs/tags/${RELVERS}.tar.gz" -o "${TMPDIR}/nodejs_${RELVERS}.tar.gz"
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "Error downloading latest nodejs tarball.."
|
||||
exit 1;
|
||||
fi
|
||||
|
||||
mkdir "${TMPDIR}/nodejs"
|
||||
|
||||
tar -xf "nodejs_${RELVERS}.tar.gz" -C "${TMPDIR}/nodejs" --strip-components=1
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "Error while trying to untar tarball ${TMPDIR}/nodejs_${RELVERS}.tar.gz"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
cd "${TMPDIR}/nodejs"
|
||||
|
||||
./configure
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "Error configuring build"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
make
|
||||
if [ $? -ne - ]; then
|
||||
echo "Error running make"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
install_latest_nodejs "$@"
|
||||
18
install/install-yq
Executable file
18
install/install-yq
Executable file
|
|
@ -0,0 +1,18 @@
|
|||
#!/bin/sh
|
||||
|
||||
url="https://github.com/mikefarah/yq/releases/latest/download/yq_linux_amd64"
|
||||
dir=$(mktemp -d)
|
||||
|
||||
cleanup () {
|
||||
rm -rf "$dir"
|
||||
}
|
||||
trap cleanup EXIT
|
||||
|
||||
curl -L "$url" -o "$dir/yq"
|
||||
chmod +x "$dir/yq"
|
||||
|
||||
# mkdir -p is not POSIX compliant
|
||||
[ ! -d ~/.local ] && mkdir ~/.local
|
||||
[ ! -d ~/.local/bin ] && mkdir ~/.local/bin
|
||||
|
||||
cp "$dir/yq" ~/.local/bin
|
||||
Loading…
Reference in a new issue