: ==========================================
: Introduction
: ==========================================
: curl -sL https://firebase.tools/dataconnect | bash
: -----------------------------------------
: Uninstalling - default false
: -----------------------------------------
: curl -sL https://firebase.tools/dataconnect | uninstall=true bash
: ==========================================
: Advanced Usage
: ==========================================
: -----------------------------------------
: Setup Flutter - default: false
: -----------------------------------------
: curl -sL https://firebase.tools/dataconnect | flutter=true bash
: ==========================================
: Source Code
: ==========================================
sorry() {
echo
echo "Something went wrong, local dev setup has not been finished."
echo "Please try manual installation to setup your development environment."
echo "https://firebase.google.com/docs/data-connect/quickstart?userflow=manual#prerequisites"
echo
exit 1
}
STANDALONE_INSTALL_PREFIX=$HOME/.local
if [ "$uninstall" = "true" ]; then
if [[ ! "$(firebase --tool:setup-check 2>&1)" == *bins* ]]; then
echo "Your \"firebase\" install was done via npm, not firebase.tools."
echo "Run \"npm uninstall -g firebase-tools\" to uninstall."
else
echo "-- Removing binary file..."
rm $(which firebase)
fi
echo "-- Removing emulator runtimes..."
rm -rf ~/.cache/firebase/emulators
echo "-- Removing npm cache..."
rm -rf ~/.cache/firebase/tools
echo "-- Removing firebase runtime..."
rm -rf ~/.cache/firebase/runtime
echo "-- Removing code-server installation"
rm -rf $STANDALONE_INSTALL_PREFIX/lib/code-server-*
rm -rf $HOME/.cache/code-server/code-server-*
echo "-- Removing code-server data + config"
rm -rf ~/.local/share/code-server ~/.config/code-server
echo "-- uninstallation finished"
echo "-- All Done!"
exit 0
fi
echo "-- Checking your machine type..."
UNAME=$(uname -s | tr '[:upper:]' '[:lower:]')
case "$UNAME" in
linux*) MACHINE=linux;;
darwin*) MACHINE=macos;;
esac
if [ -z "$MACHINE" ]
then
echo "Your operating system is not supported: $UNAME."
sorry
fi
uname_m=$(uname -m)
case $uname_m in
aarch64) ARCH=arm64 ;;
arm64) ARCH=arm64 ;;
x86_64) ARCH=amd64 ;;
esac
if [ -z "$ARCH" ]
then
echo "Your architecture is not supported: $uname_m."
sorry
fi
if [ "$MACHINE" = macos ] && [ "$ARCH" = arm64 ]; then
if ! arch -x86_64 /usr/bin/true 2> /dev/null; then
echo '----------------------------------------------------------------------------------'
echo 'Apple silicon detected. Rosetta is required to proceed. Attempting installation...'
echo '----------------------------------------------------------------------------------'
if ! softwareupdate --install-rosetta; then
echo
echo '-- Rosetta installation seems to have failed.'
echo 'Please try running the script again after installing Rosetta. Or, try manual setup:'
echo "https://firebase.google.com/docs/data-connect/quickstart?userflow=manual#prerequisites"
exit 1
fi
fi
fi
CODE=${CODE:-code}
if ! which "$CODE" >/dev/null 2>&1; then
CODE=code-server
if ! which code-server >/dev/null 2>&1; then
echo "-- Installing code-server"
curl -fsSL "https://code-server.dev/install.sh" | grep -v "Deploy code-server" | sh -s -- --prefix="$STANDALONE_INSTALL_PREFIX" --method=standalone || sorry
CODE="$STANDALONE_INSTALL_PREFIX/bin/code-server"
CODE_ARGS="--disable-telemetry"
fi
echo "-- Using code-server"
fi
if [ "$CODE"x = "code-server"x ] || [[ "$CODE" == */code-server ]]; then
LISTEN="127.0.0.1:${PORT:-9394}"
CONFIG_DIR="$HOME/.config/code-server"
CONFIG_YAML="$CONFIG_DIR/config.yaml"
mkdir -p "$CONFIG_DIR"
if ! [ -f "$CONFIG_YAML" ]; then
echo "bind-addr: '$LISTEN'" > "$CONFIG_YAML"
echo "auth: none" >> "$CONFIG_YAML"
echo "cert: false" >> "$CONFIG_YAML"
echo "open: true" >> "$CONFIG_YAML"
echo "disable-telemetry: true" >> "$CONFIG_YAML"
echo "disable-getting-started-override: true" >> "$CONFIG_YAML"
fi
fi
echo "-- Installing Firebase Data Connect extension"
"$CODE" $CODE_ARGS --uninstall-extension "firebase.firebase-vscode" >/dev/null 2>&1
if [ "$CODE"x = "code"x ] || [ "$CODE"x = "code-server"x ]; then
"$CODE" --install-extension "GoogleCloudTools.firebase-dataconnect-vscode" --force || sorry
else
echo "-- Downloading Firebase Data Connect extension"
VSIX_URL=$(curl -fsSL "https://open-vsx.org/api/GoogleCloudTools/firebase-dataconnect-vscode" | grep -oE '"https:[^"]*\.vsix"' | grep -oE '[^"]*' | head -n 1)
[ "$VSIX_URL"x != ""x ] || sorry
CACHE_DIR=$HOME/.cache
mkdir -p "$CACHE_DIR" || sorry
VSIX_FILE="$CACHE_DIR/firebase-dataconnect-vscode.vsix"
curl -fSL "$VSIX_URL"> "$VSIX_FILE" || sorry
"$CODE" $CODE_ARGS --install-extension "$VSIX_FILE" --force || sorry
fi
INSTALL_DIR="$STANDALONE_INSTALL_PREFIX/bin"
mkdir -p -- "$INSTALL_DIR" || sorry
DOWNLOAD_URL="https://firebase.tools/bin/$MACHINE/latest"
echo "-- Downloading Firebase CLI binary from $DOWNLOAD_URL"
curl -f -o "$INSTALL_DIR/firebase" -L --progress-bar $DOWNLOAD_URL || sorry
echo "-- Setting permissions on binary..."
chmod +rx "$INSTALL_DIR/firebase" || sorry
VERSION=$("$INSTALL_DIR/firebase" --version)
if [ -z "$VERSION" ]
then
echo "Something went wrong, firebase has not been installed."
sorry
fi
echo "-- Checking your PATH variable..."
if [[ ! ":$PATH:" == *":$INSTALL_DIR:"* ]]; then
echo ""
echo "It looks like $INSTALL_DIR isn't on your PATH."
echo "Please add the following line to either your ~/.profile or ~/.bash_profile, then restart your terminal."
echo ""
echo "PATH=\$PATH:$INSTALL_DIR"
echo ""
echo "For more information about modifying PATHs, see https://unix.stackexchange.com/a/26059"
echo ""
fi
echo "-- firebase-tools@$VERSION is now installed"
export FIREBASE_BINARY="$STANDALONE_INSTALL_PREFIX/bin/firebase"
export PATH="$STANDALONE_INSTALL_PREFIX/bin:$PATH"
if [ "$flutter"x != ""x ]; then
path_str="export PATH=\$PATH"
if ! [ -x "$(command -v flutter)" ]; then
echo '-- Flutter not found.' >&2
echo "-- Installing Flutter"
if [ "$MACHINE" = macos ]; then
if [ "$ARCH" = amd64 ]; then
export FLUTTER_DOWNLOAD_PATH="https://storage.googleapis.com/flutter_infra_release/releases/stable/macos/flutter_macos_3.24.3-stable.zip"
export FLUTTER_FILE_NAME="flutter_macos_3.24.3-stable.zip"
else
export FLUTTER_DOWNLOAD_PATH="https://storage.googleapis.com/flutter_infra_release/releases/stable/macos/flutter_macos_arm64_3.24.3-stable.zip"
export FLUTTER_FILE_NAME="flutter_macos_arm64_3.24.3-stable.zip"
fi
else
export FLUTTER_DOWNLOAD_PATH="https://storage.googleapis.com/flutter_infra_release/releases/stable/linux/flutter_linux_3.24.3-stable.tar.xz"
export FLUTTER_FILE_NAME="flutter_linux_3.24.3-stable.tar.xz"
fi
mkdir -p ~/development
mkdir -p ~/.cache
export FLUTTER_FILE_PATH="$HOME/.cache/$FLUTTER_FILE_NAME"
if [ -f $FLUTTER_FILE_PATH ]; then
echo "-- skipping download of flutter zip"
else
echo "-- Downloading flutter"
curl -f -o "$FLUTTER_FILE_PATH" -L --progress-bar $FLUTTER_DOWNLOAD_PATH || sorry
fi
if [ "$MACHINE" = macos ]; then
echo "-- Unzipping flutter"
unzip $FLUTTER_FILE_PATH \
-d ~/development/
else
echo "-- Untarring flutter"
tar -xf $FLUTTER_FILE_PATH -C ~/development/
fi
path_str+=":$HOME/development/flutter/bin"
else
echo "-- Flutter installation found. Skipping installation."
fi
if ! [ -x "$(command -v flutterfire)" ]; then
echo "-- Installing flutterfire"
export PATH="$HOME/development/flutter/bin:$HOME/.pub-cache/bin:$PATH"
echo "Please add the following line to either your ~/.profile or ~/.bash_profile, then restart your terminal."
echo ""
echo "$path_str:$HOME/.pub-cache/bin"
echo ""
echo "For more information about modifying PATHs, see https://unix.stackexchange.com/a/26059"
echo ""
dart pub global activate flutterfire_cli
else
echo "-- 'flutterfire' command found. Skipping installation"
fi
fi
if [ "$(pwd -P)" = "$HOME" ]; then
SAMPLE_DIR="$HOME/.cache/firebase/placeholder"
README_RELPATH="FIREBASE_INSTRUCTIONS.md"
mkdir -p "$SAMPLE_DIR"
README="$SAMPLE_DIR/$README_RELPATH"
echo '# Editor setup successful!' > "$README"
echo 'To get started with Firebase Data Connect, open a folder via **Menu > File > Open Folder...**' >> "$README"
echo 'Then, click the Firebase Data Connect logo from the left panel.' >> "$README"
echo >> "$README"
echo 'A project directory is required for development. (You may create a blank new one if needed.)' >> "$README"
echo 'For more information, see: https://firebase.google.com/docs/data-connect/quickstart?userflow=automatic#set_up_the_development_environment' >> "$README"
echo '(To skip this message, `cd` to your project directory before you run the setup script.)' >> "$README"
else
README_DIR=".firebase"
README_RELPATH="$README_DIR/INSTRUCTIONS.md"
README="$PWD/$README_RELPATH"
mkdir -p "$PWD/$README_DIR"
if [ -f "$README" ]; then
README=
else
echo '# Editor setup successful!' > "$README"
echo >> "$README"
echo 'To start, click the Firebase Data Connect logo from the left panel.' >> "$README"
echo >> "$README"
echo 'For more information, see: https://firebase.google.com/docs/data-connect/quickstart?userflow=automatic#set_up_your_project_directory' >> "$README"
fi
fi
if [ "$CODE"x = "code-server"x ] || [[ "$CODE" == */code-server ]]; then
FOLDER=${SAMPLE_DIR:-$PWD}
"$CODE" $CODE_ARGS \
--auth=none \
--disable-update-check \
--disable-workspace-trust \
--disable-proxy \
--ignore-last-opened \
--bind-addr "$LISTEN" \
--open \
"$FOLDER" | (
while read line; do
echo "$line"
case $line in
*"HTTP server listening on "*)
URL="${line##* }"
(
sleep 3
echo
echo ' +-----------------------------------------------------------------+'
echo ' | A new tab with the code editor can be found your browser now. |'
echo ' | If not, paste the following URL in the address bar: |'
echo ' +-----------------------------------------------------------------+'
echo " $URL"
echo
)&
;;
*"Session server listening on "*)
if [ "$README"x != ""x ]; then
(
sleep 3 && \
"$CODE" $CODE_ARGS --reuse-window "$README" >/dev/null 2>&1 || \
sleep 5 && \
"$CODE" $CODE_ARGS --reuse-window "$README" >/dev/null 2>&1 || \
sleep 8 && \
"$CODE" $CODE_ARGS --reuse-window "$README" >/dev/null 2>&1
)&
fi
;;
esac
done
)
else
OPEN_PATH="$PWD"
if [ "$README"x != ""x ]; then
if [ "$SAMPLE_DIR"x == ""x ]; then
CODE_ARGS="$CODE_ARGS --goto $README_RELPATH:1"
else
OPEN_PATH="$README"
CODE_ARGS="$CODE_ARGS --new-window"
fi
fi
"$CODE" $CODE_ARGS "$OPEN_PATH" || sorry
echo
echo ' +-------------------------------------------------------------------+'
echo ' | A VS Code editor window should be opened and you can start by |'
echo ' | clicking the Firebase Data Connect logo in the left-panel. |'
echo ' | If not, launch VS Code manually and open your project directory. |'
echo ' +-------------------------------------------------------------------+'
echo
fi