Skip to content

Commit

Permalink
Format code using shfmt
Browse files Browse the repository at this point in the history
  • Loading branch information
passsy committed Sep 10, 2019
1 parent e15423f commit fcecf2c
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 39 deletions.
36 changes: 17 additions & 19 deletions flutterw
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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" "$@"
Expand Down Expand Up @@ -99,4 +97,4 @@ if [ $FLUTTER_EXIT_STATUS -eq 0 ]; then
fi
fi

exit $FLUTTER_EXIT_STATUS
exit $FLUTTER_EXIT_STATUS
33 changes: 15 additions & 18 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand All @@ -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
Expand All @@ -85,7 +84,6 @@ else
fi
fi


###
# Downlaod flutterw exectuable
###
Expand All @@ -105,21 +103,20 @@ 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
###

# 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"
Expand Down
4 changes: 2 additions & 2 deletions uninstall.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

0 comments on commit fcecf2c

Please sign in to comment.