Snippets

profile://github.com/delan Mastodon on OpenBSD was a nightmare

Created by Delan Azabani
#!/bin/sh
set -eux

pkg_add -Ua ImageMagick ffmpeg postgresql-client libxml libxslt git g++\%8 protobuf gcc\%8 autoconf\%2.69 bison openssl\%1.1 libyaml libffi gdbm nginx redis postgresql-server postgresql-contrib libidn icu4c

# for rbenv ### pkg_add -a curl bash

# for 2.2.0 ### pkg_add -a ruby\%2.5
# for 2.7.0 ### pkg_add -a ruby\%2.6

# for 2.2.0 ### gem25 install bundler:1.16.1
# for 2.5.0 ### gem25 install bundler:1.16.3
# for 2.7.0 ### gem26 install bundler:1.17.3

# for 2.2.0 ### pkg_add /usr/ports/packages/amd64/all/node-8.12.0p1.tgz
# for 2.5.0 ### pkg_add node

# workaround for nokogiri 1.8.1 (LZMA_OK compile error)
ln -sf /usr/local/include/lzma.h /usr/local/include/lzma /usr/include

su -l mastodon_ ./user.sh
#!/bin/sh
set -eux

export CC=x86_64-unknown-openbsd6.5-egcc
export CXX=x86_64-unknown-openbsd6.5-eg++

git_check() {
	git rev-parse --resolve-git-dir "$1/.git" > /dev/null 2>&1
}

git_clone() {
	destination="$1"; shift
	source="$1"; shift

	if ! git_check "$destination"; then
		git clone "$@" -- "$source" "$destination"
	fi
}

# git_clone ~/.rbenv https://github.com/rbenv/rbenv
# git_clone ~/.rbenv/plugins/ruby-build https://github.com/rbenv/ruby-build
# export PATH=~/.rbenv/bin:$PATH
# eval "$(rbenv init - ksh)"
# rbenv install 2.5.1
# rbenv global 2.5.1

git_clone ~/mastodon https://github.com/tootsuite/mastodon -b v2.2.0 --depth 1
cd ~/mastodon

# brianmario/charlock_holmes#127
sed -Ei '/^(gem '\''charlock_holmes'\''), '\''~> 0[.]7[.]5'\''$/s//\1, '\''~> 0.7.6'\''/' Gemfile
sed -Ei '/^(    charlock_holmes) [(]0[.]7[.]5[)]$/s//\1 (0.7.6)/' Gemfile.lock
sed -Ei '/^(  charlock_holmes) [(]~> 0[.]7[.]5[)]$/s//\1 (~> 0.7.6)/' Gemfile.lock

bundle25 install -j "$(getconf NPROCESSORS_ONLN)" --deployment --without 'development test'

# https://npm.community/t/crash-npm-err-cb-never-called/858
if [ $(sysctl -n kern.maxfiles) -lt 20000 ]; then
	>&2 printf 'fatal: %s\n' 'please set sysctl(8) variable kern.maxfiles to at least 20000'
	exit 1
elif [ $(ulimit -n) -lt 10000 ]; then
	>&2 printf 'fatal: %s\n' 'please set openfiles[-cur] to at least 1000 in login.conf(5)'
	>&2 printf 'fatal: %s\n' 'for example: mastodon_:openfiles=10000:tc=daemon:'
	exit 1
fi

# uws@^8.14.0 no longer installs properly on Node.js 10 (V8 API changes)
version=$(node -v)
if [ ${version%%.*} = v10 ]; then
	>&2 printf 'fatal: %s\n' 'this version of Mastodon is incompatible with Node.js 10'
	>&2 printf 'fatal: %s %s %s %s %s\n' 'for OpenBSD 6.5-release, try to build' \
		'node-8.12.0p1.tgz by checking out your ports tree at OPENBSD_6_5_BASE' \
		'then typing: mkdir -p ...; cvsps -g -p ... -f lang/node/Makefile -r' \
		'OPENBSD_6_4_BASE -r OPENBSD_6_5_BASE -l objections; patch -Rfp1 <' \
		'.../145752.patch; cd lang/node; make; doas make install'
	exit 1
fi

# rake assets:precompile has a hard dependency on yarn
mkdir -p .../local
cd .../local
npm init -y
npm install yarn
cd -

export PATH=$(pwd)/.../local/node_modules/.bin:$PATH

# package.json also needs to be installed with yarn rather
# than npm, or else some emoji picker assets will fail to
# compile with module not found errors (as of 2.2.0)
yarn install --pure-lockfile

export RAILS_ENV=production

# not available until 2.3.0 (tootsuite/documentation#562)
# bundle25 exec rake mastodon:setup

cp /.back/mastodon/.env.production .

# or s/rake/rails/
bundle25 exec rake db:migrate
bundle25 exec rake assets:precompile

# tmux new-session -ds mastodon
#!/bin/sh
set -eux

export CC=x86_64-unknown-openbsd6.5-egcc
export CXX=x86_64-unknown-openbsd6.5-eg++

