diff --git a/flutterw b/flutterw index c9d0e69..ae3f572 100644 --- a/flutterw +++ b/flutterw @@ -16,23 +16,22 @@ ## ############################################################################## - # Attempt to set APP_HOME # Resolve links: $0 may be a link PRG="$0" # Need this for relative symlinks. -while [ -h "$PRG" ] ; do - ls=`ls -ld "$PRG"` - link=`expr "$ls" : '.*-> \(.*\)$'` - if expr "$link" : '/.*' > /dev/null; then - PRG="$link" - else - PRG=`dirname "$PRG"`"/$link" - fi +while [ -h "$PRG" ]; do + ls=$(ls -ld "$PRG") + link=$(expr "$ls" : '.*-> \(.*\)$') + if expr "$link" : '/.*' >/dev/null; then + PRG="$link" + else + PRG=$(dirname "$PRG")"/$link" + fi done -SAVED="`pwd`" -cd "`dirname \"$PRG\"`/" >/dev/null -APP_HOME="`pwd -P`" +SAVED="$(pwd)" +cd "$(dirname \"$PRG\")/" >/dev/null +APP_HOME="$(pwd -P)" cd "$SAVED" >/dev/null FLUTTER_SUBMODULE_NAME='.flutter' @@ -44,7 +43,7 @@ if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then fi # submodule starting with "-" are not initialized -init_status=`git submodule | grep "\ $FLUTTER_SUBMODULE_NAME$" | cut -c 1` +init_status=$(git submodule | grep "\ $FLUTTER_SUBMODULE_NAME$" | cut -c 1) # Fix not initialized flutter submodule if [ "$init_status" = "-" ]; then @@ -53,13 +52,13 @@ if [ "$init_status" = "-" ]; then fi # Detect detach HEAD and fix it. commands like upgrade expect a valid branch, not a detached HEAD -FLUTTER_SYMBOLIC_REF=`git -C $FLUTTER_SUBMODULE_NAME symbolic-ref -q HEAD` +FLUTTER_SYMBOLIC_REF=$(git -C $FLUTTER_SUBMODULE_NAME symbolic-ref -q HEAD) if [ -z $FLUTTER_SYMBOLIC_REF ]; then echo "Warning: Detected detached HEAD. '$FLUTTER_SUBMODULE_NAME' submodule points to a specific commit, not a branch." echo "You can ignore this warning when you run './flutterw' for the first time after cloning the repository." - FLUTTER_REV=`git -C $FLUTTER_SUBMODULE_NAME rev-parse HEAD` - FLUTTER_CHANNEL=`git config -f .gitmodules submodule.$FLUTTER_SUBMODULE_NAME.branch` - if git -C $FLUTTER_SUBMODULE_NAME branch --contains $FLUTTER_REV | grep $FLUTTER_CHANNEL > /dev/null; then + FLUTTER_REV=$(git -C $FLUTTER_SUBMODULE_NAME rev-parse HEAD) + FLUTTER_CHANNEL=$(git config -f .gitmodules submodule.$FLUTTER_SUBMODULE_NAME.branch) + if git -C $FLUTTER_SUBMODULE_NAME branch --contains $FLUTTER_REV | grep $FLUTTER_CHANNEL >/dev/null; then echo "Fixing detached HEAD $FLUTTER_REV. Binding it to channel '$FLUTTER_CHANNEL' (as defined in .gitmodules)." git -C $FLUTTER_SUBMODULE_NAME branch -q -f $FLUTTER_CHANNEL $FLUTTER_REV git -C $FLUTTER_SUBMODULE_NAME checkout -q $FLUTTER_CHANNEL @@ -71,7 +70,6 @@ if [ -z $FLUTTER_SYMBOLIC_REF ]; then fi fi - # Wrapper tasks done, call flutter binay with all args set -e "$FLUTTER_DIR/bin/flutter" "$@" @@ -99,4 +97,4 @@ if [ $FLUTTER_EXIT_STATUS -eq 0 ]; then fi fi -exit $FLUTTER_EXIT_STATUS \ No newline at end of file +exit $FLUTTER_EXIT_STATUS diff --git a/install.sh b/install.sh index 822dfd5..3871242 100755 --- a/install.sh +++ b/install.sh @@ -17,32 +17,32 @@ if ! [ -f pubspec.yaml ]; then printf "Continuing in case this flutter wrapper is used to create a new project. If so continue with './flutterw create .'\n\n" fi - ### # Parse arguments ### # Parse arguments -while [ "$1" != "" ]; do case $1 in +while [ "$1" != "" ]; do + case $1 in # version tag which should be used for downloading - -t|--tag) - shift - VERSION_TAG="$1" - ;; + -t | --tag) + shift + VERSION_TAG="$1" + ;; *) - echo "Unknown option '$key'" - ;; + echo "Unknown option '$key'" + ;; esac shift done if [ -z "$VERSION_TAG" ]; then # Get latest version from master in git - VERSION_TAG=`curl -s "https://raw.githubusercontent.com/passsy/flutter_wrapper/master/version"` - - starts_with_v=`echo "$VERSION_TAG" | cut -c 1` + VERSION_TAG=$(curl -s "https://raw.githubusercontent.com/passsy/flutter_wrapper/master/version") + + starts_with_v=$(echo "$VERSION_TAG" | cut -c 1) if [ "$starts_with_v" != "v" ]; then # add v prefix for tag if not present VERSION_TAG="v$VERSION_TAG" @@ -51,14 +51,13 @@ fi printf "Installing Flutter Wrapper $VERSION_TAG\n" - ### # Add .flutter submodule ### FLUTTER_DIR_NAME='.flutter' # Check if submodule already exists (when updating flutter wrapper) -HAS_SUBMODULE=`git submodule | grep "\ \.flutter"` +HAS_SUBMODULE=$(git submodule | grep "\ \.flutter") if [ -z "$HAS_SUBMODULE" ]; then printf "adding '.flutter' submodule\n" UPDATED=false @@ -76,7 +75,7 @@ else UPDATED=true # Update old ssh url to https - USES_SSH=`git config --file=.gitmodules submodule.\.flutter.url | cut -c 1-4` + USES_SSH=$(git config --file=.gitmodules submodule.\.flutter.url | cut -c 1-4) if [ "$USES_SSH" = "git@" ]; then printf "Update .flutter submodule url to https\n" git config --file=.gitmodules submodule.\.flutter.url https://github.com/flutter/flutter.git @@ -85,7 +84,6 @@ else fi fi - ### # Downlaod flutterw exectuable ### @@ -105,13 +103,12 @@ chmod 755 flutterw sed -i.bak "s/VERSION_PLACEHOLDER/$VERSION_TAG/g" flutterw && rm flutterw.bak # Replace date placeholder in wrapper -DATE=`date '+%Y-%m-%d %H:%M:%S'` +DATE=$(date '+%Y-%m-%d %H:%M:%S') sed -i.bak "s/DATE_PLACEHOLDER/$DATE/g" flutterw && rm flutterw.bak # add it to git git add flutterw - ### # Downlaod flutterw exectuable ### @@ -119,7 +116,7 @@ git add flutterw # bind this flutter instance to the project (update .packages file) ./flutterw packages get -if $UPDATED ; then +if $UPDATED; then printf "\nFlutter Wrapper updated to version $VERSION_TAG\n\n" else printf "\nFlutter Wrapper installed (version $VERSION_TAG), initialized with channel stable.\n\n" diff --git a/uninstall.sh b/uninstall.sh index 75be1a5..4be95ce 100755 --- a/uninstall.sh +++ b/uninstall.sh @@ -6,7 +6,7 @@ FLUTTER_DIR_NAME='.flutter' # remove wrapper executable via git or fallback just the wrapper file when not # known to git -git rm -f flutterw >> /dev/null 2>&1 || rm flutterw +git rm -f flutterw >>/dev/null 2>&1 || rm flutterw # remove submodule git submodule deinit -f $FLUTTER_DIR_NAME @@ -20,5 +20,5 @@ rm -rf .git/modules/$FLUTTER_DIR_NAME # remove empty .gitmodules file if ! [ -s .gitmodules ]; then # try via git first, fallback to just rm when not added to git - git rm -f .gitmodules >> /dev/null 2>&1 || rm .gitmodules + git rm -f .gitmodules >>/dev/null 2>&1 || rm .gitmodules fi