Skip to content

Instantly share code, notes, and snippets.

@mikestecker
Last active May 9, 2023 17:49
Show Gist options
  • Save mikestecker/6535893235efa9aff5295e30cc66cfee to your computer and use it in GitHub Desktop.
Save mikestecker/6535893235efa9aff5295e30cc66cfee to your computer and use it in GitHub Desktop.
Bash script for my server setup with Digital Ocean, Server Pilot with Node, Gulp and Craft
For Buddy to be able to update NGINX and run other commands as root, you need to follow these steps to give the user buddy access.
If no user has been created, follow the guide here to create a user for Buddy:
https://www.digitalocean.com/community/tutorials/how-to-add-and-delete-users-on-ubuntu-16-04
1. On ubuntu based systems, run " $ sudo visudo "
2. this will open /etc/sudoers file.
3. If your buddy user is already in that file, then modify to look like this:
buddy ALL=(ALL) NOPASSWD: ALL
4. save the file by doing Ctrl+O (dont save in tmp file. save in /etc/sudoers, confirm overwrite)
5. Exit by doing Ctrl+X
6. Relaunch your buddy job
7. you shouldnt see that error message again :)
#!/bin/bash
##############################################################
# #
# Digital Ocean / Forge Recipe for CraftCMS websites #
# #
#============================================================#
# #
# Assumptions: #
# #
# - Stock Ubuntu 16.04 Digital Ocean droplet #
# - You are running this recipe as root #
# #
#============================================================#
# #
# References & Credits: #
# #
# Thanks to Andrew Welch & @nystudio107 folks. This recipe #
# rely heavily on their articles. #
# #
# Much of this was lifted from Rodrigo Passos: #
# https://gist.github.com/webrgp/ #
# fe13d7c61420632f85d5d81e76538fce #
# #
##############################################################
# Exit immediately if a simple command exits with a non-zero status (https://ss64.com/bash/set.html)
set -e
perform_craftcms_server_setup() {
# Check if the user is root
user="$(id -un 2>/dev/null || true)"
if [ "$user" != 'root' ]; then
cat >&2 <<-'EOF'
Error: this installer needs the ability to run commands as root.
We are unable to find either "sudo" or "su" available to make this happen.
EOF
exit 1
fi
# Create a playground directory to be remove at the end
mkdir ~/playground
cd ~/playground
# Install Digital Ocean Monitoring tools
curl -sSL https://agent.digitalocean.com/install.sh | sh
# Make sure you have tools in place
apt-get -y install autoconf automake libtool nasm make pkg-config git build-essential
# Install the latest Node.js (version 8.x as of writing)
# https://www.digitalocean.com/community/tutorials/how-to-install-node-js-on-ubuntu-16-04
curl -sL https://deb.nodesource.com/setup_8.x -o nodesource_setup.sh
sudo bash nodesource_setup.sh
sudo apt-get install nodejs
# Install Yarn
curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add -
echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list
apt-get update && apt-get -y install yarn
# Install the PHP ImageMagick Extension
# https://serverpilot.io/community/articles/how-to-install-the-php-imagemagick-extension.html
# Replace version number in commands below accordingly (version 7.1 as of writing)
apt-get -y install gcc make autoconf libc-dev pkg-config
apt-get -y install libmagickwand-dev
printf "\n" | pecl7.1-sp install imagick
# When prompted with:
# Please provide the prefix of Imagemagick installation [autodetect] :
# just press Enter; do not type a prefix (that is, allow autodetect).
# adding the prefix: printf "\n" will do this automatically. Example:
# printf "\n" | pecl7.1-sp install imagick
# Now tell PHP about it:
sudo bash -c "echo extension=imagick.so > /etc/php7.1-sp/conf.d/imagick.ini"
sudo service php7.1-fpm-sp restart
# Install jpegoptim, optipng, gifsicle, svgo & webp ( https://nystudio107.com/blog/creating-optimized-images-in-craft-cms )
apt-get -y install jpegoptim
apt-get -y install optipng
apt-get -y install gifsicle
apt-get -y install webp
npm install -g svgo
# Install Gulp for running build process
npm install gulp -g
# FOR REVIEW/MODIFICATIONS LATER:
# Install the nginx partials from https://github.com/nystudio107/nginx-craft
# git clone https://github.com/nystudio107/nginx-craft.git nginx-craft
# cp -R nginx-craft/nginx-partials /etc/nginx
# Clean up playground
cd ~
rm -rf ~/playground
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment