-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from dotenvx/installer
Installer
- Loading branch information
Showing
9 changed files
with
325 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
name: ci | ||
|
||
on: push | ||
|
||
jobs: | ||
test: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
fail-fast: true | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: actions/setup-node@v4 | ||
with: | ||
node-version: 16.x | ||
- name: install shellspec | ||
run: curl -fsSL https://git.io/shellspec | sh -s 0.28.1 --yes | ||
- run: which shellspec | ||
- run: npm install | ||
- run: npm run standard | ||
- run: npm test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
--require spec_helper | ||
|
||
## Default kcov (coverage) options | ||
# --kcov-options "--include-path=. --path-strip-level=1" | ||
# --kcov-options "--include-pattern=.sh" | ||
# --kcov-options "--exclude-pattern=/.shellspec,/spec/,/coverage/,/report/" | ||
|
||
## Example: Include script "myprog" with no extension | ||
# --kcov-options "--include-pattern=.sh,myprog" | ||
|
||
## Example: Only specified files/directories | ||
# --kcov-options "--include-pattern=myprog,/lib/" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
#!/bin/sh | ||
|
||
set -e | ||
|
||
# default values | ||
VERSION="0.44.1" | ||
DIRECTORY="/usr/local/bin" | ||
|
||
usage() { | ||
echo "Usage: $0 [options] [command]" | ||
echo "" | ||
echo "install dotenvx – a better dotenv" | ||
echo "" | ||
echo "Options:" | ||
echo " --directory directory to install dotenvx to (default: \"/usr/local/bin\")" | ||
echo " --version version of dotenvx to install (default: \"$VERSION\")" | ||
echo "" | ||
echo "Commands:" | ||
echo " install install dotenvx" | ||
echo " help display help" | ||
} | ||
|
||
directory() { | ||
local dir=$DIRECTORY | ||
|
||
case "$dir" in | ||
~*/*) | ||
dir="$HOME/${dir#\~/}" | ||
;; | ||
~*) | ||
dir="$HOME/${dir#\~}" | ||
;; | ||
esac | ||
|
||
echo "${dir}" | ||
return 0 | ||
} | ||
|
||
is_directory_writable() { | ||
# check installation directory is writable | ||
if [ ! -w "$(directory)" ] && [ "$(id -u)" -ne 0 ]; then | ||
echo "[INSTALLATION_FAILED] the installation directory [$(directory)] is not writable by the current user" | ||
echo "? run as root [sudo $0] or choose a writable directory like your current directory [$0 directory=.]" | ||
|
||
return 1 | ||
fi | ||
|
||
return 0 | ||
} | ||
|
||
is_curl_installed() { | ||
if ! command -v curl >/dev/null 2>&1; then | ||
echo "[INSTALLATION_FAILED] curl is required and appears to not be installed" | ||
echo "? install curl and try again" | ||
|
||
exit 1 | ||
fi | ||
|
||
return 0 | ||
} | ||
|
||
os() { | ||
echo "$(uname -s | tr '[:upper:]' '[:lower:]')" | ||
|
||
return 0 | ||
} | ||
|
||
arch() { | ||
echo "$(uname -m | tr '[:upper:]' '[:lower:]')" | ||
|
||
return 0 | ||
} | ||
|
||
is_os_supported() { | ||
local os="$(os)" | ||
|
||
case "$os" in | ||
linux) os="linux" ;; | ||
darwin) os="darwin" ;; | ||
*) | ||
echo "[INSTALLATION_FAILED] your operating system ${os} is currently unsupported" | ||
echo "? request support by opening an issue at [https://github.com/dotenvx/dotenvx.sh/issues]" | ||
|
||
return 1 | ||
;; | ||
esac | ||
|
||
return 0 | ||
} | ||
|
||
is_arch_supported() { | ||
local arch="$(arch)" | ||
|
||
case "$arch" in | ||
x86_64) arch="x86_64" ;; | ||
amd64) arch="amd64" ;; | ||
arm64) arch="arm64" ;; | ||
aarch64) arch="aarch64" ;; | ||
*) | ||
echo "[INSTALLATION_FAILED] your architecture ${arch} is currently unsupported - must be x86_64, amd64, arm64, or aarch64" | ||
echo "? request support by opening an issue at [https://github.com/dotenvx/dotenvx.sh/issues]" | ||
|
||
return 1 | ||
;; | ||
esac | ||
|
||
return 0 | ||
} | ||
|
||
os_arch() { | ||
echo "$(os)-$(arch)" | ||
|
||
return 0 | ||
} | ||
|
||
# parse arguments | ||
for arg in "$@"; do | ||
case $arg in | ||
directory=* | --directory=*) | ||
DIRECTORY="${arg#*=}" | ||
;; | ||
help | --help) | ||
usage | ||
exit 0 | ||
;; | ||
*) | ||
# Unknown option | ||
echo "Unknown option: $arg" | ||
usage | ||
exit 1 | ||
;; | ||
esac | ||
done | ||
|
||
# is_directory_writable | ||
# is_curl_installed | ||
# is_os_supported | ||
# is_arch_supported | ||
# echo "os: $(os) arch: $(arch)" | ||
echo "hello" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
Describe 'install.sh' | ||
Include install.sh directory=./spec/tmp | ||
|
||
setup() { | ||
VERSION="0.44.1" | ||
} | ||
|
||
mock_home() { | ||
HOME="/home/testuser" | ||
DIRECTORY="~/testdir" | ||
} | ||
|
||
mock_unwritable_directory() { | ||
DIRECTORY="/usr/local/testing-installer" # requires root/sudo | ||
} | ||
|
||
BeforeEach 'setup' | ||
|
||
Describe 'default values' | ||
It 'checks default VERSION' | ||
When call echo "$VERSION" | ||
The output should equal "0.44.1" | ||
End | ||
|
||
It 'checks default DIRECTORY' | ||
When call echo "$DIRECTORY" | ||
The output should equal "./spec/tmp" | ||
End | ||
End | ||
|
||
Describe 'usage()' | ||
It 'displays usage' | ||
When call usage | ||
The output should equal "Usage: $0 [options] [command] | ||
install dotenvx – a better dotenv | ||
Options: | ||
--directory directory to install dotenvx to (default: \"/usr/local/bin\") | ||
--version version of dotenvx to install (default: \"0.44.1\") | ||
Commands: | ||
install install dotenvx | ||
help display help" | ||
End | ||
End | ||
|
||
Describe 'directory()' | ||
It 'smartly returns directory as default INSTALL_DIR' | ||
When call directory | ||
The output should equal "./spec/tmp" | ||
End | ||
|
||
Describe 'when home directory' | ||
Before 'mock_home' | ||
|
||
It 'expands ~ to home directory' | ||
When call directory | ||
The output should equal "/home/testuser/testdir" | ||
End | ||
End | ||
End | ||
|
||
Describe 'is_directory_writable()' | ||
It 'is true (0)' | ||
When call is_directory_writable | ||
The status should equal 0 | ||
End | ||
|
||
Describe 'when unwritable directory' | ||
Before 'mock_unwritable_directory' | ||
|
||
It 'is false (1) to /usr/local/testing-installer (typical case that /usr/local/testing-installer is not writable)' | ||
When call is_directory_writable | ||
The status should equal 1 | ||
The output should equal "[INSTALLATION_FAILED] the installation directory [/usr/local/testing-installer] is not writable by the current user | ||
? run as root [sudo $0] or choose a writable directory like your current directory [$0 directory=.]" | ||
End | ||
End | ||
End | ||
|
||
Describe 'is_curl_installed()' | ||
It 'is true (0) (typical case that /usr/bin/curl is installed)' | ||
When call is_curl_installed | ||
The status should equal 0 | ||
End | ||
End | ||
|
||
Describe 'os()' | ||
It 'returns current os lowercased' | ||
When call os | ||
The status should equal 0 | ||
The output should equal "$(uname -s | tr '[:upper:]' '[:lower:]')" | ||
End | ||
End | ||
|
||
Describe 'arch()' | ||
It 'returns current arch lowercased' | ||
When call arch | ||
The status should equal 0 | ||
The output should equal "$(uname -m | tr '[:upper:]' '[:lower:]')" | ||
End | ||
End | ||
|
||
Describe 'is_os_supported()' | ||
It 'returns true' | ||
When call is_os_supported | ||
The status should equal 0 | ||
End | ||
End | ||
|
||
Describe 'is_arch_supported()' | ||
It 'returns true' | ||
When call is_arch_supported | ||
The status should equal 0 | ||
End | ||
End | ||
|
||
Describe 'os_arch()' | ||
It 'returns the combined values' | ||
When call os_arch | ||
The status should equal 0 | ||
The output should equal "$(uname -s | tr '[:upper:]' '[:lower:]')-$(uname -m | tr '[:upper:]' '[:lower:]')" | ||
End | ||
End | ||
End |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# shellcheck shell=sh | ||
|
||
# Defining variables and functions here will affect all specfiles. | ||
# Change shell options inside a function may cause different behavior, | ||
# so it is better to set them here. | ||
# set -eu | ||
|
||
# This callback function will be invoked only once before loading specfiles. | ||
spec_helper_precheck() { | ||
# Available functions: info, warn, error, abort, setenv, unsetenv | ||
# Available variables: VERSION, SHELL_TYPE, SHELL_VERSION | ||
: minimum_version "0.28.1" | ||
} | ||
|
||
# This callback function will be invoked after a specfile has been loaded. | ||
spec_helper_loaded() { | ||
: | ||
} | ||
|
||
# This callback function will be invoked after core modules has been loaded. | ||
spec_helper_configure() { | ||
# Available functions: import, before_each, after_each, before_all, after_all | ||
: import 'support/custom_matcher' | ||
} |
Empty file.