-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add get universer bash #171
Open
mymodian
wants to merge
3
commits into
main
Choose a base branch
from
feat/get-universer
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,229 @@ | ||
#!/bin/bash | ||
|
||
_CI_TEST=${_CI_TEST:-false} | ||
_HOST=${_HOST:-"univer.ai"} | ||
|
||
# get os type | ||
osType=$(uname) | ||
if [ "${osType}" == "Darwin" ]; then | ||
osType="darwin" | ||
elif [ "${osType}" == "Linux" ]; then | ||
osType="linux" | ||
elif [[ "${osType}" == MINGW64* ]]; then | ||
osType="mingw" | ||
else | ||
echo "Warning: Unknow OS type ${osType}" | ||
fi | ||
|
||
# get arch type | ||
archType=$(uname -m) | ||
if [ "${archType}" == "x86_64" ]; then | ||
archType="amd64" | ||
elif [ "${archType}" == "aarch64" ] || [ "$archType" == "arm64" ]; then | ||
archType="arm64" | ||
else | ||
echo "Error: Unsupport arch type ${archType}" | ||
exit 1 | ||
fi | ||
|
||
SCRIPT_DIR="/tmp/univer-script" | ||
|
||
# check curl command | ||
if ! [ -x "$(command -v curl)" ]; then | ||
echo "Error: curl is not installed." >&2 | ||
exit 1 | ||
fi | ||
|
||
if ! [ -x "$(command -v docker)" ]; then | ||
echo "Docker is not installed." | ||
read -p "Do you want to install Docker? (Y/n): " choice | ||
choice=${choice:-Y} # Default to 'Y' if no input is provided | ||
case "$choice" in | ||
y|Y ) | ||
mkdir -p $SCRIPT_DIR/get-docker | ||
curl -s -o $SCRIPT_DIR/get-docker/get-docker.sh https://release-univer.oss-cn-shenzhen.aliyuncs.com/tool/get-docker.sh | ||
curl -s -o $SCRIPT_DIR/get-docker/get-docker-official-script.sh https://release-univer.oss-cn-shenzhen.aliyuncs.com/tool/get-docker-official-script.sh | ||
# run get-docker script from local get-docker/get-docker.sh | ||
bash $SCRIPT_DIR/get-docker/get-docker.sh || { echo "Failed to install Docker"; exit 1; } | ||
# TODO(zsq1234): newgrp docker interupt the script, so use sudo chmod 666 /var/run/docker.sock instead and temporary | ||
sudo chmod 666 /var/run/docker.sock | ||
rm -rf $SCRIPT_DIR/get-docker | ||
;; | ||
n|N ) | ||
echo "Installation aborted. Docker is required to proceed." >&2 | ||
exit 1 | ||
;; | ||
* ) | ||
echo "Invalid input. Installation aborted." >&2 | ||
exit 1 | ||
;; | ||
esac | ||
fi | ||
|
||
docker compose version &>/dev/null | ||
if [ $? -ne 0 ]; then | ||
docker-compose version &>/dev/null | ||
if [ $? -ne 0 ]; then | ||
echo "Error: docker compose is not installed." | ||
exit 1 | ||
fi | ||
fi | ||
|
||
# check docker daemon | ||
if ! docker info > /dev/null 2>&1; then | ||
echo "Error: docker daemon is not running." >&2 | ||
exit 1 | ||
fi | ||
|
||
set -eu | ||
|
||
# check docker version | ||
_docker_version=$(docker version --format '{{ .Server.Version }}') | ||
if [ "$(printf '%s\n' "$_docker_version" "23.0" | sort -V | head -n1)" == "$_docker_version" ] && [ "$_docker_version" != "23.0" ]; then | ||
echo "Warning: docker version $_docker_version less than 23.0" >&2 | ||
fi | ||
|
||
checkPort() { | ||
if ! [ -x "$(command -v netstat)" ] || ! [ -x "$(command -v awk)" ] ; then | ||
docker run --network=host --rm univer-acr-registry.cn-shenzhen.cr.aliyuncs.com/release/network-tool:0.0.1 netstat -tuln | awk '{print $4}' | grep -q ":$1" | ||
else | ||
netstat -tuln | awk '{print $4}' | grep -q ":$1" | ||
fi | ||
if [ $? -eq 0 ]; then | ||
echo "Port $1 is already in use." | ||
exit 1 | ||
fi | ||
} | ||
|
||
|
||
tokenPath="${HOME}/.univer/" | ||
tokenFileName="${tokenPath}/deploy_token" | ||
|
||
getTokenURL="https://${_HOST}/cli-auth" | ||
verifyTokenURL="https://${_HOST}/license-manage-api/cli-auth/verify-token" | ||
|
||
|
||
openURL() { | ||
local url="$1" | ||
local openCommand | ||
|
||
# Determine the appropriate command to open the URL based on the OS | ||
if [[ "$(uname -r)" == *microsoft* ]]; then | ||
# Assuming running under WSL | ||
openCommand="cmd.exe /c start" | ||
elif [[ "$OSTYPE" == "linux-gnu"* ]]; then | ||
# xdg-open is available in most Linux distributions. | ||
# It opens a file or URL in the user's preferred browser (configurable with xdg-settings). | ||
if command -v xdg-open > /dev/null; then | ||
openCommand="xdg-open" | ||
else | ||
return 1 | ||
fi | ||
elif [[ "$OSTYPE" == "darwin"* ]]; then | ||
openCommand="open" | ||
elif [[ "$OSTYPE" == "msys" ]]; then | ||
# Assuming running mingw | ||
openCommand="start" | ||
else | ||
# "Unsupported environment for openURL function." | ||
return 1 | ||
fi | ||
|
||
# Attempt to open the URL | ||
if [[ "$openCommand" == "cmd.exe*" ]]; then | ||
$openCommand "${url//ir/ri}" # "$(echo "$url" | sed 's/&/^&/')" Escaping '&' for cmd.exe | ||
else | ||
$openCommand "$url" | ||
fi | ||
|
||
# Check if the command was successful | ||
if [ $? -eq 0 ]; then | ||
# "URL opened successfully." | ||
return 0 | ||
else | ||
# "Failed to open URL." | ||
return 1 | ||
fi | ||
} | ||
|
||
verifyToken() { | ||
reqToken=$1 | ||
verbose=$2 | ||
response="$(curl -s -w "\n%{http_code}" ${verifyTokenURL} -H 'X-Session-Token: '"${reqToken}" -d "token=${reqToken}&source=deploy")"; | ||
http_body="$(echo "${response}" | sed '$d')"; | ||
http_code="$(echo "${response}" | tail -n 1)"; | ||
|
||
if [[ "$http_code" -ne 200 ]] ; then | ||
${verbose} && echo "That's not a valid token! (server response code:$http_code)" | ||
return 1 | ||
else | ||
echo "Welcome! You're authenticated." | ||
fi | ||
return 0 | ||
} | ||
|
||
token="" | ||
|
||
getToken(){ | ||
if [ -s ${tokenFileName} ]; then | ||
# check saved token | ||
token=$(cat "${tokenFileName}") | ||
if ! verifyToken "${token}" false; then | ||
token="" | ||
echo -n "" > "${tokenFileName}" | ||
fi | ||
fi | ||
|
||
if [ -z "$token" ]; then | ||
echo "Please authenticate the CLI to subscribe to our upgrade notifications" | ||
openURL "${getTokenURL}" && | ||
echo -e "Your browser has been opened to visit:\n\n\t ${getTokenURL} \n" || | ||
echo -e "Open the following in your browser:\n\n\t ${getTokenURL} \n" | ||
|
||
while [ "$_CI_TEST" != "true" ] ; do | ||
read -r -p "> Paste your token here: " token | ||
if verifyToken "${token}" true; then | ||
mkdir -p "${tokenPath}" | ||
echo -n "${token}" > "${tokenFileName}" | ||
break | ||
fi | ||
done | ||
fi | ||
} | ||
|
||
getToken | ||
|
||
# download specfied version | ||
work_dir=$PWD | ||
tmp_dir=$(mktemp -d) | ||
|
||
mkdir -p "$tmp_dir" && cd "$tmp_dir" | ||
if [ $# == 1 ]; then | ||
echo "start download version:$1..." | ||
curl -s -o univer.tar.gz https://release-univer.oss-cn-shenzhen.aliyuncs.com/release/docker-compose.$1.tar.gz | ||
else | ||
echo "start download the latest version..." | ||
curl -s -o univer.tar.gz https://release-univer.oss-cn-shenzhen.aliyuncs.com/release/docker-compose.tar.gz | ||
fi | ||
tar -xzf univer.tar.gz && rm univer.tar.gz | ||
# get real version | ||
. .env | ||
version=$UNIVERSER_VERSION | ||
if [ $# == 1 ] && [ "$version" != "$1" ]; then | ||
echo "the specified version:$1 not exists." | ||
rm -r $tmp_dir | ||
exit 1 | ||
fi | ||
|
||
# mv to work dir | ||
cd "$work_dir" | ||
target_dir="$work_dir/universer-${version}" | ||
|
||
if [ -d "$target_dir" ]; then | ||
echo "the version:${version} already exists." | ||
rm -r $tmp_dir | ||
exit 1 | ||
fi | ||
|
||
mv "$tmp_dir" "$target_dir" | ||
echo "download success, target dir is:${target_dir}" |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
可以定义个变量