代码拉取完成,页面将自动刷新
#!/usr/bin/env bash
# Installation script for Deno Version Manager
# Copyright (C) 2020 ~ 2024, Chen Su and all contributors.
# Ensure the script is downloaded completely
{
dvm_add_into_profile_file() {
local is_dvm_defined
dvm_get_profile_file
is_dvm_defined=$(grep DVM_DIR < "$DVM_PROFILE_FILE")
if [ -n "$is_dvm_defined" ]
then
return
fi
echo "
# Deno Version Manager
export DVM_DIR=\"\$HOME/.dvm\"
[ -f \"\$DVM_DIR/dvm.sh\" ] && . \"\$DVM_DIR/dvm.sh\"
[ -f \"\$DVM_DIR/bash_completion\" ] && . \"\$DVM_DIR/bash_completion\"
" >> "$DVM_PROFILE_FILE"
}
dvm_check_dir() {
if [ ! -d "$DVM_DIR" ]
then
mkdir -p "$DVM_DIR"
else
echo "directory $DVM_DIR already exists."
exit 1
fi
}
dvm_compare_version() {
test "$(printf '%s\n' "$@" | sort -V | head -n 1)" != "$2"
}
dvm_get_latest_version() {
local request_url
local response
case "$DVM_SOURCE" in
"gitee")
request_url="https://gitee.com/api/v5/repos/ghosind/dvm/releases/latest"
;;
"github"|*)
request_url="https://api.github.com/repos/ghosind/dvm/releases/latest"
;;
esac
if ! dvm_has curl
then
echo "curl is required."
exit 1
fi
if ! response=$(curl -s "$request_url")
then
echo "Failed to get the latest DVM version."
exit 1
fi
DVM_LATEST_VERSION=$(echo "$response" | sed 's/"/\n/g' | grep tag_name -A 2 | grep v)
}
dvm_get_profile_file() {
case "${SHELL##*/}" in
"bash")
DVM_PROFILE_FILE="$HOME/.bashrc"
;;
"zsh")
DVM_PROFILE_FILE="$HOME/.zshrc"
;;
*)
DVM_PROFILE_FILE="$HOME/.profile"
;;
esac
}
dvm_has() {
command -v "$1" > /dev/null
}
dvm_install() {
dvm_check_dir
DVM_SCRIPT_DIR=${0%/*}
if [ -f "$DVM_SCRIPT_DIR/dvm.sh" ] &&
[ -d "$DVM_SCRIPT_DIR/.git" ] &&
[ -f "$DVM_SCRIPT_DIR/bash_completion" ]
then
# Copy all files to DVM_DIR
cp -R "$DVM_SCRIPT_DIR/". "$DVM_DIR"
else
dvm_get_latest_version
dvm_install_latest_version
fi
dvm_add_into_profile_file
echo "DVM has been installed, please restart your terminal or run \`source $DVM_PROFILE_FILE\` to apply changes."
}
dvm_install_latest_version() {
local git_url
local cmd
case "$DVM_SOURCE" in
"gitee")
git_url="https://gitee.com/ghosind/dvm.git"
;;
"github"|*)
git_url="https://github.com/ghosind/dvm.git"
;;
esac
if ! dvm_has git
then
echo "git is require."
exit 1
fi
cmd="git clone -b $DVM_LATEST_VERSION $git_url $DVM_DIR --depth=1"
if ! ${cmd}
then
echo "failed to download DVM."
exit 1
fi
}
dvm_print_help() {
echo "DVM installation script"
echo
echo "Usage: install.sh [-r <github|gitee>] [-d <dvm_dir>]"
echo
echo "Options:"
echo " -r <github|gitee> Set the repository server, default github."
echo " -d dir Set the dvm install directory, default ~/.dvm."
echo " -h Print help."
echo
echo "Example:"
echo " install.sh -r github -d ~/.dvm"
}
dvm_set_default() {
DVM_DIR=${DVM_DIR:-$HOME/.dvm}
DVM_SOURCE=${DVM_SOURCE:-github}
}
dvm_set_default
while getopts "hr:d:" opt
do
case "$opt" in
"h")
dvm_print_help
exit 0
;;
"r")
if [ "$OPTARG" != "github" ] && [ "$OPTARG" != "gitee" ]
then
dvm_print_help
exit 1
fi
DVM_SOURCE="$OPTARG"
;;
"d")
if [ -z "$OPTARG" ]
then
dvm_print_help
exit 1
fi
DVM_DIR="$OPTARG"
;;
*)
;;
esac
done
if [ "$DVM_SOURCE" != "github" ] && [ "$DVM_SOURCE" != "gitee" ]
then
dvm_print_help
exit 1
fi
dvm_install
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。