Skip to content

Instantly share code, notes, and snippets.

@gregfenton
Last active June 16, 2023 23:04
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gregfenton/902bd168a610107045ca2e6912151eb9 to your computer and use it in GitHub Desktop.
Save gregfenton/902bd168a610107045ca2e6912151eb9 to your computer and use it in GitHub Desktop.
Shell script for creating a Firebase project
#!/bin/bash
red=$(tput setaf 1)
green=$(tput setaf 2)
blue=$(tput setaf 6)
yellow=$(tput setaf 3)
reset=$(tput sgr0)
ROOT=$(pwd)
echo ""
echo "πŸ”₯πŸ”₯πŸ”₯ ${blue}FB Init ${reset}πŸ”₯πŸ”₯πŸ”₯"
echo ""
echo -n "Enter a ${blue}Project ID: ${reset}"
read projectID
echo "Project ID (${projectID})"
#----
# DO ALL OF OUR WORK FROM WITHIN THE FIREBASE DIRECTORY
#
mkdir ${ROOT}/firebase
cd ${ROOT}/firebase
if [[ $? -ne 0 ]]; then
echo ""
echo "${red}YIKES! Failed to cd to (${ROOT}/firebase)"
echo "${red}Exiting...${reset}"
echo ""
exit 1
fi
firebase login
echo "${green}Creating the Firebase project..."
if firebase projects:create --display-name $projectID $projectID; then
echo "${green}Success!${reset}"
else
echo "${red}Failed to create project ($projectID)${reset}"
echo "${red}Name not valid? Try with a different one${reset}"
echo "${red}Exiting...${reset}"
exit
fi
open https://console.firebase.google.com/project/$projectID/firestore
echo ""
echo "${yellow}Please enable ${red}Firestore${yellow} (click 'create database') in the browser that just opened.${reset}"
echo ""
echo -n "press ENTER to continue: "
read waiting
open https://console.firebase.google.com/project/$projectID/functions
echo ""
echo "${yellow}Please enable ${red}Functions${yellow} in the browser that just opened.${reset}"
echo "You will need to upgrade the project to the ${blue}Blaze${reset} plan"
echo ""
echo -n "press ENTER to continue: "
read waiting
open https://console.firebase.google.com/project/$projectID/storage
echo ""
echo "${yellow}Please enable ${red}Hosting${yellow} in the browser that just opened.${reset}"
echo ""
echo -n "press ENTER to continue: "
read waiting
open https://console.firebase.google.com/project/$projectID/hosting
echo ""
echo "${yellow}Please enable ${red}Storage${yellow} in the browser that just opened.${reset}"
echo ""
echo -n "press ENTER to continue: "
read waiting
echo ""
echo "${yellow}Now init Firebase with ${green}Firestore${reset}, ${green}Functions${reset}, "
echo "${green}Hosting${reset}, and ${green}Storage${reset} and then select the new Firebase"
echo "project ${blue}${projectID}${reset}"
echo ""
sleep 1s
# project was created above; this creates/updates FB config files on this machine
firebase -P ${projectID} init
if [[ $? -ne 0 ]]; then
echo ""
echo "${red}YIKES!${reset} The command ${yellow}firebase init${reset} failed."
echo "${red}Exiting...${reset}"
echo ""
exit 1
fi
WEB_APP_NAME="${projectID}-web"
echo ""
echo "${green}Creating web app: ${blue}${WEB_APP_NAME}${reset}"
echo ""
firebase -P ${projectID} apps:create web "${WEB_APP_NAME}"
echo ""
echo "${green}Writing project client SDK config data to ${yellow}./firebaseConfig.json${reset}:"
echo ""
firebase -P ${projectID} apps:sdkconfig |
awk '/initializeApp/{found=1; print "{";next}/\}\);/{print "}";next}{if(found)print}' \
> ./firebaseConfig.json
open https://console.firebase.google.com/u/0/project/$projectID/authentication/providers
echo ""
echo "${yellow}Please enable Email/Password sign in with Firebase Authentication in the browser that just opened.${reset}"
echo -n "press enter when complete: "
read waiting
echo "${green}deps installed"
echo "${green}config set"
echo "${green}initialization complete"
echo "πŸ”₯ πŸ§—πŸΌβ€β™‚οΈ πŸ” ${blue}GOOD TO GO${reset} πŸ” πŸ§—πŸΌβ€β™‚οΈ πŸ”₯"
echo -n "press enter to exit... "
read waiting
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment