Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 20 additions & 5 deletions scripts/install.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,15 @@ param(

$ErrorActionPreference = "Stop"

$exeName = "ir"

$repository = "smashedr/install-release"
$exeName = "ir"

Write-Host -ForegroundColor Green "Installing: $repository"

## ARCH
Write-Host -ForegroundColor Green "Installing: $repository as $exeName"


## OS
if (-not (Test-Path variable:IsWindows)) {
Write-Host -ForegroundColor DarkCyan "Windows Detected. Forcing IsWindows."
$script:IsWindows = $true
Expand All @@ -29,6 +32,9 @@ $platform = switch ($true) {
}
}
Write-Host -ForegroundColor DarkCyan "platform: $platform"


## ARCH
$osArchitecture = [System.Runtime.InteropServices.RuntimeInformation,mscorlib]::OSArchitecture
Write-Host -ForegroundColor DarkCyan "osArchitecture: $osArchitecture"
$arch = switch ($osArchitecture) {
Expand All @@ -42,6 +48,7 @@ $arch = switch ($osArchitecture) {
}
Write-Host -ForegroundColor DarkCyan "arch: $arch"


## FILE
if ($IsWindows) {
$binPath = Join-Path $env:LOCALAPPDATA "Microsoft\WindowsApps"
Expand All @@ -54,9 +61,13 @@ if ($IsWindows) {
Write-Host -ForegroundColor DarkCyan "exeName: $exeName"
Write-Host -ForegroundColor DarkCyan "binPath: $binPath"
Write-Host -ForegroundColor DarkCyan "file: $file"


## URL
$url = "https://github.com/$repository/releases/latest/download/$file"
Write-Host -ForegroundColor DarkCyan "url: $url"


## BIN
Write-Host -ForegroundColor White "Target Directory: $binPath"
if ($bin) {
Expand All @@ -75,6 +86,7 @@ if (-not (Test-Path $binPath)) {
throw
}


## PATH
if ($IsWindows) {
# Windows
Expand Down Expand Up @@ -103,6 +115,7 @@ if ($IsWindows) {
}
}


## TEMP
$temp = [system.io.path]::GetTempPath()
Write-Host -ForegroundColor DarkCyan "temp: $temp"
Expand All @@ -111,19 +124,21 @@ Write-Host -ForegroundColor DarkCyan "tempDir: $tempDir"
$zipPath = Join-Path $tempDir $file
Write-Host -ForegroundColor DarkCyan "zipPath: $zipPath"

## EXEC

try {
# Download
Write-Host -ForegroundColor DarkCyan "Downloading: $url"
New-Item -ItemType Directory -Path $tempDir -Force | Out-Null
Invoke-WebRequest -Uri $url -OutFile $zipPath

# Extract
if ($zipPath -like "*.tar.gz") {
tar -xzf $zipPath -C $tempDir
} else {
Expand-Archive -Path $zipPath -DestinationPath $tempDir -Force
}
# Install

# Move
$source = Join-Path $tempDir $exeName
Move-Item -Path $source -Destination $binPath -Force
} catch {
Expand Down
42 changes: 21 additions & 21 deletions scripts/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@
set -e


OWNER="smashedr"
REPO="install-release"
REPOSITORY="smashedr/install-release"
EXE="ir"
TARGET_BIN="${HOME}/bin"
#TARGET_BIN="${HOME}/bin"


echo "Installing: ${OWNER}/${REPO} as ${EXE}"
echo "Installing: ${REPOSITORY} as ${EXE}"


function fail() {
Expand All @@ -24,7 +23,7 @@ function fail() {
}


# OS
## OS
OS=$(uname -s | tr '[:upper:]' '[:lower:]')
echo "OS: ${OS}"
case "${OS}" in
Expand All @@ -36,7 +35,7 @@ esac
echo "OS: ${OS}"


# ARCH
## ARCH
ARCH="$(uname -m)"
echo "ARCH: ${ARCH}"
case "${ARCH}" in
Expand All @@ -48,25 +47,27 @@ esac
echo "ARCH: ${ARCH}"


# FTYPE
## FILE
if [[ "${OS}" = "Windows" ]]; then
TARGET_BIN="${LOCALAPPDATA}\Microsoft\WindowsApps"
# TODO: Confirm setting ${EXE} to .exe is not required
FTYPE="zip"
which unzip > /dev/null || fail "unzip is not installed"
else
TARGET_BIN="${HOME}/.local/bin"
FTYPE="tar.gz"
which tar > /dev/null || fail "tar is not installed"
which gzip > /dev/null || fail "gzip is not installed"
fi
echo "FTYPE: ${FTYPE}"


# URL
URL="https://github.com/${OWNER}/${REPO}/releases/latest/download/${EXE}_${OS}_${ARCH}.${FTYPE}"
## URL
URL="https://github.com/${REPOSITORY}/releases/latest/download/${EXE}_${OS}_${ARCH}.${FTYPE}"
echo "URL: ${URL}"


# GET
## GET
GET=""
if which curl > /dev/null; then
GET="curl --fail -# -L"
Expand All @@ -81,7 +82,7 @@ fi
echo "GET: ${GET}"


# BIN
## BIN
echo "Target Directory: ${TARGET_BIN}"
echo -n "Enter Path [press <enter> to accept]: "
read -r input </dev/tty
Expand All @@ -92,7 +93,7 @@ fi
echo "TARGET_BIN: ${TARGET_BIN}"


# PATH
## PATH
if ! echo "${PATH}" | tr ':' '\n' | grep -qx "${TARGET_BIN}"; then
echo "⚠️ Target bin NOT in PATH: ${TARGET_BIN}"
# TODO: Add TARGET_BIN to PATH
Expand All @@ -103,7 +104,7 @@ if [[ ! -d "${TARGET_BIN}" ]]; then
fi


# TEMP
## TEMP
TEMP_DIR=$(mktemp -d -t install-release-XXXXXXXXXX)
echo "TEMP_DIR: ${TEMP_DIR}"

Expand All @@ -118,7 +119,7 @@ function _execution_trap() {
trap _execution_trap EXIT HUP INT QUIT PIPE TERM


# DOWNLOAD
## DOWNLOAD
cd "${TEMP_DIR}"
if [[ ${FTYPE} = "tar.gz" ]]; then
bash -c "${GET} ${URL}" | tar zxf - || fail "download failed"
Expand All @@ -129,19 +130,18 @@ elif [[ ${FTYPE} = "zip" ]]; then
fi


# CHMOD
## CHMOD
TEMP_BIN="${TEMP_DIR}/${EXE}"
echo "TEMP_BIN: ${TEMP_BIN}"
chmod +x "${TEMP_BIN}" || fail "chmod +x failed"
DEST="${TARGET_BIN}/${EXE}"
echo "DEST: ${DEST}"


# MOVE
if ! mv "${TEMP_BIN}" "${DEST}"; then
## MOVE
if ! mv "${TEMP_BIN}" "${TARGET_BIN}"; then
echo "retrying mv with sudo..."
sudo mv "${TEMP_BIN}" "${DEST}" || fail "sudo mv failed"
sudo mv "${TEMP_BIN}" "${TARGET_BIN}" || fail "sudo mv failed"
fi


echo "✅ Successfully Installed: ${EXE}"
echo "✅ Installation Successful!"
echo "To get started run: ${EXE} --help"