glitch-soc/dist/setupprod.sh
2019-07-10 03:26:51 -04:00

98 lines
2.9 KiB
Bash
Executable file

#!/usr/bin/env bash
RAILS_ENV=production
NODE_ENV=production
function installDebDeps {
. /etc/os-release
# install curl
sudo apt install curl gnupg --no-install-recommends -y
# setup node repo if not running ubuntu
if [ $NAME == "Ubuntu" && $VERSION_ID -ge "18.04" ]
then
echo "Skipping node repository since it's uneccessary on this OS"
else
curl -sL https://deb.nodesource.com/setup_8.x | sudo bash -
fi
# setup yarn repo
curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
# update repos
sudo apt update
# install needed libraries & programs for ruby & mastodon
sudo apt install --no-install-recommends -y imagemagick ffmpeg libpq-dev libxml2-dev libxslt1-dev file \
g++ libprotobuf-dev protobuf-compiler pkg-config nodejs gcc autoconf libjemalloc-dev \
bison build-essential libssl-dev libyaml-dev libreadline-dev \
zlib1g-dev libncurses5-dev libffi-dev libgdbm-dev \
redis-server redis-tools postgresql postgresql-contrib \
yarn libidn11-dev libicu-dev libjemalloc-dev
}
function installRuby {
# setup rbenv
git clone https://github.com/rbenv/rbenv.git $HOME/.rbenv
cd $HOME/.rbenv && src/configure && make -C src
# add rubyenv to bashrc
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> $HOME/.bashrc
echo 'eval "$(rbenv init -)"' >> $HOME/.bashrc
# apply env
export PATH="$HOME/.rbenv/bin:$PATH"
eval "$(rbenv init -)"
# install ruby-build
git clone https://github.com/rbenv/ruby-build.git ~/.rbenv/plugins/ruby-build
# build and install ruby with jemalloc
if [[ *$rbMasto* == $rbVersions ]]; then
RUBY_CONFIGURE_OPTS=--with-jemalloc rbenv install $rbMasto
fi
}
function installMasto {
# create database user
echo "CREATE USER $(whoami) CREATEDB;" | sudo -u postgres psql
# update gem
printf 'y\n' | gem update --system --no-document
# install ruby and nodejs deps
gem install bundler --no-document
bundle install -j$(getconf _NPROCESSORS_ONLN) --deployment --without development test
yarn install --pure-lockfile
# setup db
bundle exec rake mastodon:setup
}
function installServices {
SYSDIR=/etc/systemd/system
# Copy service files
sudo cp dist/mastodon-*.service $SYSDIR/
sudo cp dist/mastodon.target $SYSDIR/
# Set the correct paths for the services
sudo sed -i -e 's#workdir#'$PWD'#g' $SYSDIR/mastodon-*.service
sudo sed -i -e 's#homedir#'$HOME'#g' $SYSDIR/mastodon-*.service
# Re-read service files and set mastodon to start on boot
sudo systemctl daemon-reload
sudo systemctl enable mastodon.target
}
installDebDeps
installRuby
installMasto
installServices
# Uncomment to install all the extra themes
#git submodule update --init --recursive
# Done!
echo "Setup done! Make any changes to .env.production if necessary and then run 'sudo systemctl start mastodon.target'"