2021-04-24 14:48:13 +00:00
|
|
|
#!/bin/sh
|
|
|
|
# Fallar ante cualquier error
|
|
|
|
set -e
|
|
|
|
|
|
|
|
# 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-04-26 16:03:36 +00:00
|
|
|
ENTORNO=../hain
|
2021-04-24 14:48:13 +00:00
|
|
|
|
2021-04-26 16:03:36 +00:00
|
|
|
function correr() {
|
|
|
|
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-04-26 16:03:36 +00:00
|
|
|
env -i \
|
|
|
|
USER="$USER" \
|
|
|
|
HOME="$HOME" \
|
|
|
|
RAILS_ENV=development \
|
|
|
|
bwrap \
|
|
|
|
--unshare-user-try \
|
|
|
|
--unshare-ipc \
|
|
|
|
--unshare-pid \
|
|
|
|
--unshare-uts \
|
|
|
|
--unshare-cgroup-try \
|
|
|
|
--bind "$ENTORNO" / \
|
|
|
|
--bind .. /Sutty \
|
|
|
|
--ro-bind /etc/host.conf /etc/host.conf \
|
|
|
|
--ro-bind /etc/hosts /etc/hosts \
|
|
|
|
--ro-bind /etc/networks /etc/networks \
|
|
|
|
--ro-bind /etc/passwd /etc/passwd \
|
|
|
|
--ro-bind /etc/group /etc/group \
|
|
|
|
--ro-bind /etc/nsswitch.conf /etc/nsswitch.conf \
|
|
|
|
--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 \
|
|
|
|
/bin/sh -l -c "$1"
|
|
|
|
}
|
2021-04-24 14:48:13 +00:00
|
|
|
|
2021-04-26 16:03:36 +00:00
|
|
|
function crear_entorno() {
|
|
|
|
if test -d "$ENTORNO"; then
|
|
|
|
echo "El entorno ya existe en $ENTORNO"
|
|
|
|
return
|
|
|
|
fi
|
2021-04-24 14:48:13 +00:00
|
|
|
|
2021-04-26 16:03:36 +00:00
|
|
|
# La versión de Alpine es el segundo argumento
|
|
|
|
ALPINE="${2:-3.13.5}"
|
|
|
|
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
|
|
|
|
mkdir "$ENTORNO"
|
2021-04-24 14:48:13 +00:00
|
|
|
|
2021-04-26 16:03:36 +00:00
|
|
|
# Descargar y extraer Alpine
|
|
|
|
${download} "${ALPINE_URL}" | tar xz --directory "$ENTORNO"
|
2021-04-24 14:48:13 +00:00
|
|
|
|
2021-04-26 16:03:36 +00:00
|
|
|
# Directorio de instalación de las gemas
|
|
|
|
install -dm 755 -o ${USER} -g $(id -g ${USER}) "$ENTORNO/opt/sutty"
|
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-04-27 18:25:13 +00:00
|
|
|
gnutls-utils nghttp2 \
|
|
|
|
less"
|
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"
|
|
|
|
|
|
|
|
echo "Instalando gemas..."
|
|
|
|
correr "cd /Sutty/sutty && \
|
|
|
|
bundle config set path /opt/sutty && \
|
|
|
|
bundle install"
|
|
|
|
|
|
|
|
echo "Instalando node_modules..."
|
|
|
|
correr "cd /Sutty/sutty && yarn install"
|
|
|
|
}
|
|
|
|
|
|
|
|
crear_entorno
|
|
|
|
correr "${1:-sh}"
|