Skip to content

Instantly share code, notes, and snippets.

@forsvunnet
Last active October 19, 2023 14:31
Show Gist options
  • Save forsvunnet/e3c5eb78462bb6c0ff88ee86a5a577b7 to your computer and use it in GitHub Desktop.
Save forsvunnet/e3c5eb78462bb6c0ff88ee86a5a577b7 to your computer and use it in GitHub Desktop.
Script to install a headless version of statamic ready with graphQL
#!/bin/bash
COMPOSER=/usr/local/bin/composer
STATAMIC=~/.composer/vendor/bin/statamic
if [ ! -f "$COMPOSER" ]; then
echo "Composer CLI not found"
exit 1
fi
if [ ! -f "$STATAMIC" ]; then
echo "Statamic CLI not found"
exit 1
fi
if [ -z "$1" ]; then
# Statamic headless CMS using graphql
read -p "Project name:" PROJECT_NAME
else
PROJECT_NAME=$1
fi
DIR="`pwd`/$PROJECT_NAME"
if [ -d "$DIR" ]; then
echo "Dir, $DIR, already exist"
exit 1
fi
echo "Final dir will be: $DIR"
while true
do
read -r -p "Are You Sure? [Y/n] " input
case $input in
[yY][eE][sS]|[yY]|'')
echo "Yes"
break
;;
[nN][oO]|[nN])
exit 1
;;
*)
echo "Please answer yes or no"
;;
esac
done
$STATAMIC new $PROJECT_NAME -n
cd $PROJECT_NAME
$COMPOSER require spatie/statamic-responsive-images
sed -i'' -e "/DB_CONNECTION=mysql/,\$d" .env
sed -i'' -e "s/STATAMIC_GRAPHQL_ENABLED=false/STATAMIC_GRAPHQL_ENABLED=true/g" .env
sed -i'' -e "s/STATAMIC_REVISIONS_ENABLED=false/STATAMIC_REVISIONS_ENABLED=true/g" .env
sed -i'' -e "s/STATAMIC_GIT_ENABLED=false/STATAMIC_GIT_ENABLED=true/g" .env
sed -i'' -e "/DB_CONNECTION=mysql/,\$d" .env.example
sed -i'' -e "s/STATAMIC_GRAPHQL_ENABLED=false/STATAMIC_GRAPHQL_ENABLED=true/g" .env.example
sed -i'' -e "s/STATAMIC_REVISIONS_ENABLED=false/STATAMIC_REVISIONS_ENABLED=true/g" .env.example
sed -i'' -e "s/STATAMIC_GIT_ENABLED=false/STATAMIC_GIT_ENABLED=true/g" .env.example
sed -i'' -e "s/'pro' => false/'pro' => env\('STATAMIC_PRO_ENABLED'\)/g" config/statamic/editions.php
sed -i'' -e "s/'paths' => \['api\/\*'\]/'paths' => ['graphql']/g" config/cors.php
sed -i'' -e "s/'enabled' => true/'enabled' => false/g" config/statamic/routes.php
echo STATAMIC_PRO_ENABLED=false >> .env
read -p "Git username for statamic: " STATAMIC_GIT_USER_NAME
read -p "Git email: " STATAMIC_GIT_USER_EMAIL
echo STATAMIC_GIT_USER_NAME=\"$STATAMIC_GIT_USER_NAME\" >> .env
echo STATAMIC_GIT_USER_EMAIL=$STATAMIC_GIT_USER_EMAIL >> .env
echo STATAMIC_GIT_PUSH=true >> .env
php artisan config:clear
php artisan cache:clear
$COMPOSER dumpautoload
php artisan statamic:make:user
git init
echo #
echo "Hey, Listen!"
echo #
echo #
echo "http://$PROJECT_NAME.test/cp"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment