Skip to content

Commit

Permalink
feat: update README & enhance setup script (#65)
Browse files Browse the repository at this point in the history
  • Loading branch information
thaodt authored Sep 30, 2022
1 parent cb904fc commit 2358c03
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 2 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,12 @@ async fn main() {
brew install binaryen
```

On Arch Linux based distributions, you might need to explicitly install the following:
- Install wasm-opt

```bash
sudo pacman -S binaryen
```
</details>

- **The _rs-wnfs_ Command**
Expand Down
58 changes: 56 additions & 2 deletions scripts/rs-wnfs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ red='\033[0;31m'
green='\033[0;32m'
purple='\033[0;35m'
none='\033[0m'
yellow="\033[0;33m"

# DESCRIPTION:
# Where execution starts
Expand Down Expand Up @@ -226,15 +227,54 @@ check_flag() {
return $found
}

upgrade_privilege() {
if ! has sudo; then
errorln '"sudo" command not found.'
displayln "If you are on Windows, please run your shell as an administrator, then"
displayln "rerun this script. Otherwise, please run this script as root, or install"
displayln "sudo first."
exit 1
fi
if ! sudo -v; then
errorln "Superuser not granted, aborting installation"
exit 1
fi
}

# DESCRIPTION:
# Sets up the cript by making it excutable and available system wide
# check if the current user has write perm to specific dir by trying to write to it
#
is_writeable() {
path="${1:-}/test.txt"
if touch "${path}" 2>/dev/null; then
rm "${path}"
return 0
else
return 1
fi
}

# DESCRIPTION:
# Sets up the script by making it excutable and available system wide
#
setup() {
displayln "Make script executable"
chmod u+x $script_path

displayln "Drop a link to it in /usr/local/bin"
if ln -s $script_path /usr/local/bin/rs-wnfs; then
sudo=""
if is_writeable "/usr/local/bin"; then
msg="Installing rs-wnfs, please wait…"
else
warnln "Higher permissions are required to install to /usr/local/bin"
upgrade_privilege
sudo="sudo"
msg="Installing rs-wnfs as ROOT, please wait…"
fi
displayln "$msg"

# try to make a symlink, using sudo if required
if "${sudo}" ln -s $script_path /usr/local/bin/rs-wnfs; then
successln "Successfully installed"
else
local result=$?
Expand Down Expand Up @@ -264,11 +304,25 @@ successln() {
printf "\n${green}::: $1 :::${none}\n\n"
}

# DESCRIPTION:
# Prints a warning message.
#
warnln() {
printf "\n${yellow}!!! $1 !!!${none}\n\n"
}

# DESCRIPTION:
# Prints a header message.
#
display_header() {
printf "\n${purple}$1${none}\n\n"
}

# DESCRIPTION:
# test command availability
#
has() {
command -v "$1" 1>/dev/null 2>&1
}

main $@

0 comments on commit 2358c03

Please sign in to comment.