例如,我有一个脚本来创建站点的本地副本(实际上哪个脚本并不重要,我给出了这个脚本作为示例)
#!/usr/bin/env bash
set -Eeuo pipefail
trap cleanup SIGINT SIGTERM ERR EXIT
VER="1.0.0"
script_dir=$(cd "$(dirname "${BASH_SOURCE[0]}")" &>/dev/null && pwd -P)
usage() {
cat <<EOF
Copysite v.$VER
Usage: $(basename "${BASH_SOURCE[0]}") [-h] [-v] [--verbose] -d ./Directory -u example.com
Program based on GNU Wget - designed to create a complete local copy of the site while maintaining the file structure
+---------------------------------------+
| Autor | fftcc |
| License | GNU GPL v3 |
| Website | ff99cc.art |
| E-mail | me@ff99cc.art |
| Git | codeberg.org/fftcc |
| Keyoxide | keyoxide.org/me@ff99cc.art |
+---------------------------------------+
Available options:
-h, --help Print this help and exit
-v, --version Print version
--verbose Print script debug info
-d, --dir Target directory (by default current directory if no parameter value is passed)
-u, --url Website address
EOF
exit
}
ver() {
cat <<EOF
$VER
EOF
exit
}
cleanup() {
trap - SIGINT SIGTERM ERR EXIT
}
msg() {
echo >&2 -e "${1-}"
}
wget_fn() {
wget --mirror -p --html-extension --base=./ -k -P "${dir-}" "${url-}"
}
die() {
local msg=$1
local code=${2-1} # default exit status 1
msg "$msg"
exit "$code"
}
parse_params() {
while :; do
case "${1-}" in
-h | --help) usage ;;
-v | --version) ver ;;
--verbose) set -x ;;
-d | --dir)
dir="${2-}"
shift
;;
-u | --url)
url="${2-}"
shift
;;
-?*) die "Unknown option: $1" ;;
*) break ;;
esac
shift
done
args=("$@")
# check required params and arguments
[[ -z "${url-}" ]] && die "Missing required parameter: --url"
return 0
}
parse_params "$@"
wget_fn ${dir} ${url}
帮我编写一个install.sh脚本,它会将复制站点文件复制(或使用cURL下载)到/usr/bin/目录.但问题是,并不是所有的系统都有/usr/bin/,路径可能不同,$PATH变量中也有这样的路径.但这里有另一个问题,在$PATH中可能有多个路径.如何为系统 Select 一条全局安装应用程序的路径?
理论上,您可以使用常见的路径,例如/usr/bin/或/usr/local/bin/,但是$PATH中的路径可以手动更改,也可以由其他程序更改.或者,例如,在thermex中,从根目录到usr/bin目录的路径经过许多文件夹 /data/data/com.termux/files/usr/bin 帮我找到这个问题最普遍的解决方案,并写一个脚本.
我在Internet上找到了以下解决方案:在主目录中创建~/bin并将脚本放在那里.并通过shell 配置文件将该目录添加到$PATH变量
PATH = "$HOME/bin"
但碰巧该脚本只对当前用户是全局可执行的,这不适合我.
如果有人有在Node.js 上创建cli-app的技能来帮助我用js重写我的脚本.这将确保通过NPM的跨平台兼容性,我将非常高兴.不幸的是,我没有在Commanderjs或oclif上创建应用程序的经验,也没有时间从头开始学习这些工具.