diff --git a/Makefile b/Makefile index cc4acc5..bf02171 100644 --- a/Makefile +++ b/Makefile @@ -36,6 +36,16 @@ lint: clean: cd distrod; cargo clean; cargo.exe clean +## Install locally built opt_distrod.tar.gz distrobution. Use 'update' if this system is already running distrod. +install: build + sudo ./install.sh install --release-file ./opt_distrod.tar.gz +.PHONY: install + +## Update local install with built opt_distrod.tar.gz distrobution. Use 'install' if this system doesn't have distrod installed. +update: build + sudo ./install.sh update --release-file ./opt_distrod.tar.gz +.PHONY: update + ifneq ($(shell uname -a | grep microsoft),) # This is a WSL environment, which means you can run .exe ROOTFS_PATH = $(OUTPUT_ROOTFS_PATH) OUTPUT_PORT_PROXY_EXE_PATH = distrod/target/release/portproxy.exe diff --git a/install.sh b/install.sh index 0aeca22..e620c4c 100755 --- a/install.sh +++ b/install.sh @@ -4,19 +4,27 @@ set -e LATEST_RELEASE_URL="https://github.com/nullpo-head/wsl-distrod/releases/latest/download/opt_distrod.tar.gz" -HELP_STR="Usage: $0 +help () { + cat <<-eof +Usage: $0 [flags] + +flags: + -r, --release-file + Use as opt_distrod.tar.gz instead of downloading from: + $LATEST_RELEASE_URL + -h, --help + Displays this help, the same as the help command command: - install - update - - uninstall" - -help () { - echo "$HELP_STR" + - uninstall + - help (this) +eof } error_help () { - error "$HELP_STR" + error "$(help)" } install () { @@ -77,34 +85,34 @@ error () { echo "$@" >&2 } - if [ -z "$1" ]; then + help error_help exit 1 fi -if [ "$(whoami)" != "root" ]; then - error "You must be root to run this script, please use sudo ./install.sh" - exit 1 -fi +unset NEEDS_ROOT COMMAND= while [ -n "$1" ]; do case "$1" in - -h|--help) - echo "$HELP_STR" - exit 0 + -h|--help|help) + COMMAND=help + break ;; install) COMMAND=install + NEEDS_ROOT=1 shift ;; uninstall) COMMAND=uninstall + NEEDS_ROOT=1 shift ;; update) COMMAND=update + NEEDS_ROOT=1 shift ;; -r|--release-file) @@ -122,4 +130,9 @@ while [ -n "$1" ]; do esac done +if [ -n "$NEEDS_ROOT" ] && [ "$(whoami)" != "root" ]; then + printf "You must be root to use the '${COMMAND}' command, please use 'sudo ${0} ${COMMAND}'\n" + exit 1 +fi + "$COMMAND"