This commit is contained in:
void 2021-04-26 16:03:36 +00:00
parent b90e65fd19
commit 219fbbf05f

107
haini.sh
View file

@ -8,46 +8,91 @@ 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
# 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"
ENTORNO=../hain
# Definir si vamos a usar wget o curl
type wget >/dev/null && download="wget -O -"
type curl >/dev/null && download="curl"
function correr() {
echo "> $1"
# Si no hay ninguno de los dos, salir
test -z "${download}" && exit 1
# Necesitamos bubblewrap
type bwrap >/dev/null || exit 1
# Necesitamos proot
type proot >/dev/null || exit 1
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"
}
# Necesario para algunas distribuciones
export PROOT_NO_SECCOMP=1
function crear_entorno() {
if test -d "$ENTORNO"; then
echo "El entorno ya existe en $ENTORNO"
return
fi
# El entorno de trabajo es desarrollo
export RAILS_ENV=development
# 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"
# Darle permiso de lectura a otres también
umask 022
# 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"
# Crear el directorio de trabajo
mkdir ../hain && cd ../hain
# Si no hay ninguno de los dos, salir
test -z "${download}" && exit 1
# Descargar y extraer Alpine
${download} "${ALPINE_URL}" | tar xvzf -
# Darle permiso de lectura a otres también
umask 022
# Directorio de instalación de las gemas
install -dm 755 -o ${USER} -g $(id -g ${USER}) opt/sutty
# Crear el directorio de trabajo
mkdir "$ENTORNO"
# Instalar las dependencias
proot -S . /sbin/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
# Descargar y extraer Alpine
${download} "${ALPINE_URL}" | tar xz --directory "$ENTORNO"
# Habilitar la instalación de gemas binarias
sed -re "s/#(@platforms = )/\1/" -i usr/lib/ruby/2.7.0/rubygems.rb
# Directorio de instalación de las gemas
install -dm 755 -o ${USER} -g $(id -g ${USER}) "$ENTORNO/opt/sutty"
# Instalar las gemas como root
proot -R . -w ../sutty /usr/bin/bundle install --path /opt/sutty
# 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 \
gnutls-utils nghttp2"
# 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}"