Skip to content

Commit

Permalink
add:install
Browse files Browse the repository at this point in the history
  • Loading branch information
dashixiong91 committed Sep 23, 2019
1 parent 70729d4 commit 4271790
Showing 1 changed file with 41 additions and 10 deletions.
51 changes: 41 additions & 10 deletions fvm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,26 @@

set -e

OLD_PWD="$PWD"
THIS_DIR="$(cd "$(if [[ "${0:0:1}" == "/" ]]; then echo "$(dirname $0)";else echo "$PWD/$(dirname $0)";fi)"; pwd)"
cd ${OLD_PWD}
FLUTTER_STORAGE_BASE_URL=${FLUTTER_STORAGE_BASE_URL:-"http://mirrors.cnnic.cn/flutter"}
FLUTTER_RELEASE_BASE_URL="${FLUTTER_STORAGE_BASE_URL}/flutter_infra/releases"

darwin=false
case "`uname`" in
Darwin*) darwin=true;;
esac

function print_help(){
echo "Flutter SDK versions Manager."
echo ""
echo "Usage: fvm <command> [arguments]"
echo ""
echo "Available commands:"
echo " list|ls Print flutter-sdk installed versions."
echo " use Switch flutter-sdk to version."
echo " install Install flutter-sdk version."
echo " help|* Display help information."
echo " use Switch flutter-sdk to version."
echo " list|ls Print flutter-sdk installed versions."
echo " list-remote Print flutter-sdk release versions."
echo " install Install flutter-sdk version."
echo " help|* Display help information."
echo ""

}
Expand All @@ -29,6 +35,7 @@ function list(){
echo "${version} => `cat ${THIS_DIR}/versions/${version}/version`"
done
}

function current(){
local current=`readlink $THIS_DIR/current`
current=${current#$THIS_DIR/versions/}
Expand Down Expand Up @@ -57,10 +64,33 @@ function use(){
ln -s $target_version_dir $current_dir
print_current_version
}

function list_remote(){
local release_info_url="${FLUTTER_RELEASE_BASE_URL}/releases_linux.json"
if [[ darwin ]];then
release_info_url="${FLUTTER_RELEASE_BASE_URL}/releases_macos.json"
fi
curl -Ss ${release_info_url} | grep 'stable/' | awk -F ': ' '{print $2}' | awk -F '"' '{print $2}'
}
function install(){
echo "TODO: it is not implements.."
# https://mirrors.cnnic.cn/flutter/flutter_infra/releases/stable/macos/
local version_key="$1"
local version_zip=""
version_zip=`list_remote | grep "$version_key" | awk 'NR==1'`
if [[ -z ${version_zip} ]];then
echo "Error: no flutter version match $version_key !!"
exit 1
fi
local version_short=`echo $version_zip | awk -F '_v' '{print $2}' | awk -F '.zip' '{print $1}'`
local download_url="${FLUTTER_RELEASE_BASE_URL}/${version_zip}"
local temp_path="${TMPDIR}/flutter.zip"
local target_dir="${THIS_DIR}/versions/${version_short}"
if [[ -d ${target_dir} ]];then
echo "Error: flutter $version_short seems to has installed ,please check it!!"
exit 1
fi
echo "flutter $version_short has downloading..."
curl --progress-bar -o $temp_path $download_url
unzip -o $temp_path -d $target_dir
echo "flutter $version_short has installed to $target_dir!"
}

function main(){
Expand All @@ -70,7 +100,8 @@ function main(){
case ${cmd} in
"use")use $args;;
"list"|"ls")list;;
"install")install;;
"list-remote")list_remote;;
"install")install $args;;
"help"|*)print_help;;
esac
}
Expand Down

0 comments on commit 4271790

Please sign in to comment.