git_check() {
	git rev-parse --resolve-git-dir "$1/.git" > /dev/null 2>&1
}

git_clone() {
	destination="$1"; shift
	source="$1"; shift

	if ! git_check "$destination"; then
		git clone "$@" -- "$source" "$destination"
	fi
}

cd ~/mastodon
git fetch --depth 1 origin v2.3.0
git reset --hard FETCH_HEAD

# brianmario/charlock_holmes#127
sed -Ei '/^(gem '\''charlock_holmes'\''), '\''~> 0[.]7[.]5'\''$/s//\1, '\''~> 0.7.6'\''/' Gemfile
sed -Ei '/^(    charlock_holmes) [(]0[.]7[.]5[)]$/s//\1 (0.7.6)/' Gemfile.lock
sed -Ei '/^(  charlock_holmes) [(]~> 0[.]7[.]5[)]$/s//\1 (~> 0.7.6)/' Gemfile.lock

bundle25 install -j "$(getconf NPROCESSORS_ONLN)" --deployment --without 'development test'

# https://npm.community/t/crash-npm-err-cb-never-called/858
if [ $(sysctl -n kern.maxfiles) -lt 20000 ]; then
	>&2 printf 'fatal: %s\n' 'please set sysctl(8) variable kern.maxfiles to at least 20000'
	exit 1
elif [ $(ulimit -n) -lt 10000 ]; then
	>&2 printf 'fatal: %s\n' 'please set openfiles[-cur] to at least 1000 in login.conf(5)'
	>&2 printf 'fatal: %s\n' 'for example: mastodon_:openfiles=10000:tc=daemon:'
	exit 1
fi

# uws@^8.14.0 no longer installs properly on Node.js 10 (V8 API changes)
version=$(node -v)
if [ ${version%%.*} = v10 ]; then
	>&2 printf 'fatal: %s\n' 'this version of Mastodon is incompatible with Node.js 10'
	>&2 printf 'fatal: %s %s %s %s %s\n' 'for OpenBSD 6.5-release, try to build' \
		'node-8.12.0p1.tgz by checking out your ports tree at OPENBSD_6_5_BASE' \
		'then typing: mkdir -p ...; cvsps -g -p ... -f lang/node/Makefile -r' \
		'OPENBSD_6_4_BASE -r OPENBSD_6_5_BASE -l objections; patch -Rfp1 <' \
		'.../145752.patch; cd lang/node; make; doas make install'
	exit 1
fi

# rake assets:precompile has a hard dependency on yarn
mkdir -p .../local
cd .../local
npm init -y
npm install yarn
cd -

export PATH=$(pwd)/.../local/node_modules/.bin:$PATH

# package.json also needs to be installed with yarn rather
# than npm, or else some emoji picker assets will fail to
# compile with module not found errors (as of 2.2.0)
yarn install --pure-lockfile

export RAILS_ENV=production

# not available until 2.3.0 (tootsuite/documentation#562)
# bundle25 exec rake mastodon:setup

cp /.back/mastodon/.env.production .

# or s/rake/rails/
bundle25 exec rake db:migrate
bundle25 exec rake assets:precompile

# tmux new-session -ds mastodon
#!/bin/sh
set -eux

export CC=x86_64-unknown-openbsd6.5-egcc
export CXX=x86_64-unknown-openbsd6.5-eg++

git_check() {
	git rev-parse --resolve-git-dir "$1/.git" > /dev/null 2>&1
}

git_clone() {
	destination="$1"; shift
	source="$1"; shift

	if ! git_check "$destination"; then
		git clone "$@" -- "$source" "$destination"
	fi
}

cd ~/mastodon
git fetch --depth 1 origin v2.5.0
git reset --hard FETCH_HEAD

bundle25 install -j "$(getconf NPROCESSORS_ONLN)" --deployment --without 'development test'

# https://npm.community/t/crash-npm-err-cb-never-called/858
if [ $(sysctl -n kern.maxfiles) -lt 20000 ]; then
	>&2 printf 'fatal: %s\n' 'please set sysctl(8) variable kern.maxfiles to at least 20000'
	exit 1
elif [ $(ulimit -n) -lt 10000 ]; then
	>&2 printf 'fatal: %s\n' 'please set openfiles[-cur] to at least 1000 in login.conf(5)'
	>&2 printf 'fatal: %s\n' 'for example: mastodon_:openfiles=10000:tc=daemon:'
	exit 1
fi

# node-zopfli@^2.0.2 does not install properly (ENOENT in sed(1) for a gzip_container.o.d.raw),
# but yarn says that this isn't the end of the world because it's an optional dependency

# uws@10.148.0 doesn't install properly for reasons that are unclear (!g node-gyp fno-exceptions),
# but we can work around this with a wrapper for $CXX that appends -fexceptions
mkdir -p .../bin
rm -f .../bin/$CXX
> .../bin/$CXX printf '#!/bin/sh\nexec %s "$@" -fexceptions\n' "$(command -v $CXX)"
chmod +x .../bin/$CXX
export PATH=$(pwd)/.../bin:$PATH

