2021-04-24 14:48:13 +00:00
|
|
|
#!/bin/sh
|
|
|
|
# Fallar ante cualquier error
|
|
|
|
set -e
|
|
|
|
|
2021-05-25 13:48:32 +00:00
|
|
|
DIR="$(dirname "$(realpath "$0")")"
|
2021-04-24 14:48:13 +00:00
|
|
|
|
2021-05-25 13:51:10 +00:00
|
|
|
# Sólo se puede correr desde el directorio de Sutty
|
|
|
|
if test "$(dirname "$DIR")" != "$(dirname "$PWD")"; then
|
|
|
|
echo "¡No estás corriendo dentro de una carpeta dentro de Sutty!"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2021-04-24 14:48:13 +00:00
|
|
|
# Por ahora sólo soportamos x86_64
|
|
|
|
uname -m | grep -q x86_64 || exit 1
|
|
|
|
|
|
|
|
# Sutty tiene que estar clonada en el directorio anterior
|
|
|
|
test -d ../sutty/.git || git clone git@0xacab.org:sutty/sutty.git ../sutty
|
|
|
|
|
2021-05-16 16:22:58 +00:00
|
|
|
# Podemos cambiar el entorno
|
|
|
|
ENTORNO=${ENTORNO:-../hain}
|
2021-04-24 14:48:13 +00:00
|
|
|
|
2021-05-16 15:45:16 +00:00
|
|
|
correr() {
|
2021-04-26 16:03:36 +00:00
|
|
|
echo "> $1"
|
2021-04-24 14:48:13 +00:00
|
|
|
|
2021-04-26 16:03:36 +00:00
|
|
|
# Necesitamos bubblewrap
|
|
|
|
type bwrap >/dev/null || exit 1
|
2021-04-24 14:48:13 +00:00
|
|
|
|
2021-05-16 15:45:16 +00:00
|
|
|
mkdir -p "$ENTORNO/home"
|
2021-04-28 18:16:30 +00:00
|
|
|
# migrar de versiones anteriores de hainish
|
2021-05-16 15:45:16 +00:00
|
|
|
test -d "$ENTORNO$HOME" && mv "$ENTORNO$HOME" "$ENTORNO/home/suttier"
|
2021-04-28 18:16:30 +00:00
|
|
|
|
2021-04-26 16:03:36 +00:00
|
|
|
env -i \
|
2021-04-27 18:29:15 +00:00
|
|
|
TERM="$TERM" \
|
2021-04-26 16:03:36 +00:00
|
|
|
USER="$USER" \
|
2021-04-28 18:16:30 +00:00
|
|
|
HOME="/home/suttier" \
|
2021-04-26 16:03:36 +00:00
|
|
|
RAILS_ENV=development \
|
2021-05-08 23:22:42 +00:00
|
|
|
HAIN_ENV=true \
|
2021-04-26 16:03:36 +00:00
|
|
|
bwrap \
|
|
|
|
--unshare-user-try \
|
|
|
|
--unshare-ipc \
|
|
|
|
--unshare-uts \
|
|
|
|
--unshare-cgroup-try \
|
|
|
|
--bind "$ENTORNO" / \
|
|
|
|
--bind .. /Sutty \
|
|
|
|
--ro-bind /etc/hosts /etc/hosts \
|
|
|
|
--ro-bind /etc/passwd /etc/passwd \
|
|
|
|
--ro-bind /etc/group /etc/group \
|
|
|
|
--ro-bind /etc/resolv.conf /etc/resolv.conf \
|
|
|
|
--ro-bind /etc/localtime /etc/localtime \
|
|
|
|
--dev-bind /dev /dev \
|
|
|
|
--dev-bind /sys /sys \
|
|
|
|
--dev-bind /proc /proc \
|
|
|
|
--dev-bind /tmp /tmp \
|
2021-05-25 13:51:10 +00:00
|
|
|
--chdir "/Sutty/${PWD##*/}" \
|
2021-04-26 16:03:36 +00:00
|
|
|
/bin/sh -l -c "$1"
|
|
|
|
}
|
2021-04-24 14:48:13 +00:00
|
|
|
|
2021-05-16 15:45:16 +00:00
|
|
|
crear_entorno() {
|
|
|
|
ALPINE="3.13.5"
|
2021-04-26 16:03:36 +00:00
|
|
|
ALPINE_URL="https://dl-cdn.alpinelinux.org/alpine/v${ALPINE%.*}/releases/x86_64/alpine-minirootfs-${ALPINE}-x86_64.tar.gz"
|
2021-04-24 14:48:13 +00:00
|
|
|
|
2021-04-26 16:03:36 +00:00
|
|
|
# Definir si vamos a usar wget o curl
|
|
|
|
type wget >/dev/null && download="wget -O -"
|
|
|
|
type busybox >/dev/null && download="busybox wget -O -"
|
|
|
|
type curl >/dev/null && download="curl"
|
2021-04-24 14:48:13 +00:00
|
|
|
|
2021-04-26 16:03:36 +00:00
|
|
|
# Si no hay ninguno de los dos, salir
|
|
|
|
test -z "${download}" && exit 1
|
2021-04-24 14:48:13 +00:00
|
|
|
|
2021-04-26 16:03:36 +00:00
|
|
|
# Darle permiso de lectura a otres también
|
|
|
|
umask 022
|
2021-04-24 14:48:13 +00:00
|
|
|
|
2021-04-26 16:03:36 +00:00
|
|
|
# Crear el directorio de trabajo
|
2021-05-16 16:33:32 +00:00
|
|
|
mkdir -p "$ENTORNO"
|
2021-04-24 14:48:13 +00:00
|
|
|
|
2021-04-26 16:03:36 +00:00
|
|
|
# Descargar y extraer Alpine
|
2021-05-16 16:33:32 +00:00
|
|
|
test -f "$ENTORNO/etc/os-release" || ${download} "${ALPINE_URL}" | tar xz --directory "$ENTORNO"
|
2021-04-24 14:48:13 +00:00
|
|
|
|
2021-04-26 16:03:36 +00:00
|
|
|
# Instalar las dependencias
|
|
|
|
echo "Instalando paquetes..."
|
|
|
|
correr "apk add --no-cache \
|
|
|
|
libxslt libxml2 libssh2 postgresql-libs sqlite-libs \
|
|
|
|
tzdata bash ffmpeg vips file git make \
|
|
|
|
ruby ruby-bundler ruby-json ruby-bigdecimal ruby-irb ruby-rake \
|
|
|
|
nodejs yarn \
|
2021-05-08 21:31:13 +00:00
|
|
|
gnutls-utils nginx \
|
2021-05-27 23:35:45 +00:00
|
|
|
less \
|
|
|
|
py3-cffi py3-brotli py3-fonttools"
|
2021-04-26 16:03:36 +00:00
|
|
|
|
|
|
|
# Habilitar la instalación de gemas binarias
|
|
|
|
sed -re "s/#(@platforms = )/\1/" -i "$ENTORNO/usr/lib/ruby/2.7.0/rubygems.rb"
|
|
|
|
|
2021-05-08 21:31:13 +00:00
|
|
|
# Deshabilitar el usuario de nginx
|
|
|
|
sed -re "/user nginx/d" -i "$ENTORNO/etc/nginx/nginx.conf"
|
|
|
|
|
|
|
|
# Crear el directorio del PID
|
|
|
|
install -dm 755 "$ENTORNO/run/nginx"
|
|
|
|
# Instalar la configuración
|
|
|
|
install -m 640 "$DIR/nginx.conf" "$ENTORNO/etc/nginx/http.d/default.conf"
|
2021-04-26 16:03:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
crear_entorno
|
|
|
|
correr "${1:-sh}"
|