# rake assets:precompile has a hard dependency on yarn
mkdir -p .../local
cd .../local
npm init -y
npm install yarn
cd -

export PATH=$(pwd)/.../local/node_modules/.bin:$PATH

# package.json also needs to be installed with yarn rather
# than npm, or else some emoji picker assets will fail to
# compile with module not found errors (as of 2.2.0)
yarn install --pure-lockfile

export RAILS_ENV=production

# not available until 2.3.0 (tootsuite/documentation#562)
# bundle25 exec rake mastodon:setup

cp /.back/mastodon/.env.production .

# rake assets:precompile has a hard dependency on ruby
mkdir -p .../bin
ln -sf $(command -v ruby25) .../bin/ruby
export PATH=$(pwd)/.../bin:$PATH

# or s/rake/rails/
SKIP_POST_DEPLOYMENT_MIGRATIONS=true bundle25 exec rake db:migrate
bundle25 exec rake assets:precompile

>&2 printf '%s; continue?\n' 'now restart all Mastodon processes'
read -r

bundle25 exec rake db:migrate

# tmux new-session -ds mastodon
#!/bin/sh
set -eux

# using g++%8/gcc%8 breaks assets:precompile with only node "size mismatch, relink your program"
# > maybe those errors are finally making a difference and I should try a different compiler

# using g++%4.9/gcc%4.9 breaks bundle26 install on nokogiri with "fatal error: stdalign.h" ENOENT
# > GCC's own fucking documentation says that stdalign.h was added in 4.7 but go off I guess
# > https://gcc.gnu.org/wiki/C11Status

# using clang++/clang breaks rake assets:precompile silently; output ends "Compilation failed:"
# > I guess I was right and "relink your program" was always a red herring

# trying webpack --config config/webpack/production.js (rails/webpacker#1677) reveals a SIGSEGV
# > lang/node has COMPILER = base-clang so it's clearly not the compiler so... fuck it I give up

export CC=clang
export CXX=clang++

git_check() {
	git rev-parse --resolve-git-dir "$1/.git" > /dev/null 2>&1
}

git_clone() {
	destination="$1"; shift
	source="$1"; shift

	if ! git_check "$destination"; then
		git clone "$@" -- "$source" "$destination"
	fi
}

cd ~/mastodon
git fetch --depth 1 origin v2.7.0
git reset --hard FETCH_HEAD

bundle26 install -j "$(getconf NPROCESSORS_ONLN)" --deployment --without 'development test'

# https://npm.community/t/crash-npm-err-cb-never-called/858
if [ $(sysctl -n kern.maxfiles) -lt 20000 ]; then
	>&2 printf 'fatal: %s\n' 'please set sysctl(8) variable kern.maxfiles to at least 20000'
	exit 1
elif [ $(ulimit -n) -lt 10000 ]; then
	>&2 printf 'fatal: %s\n' 'please set openfiles[-cur] to at least 1000 in login.conf(5)'
	>&2 printf 'fatal: %s\n' 'for example: mastodon_:openfiles=10000:tc=daemon:'
	exit 1
fi

export CC=x86_64-unknown-openbsd6.5-egcc
export CXX=x86_64-unknown-openbsd6.5-eg++

# uws@10.148.0 doesn't install properly for reasons that are unclear (!g node-gyp fno-exceptions),
# but we can work around this with a wrapper for $CXX that appends -fexceptions
mkdir -p .../bin
rm -f .../bin/$CXX
> .../bin/$CXX printf '#!/bin/sh\nexec %s "$@" -fexceptions\n' "$(command -v $CXX)"
chmod +x .../bin/$CXX
export PATH=$(pwd)/.../bin:$PATH

# rake assets:precompile has a hard dependency on yarn
mkdir -p .../local
cd .../local
npm init -y
npm install yarn
cd -
export PATH=$(pwd)/.../local/node_modules/.bin:$PATH

# package.json also needs to be installed with yarn rather
# than npm, or else some emoji picker assets will fail to
# compile with module not found errors (as of 2.2.0)
yarn install --pure-lockfile

export RAILS_ENV=production

# not available until 2.3.0 (tootsuite/documentation#562)
# bundle26 exec rake mastodon:setup

cp /.back/mastodon/.env.production .

# rake assets:precompile has a hard dependency on ruby
mkdir -p .../bin
ln -sf $(command -v ruby26) .../bin/ruby
export PATH=$(pwd)/.../bin:$PATH

# or s/rake/rails/
SKIP_POST_DEPLOYMENT_MIGRATIONS=true bundle26 exec rake db:migrate
bundle26 exec rake assets:precompile

yarn run webpack --config config/webpack/production.js

>&2 printf '%s; continue?\n' 'now restart all Mastodon processes'
read -r

bundle26 exec rake db:migrate

>&2 printf '%s; continue?\n' 'now restart all Mastodon processes'
read -r

# tmux new-session -ds mastodon

Comments (0)

HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.