diff --git a/bin/admin/build-and-install-ttyrec.sh b/bin/admin/build-and-install-ttyrec.sh deleted file mode 100755 index 94ee7d1..0000000 --- a/bin/admin/build-and-install-ttyrec.sh +++ /dev/null @@ -1,57 +0,0 @@ -#! /usr/bin/env bash -# vim: set filetype=sh ts=4 sw=4 sts=4 et: -set -e - -basedir=$(readlink -f "$(dirname "$0")"/../..) -# shellcheck source=lib/shell/functions.inc -. "$basedir"/lib/shell/functions.inc - -TTYREC_ARCHIVE_URL='https://github.com/ovh/ovh-ttyrec/archive/master.zip' - -action_doing "Detecting OS..." -action_detail "Found $OS_FAMILY" -if [ "$OS_FAMILY" = Linux ]; then - action_detail "Found distro $LINUX_DISTRO version $DISTRO_VERSION (major $DISTRO_VERSION_MAJOR), distro like $DISTRO_LIKE" -fi -action_done - -if echo "$DISTRO_LIKE" | grep -q -w debian; then - list="make gcc unzip wget" - if [ "$LINUX_DISTRO" = debian ] && [ "$DISTRO_VERSION_MAJOR" -ge 9 ]; then - list="$list libzstd-dev" - elif [ "$LINUX_DISTRO" = ubuntu ] && [ "$DISTRO_VERSION_MAJOR" -ge 16 ]; then - list="$list libzstd-dev" - fi - apt-get update - # shellcheck disable=SC2086 - apt-get install -y $list - # shellcheck disable=SC2086 - cleanup() { - apt-get remove --purge -y $list - apt-get autoremove --purge -y - } -elif echo "$DISTRO_LIKE" | grep -q -w rhel; then - yum install -y gcc make unzip wget - cleanup() { yum remove -y gcc make unzip wget; } -elif echo "$DISTRO_LIKE" | grep -q -w suse; then - zypper install -y gcc make libzstd-devel-static unzip wget - cleanup() { zypper remove -y -u gcc make libzstd-devel-static unzip wget; } -else - echo "This script doesn't support this OS yet ($DISTRO_LIKE)" >&2 - exit 1 -fi - -cd /tmp -wget "$TTYREC_ARCHIVE_URL" -unzip master.zip -cd ovh-ttyrec-master -./configure -make -make install -cleanup - -if ttyrec -V; then - action_done "ttyrec correctly installed" -else - action_error "couldn't install ttyrec" -fi diff --git a/bin/admin/install b/bin/admin/install index 079ce82..11c2ceb 100755 --- a/bin/admin/install +++ b/bin/admin/install @@ -1274,18 +1274,18 @@ fi if [ "${opt[check-ttyrec]}" = 1 ] ; then action_doing "Checking ttyrec version" if ! command -v ttyrec >/dev/null 2>&1; then - action_error "ttyrec is not installed, the bastion will not work! Please either install ovh-ttyrec or run this script a second time with \`$0 --nothing --install-fake-ttyrec'" + action_error "ttyrec is not installed, the bastion will not work! Please either install ovh-ttyrec (/opt/bastion/bin/admin/install-ttyrec.sh) or run this script a second time with \`$0 --nothing --no-wait --install-fake-ttyrec'" else ttyrec_version=$(ttyrec -V 2>/dev/null | grep -Eo 'ttyrec v[0-9.]+' | cut -c9-) if [ -z "$ttyrec_version" ]; then - action_error "Incompatible ttyrec version installed, the bastion will not work! Please either install ovh-ttyrec or run this script again with \`$0 --nothing --install-fake-ttyrec'" + action_error "Incompatible ttyrec version installed, the bastion will not work! Please either install ovh-ttyrec (/opt/bastion/bin/admin/install-ttyrec.sh) or run this script again with \`$0 --nothing --no-wait --install-fake-ttyrec'" else action_detail "found v$ttyrec_version" action_detail "expected v$TTYREC_VERSION_NEEDED" if [ "$(printf "%s\\n%s\\n" "$ttyrec_version" "$TTYREC_VERSION_NEEDED" | sort | head -1)" = "$TTYREC_VERSION_NEEDED" ]; then action_done else - action_error "The installed ttyrec version is too old, the bastion will not work! Please update ovh-ttyrec to at least v$TTYREC_VERSION_NEEDED" + action_error "The installed ttyrec version is too old, the bastion will not work! Please update ovh-ttyrec to at least v$TTYREC_VERSION_NEEDED (/opt/bastion/bin/admin/install-ttyrec.sh can help)" fi fi fi diff --git a/bin/admin/install-ttyrec.sh b/bin/admin/install-ttyrec.sh new file mode 100755 index 0000000..21b6c14 --- /dev/null +++ b/bin/admin/install-ttyrec.sh @@ -0,0 +1,162 @@ +#! /usr/bin/env bash +# vim: set filetype=sh ts=4 sw=4 sts=4 et: +set -e + +RELEASE_API_URL='https://api.github.com/repos/ovh/ovh-ttyrec/releases' + +basedir=$(readlink -f "$(dirname "$0")"/../..) +# shellcheck source=lib/shell/functions.inc +. "$basedir"/lib/shell/functions.inc + +usage() { + cat </dev/null; then + action_done curl + _apicall() { + curl -sL -H 'Accept: application/vnd.github.v3+json' "$1" + } + _download() { + curl -sL -O "$1" + } + elif command -v wget >/dev/null; then + action_done wget + _apicall() { + wget -q -O - --header="Accept: application/vnd.github.v3+json" "$1" + } + _download() { + wget -q "$1" + } + else + action_error "Couldn't find wget nor curl" + exit 1 + fi + + action_doing "Getting latest release..." + if command -v jq >/dev/null; then + # If we have jq, we can do it properly + url=$(_apicall $RELEASE_API_URL | jq -r '.[0].assets|.[]|.browser_download_url' | grep -F "$pattern") + elif perl -MJSON -e 1 2>/dev/null; then + # If we don't, there's a good chance we have Perl with the JSON module, use it + url=$(_apicall $RELEASE_API_URL | perl -MJSON -e 'undef $/; $d=decode_json(<>); foreach(@{ $d->[0]{assets} || [] }) { $_=$_->{browser_download_url}; /\Q'"$pattern"'\E/ && print && exit }') + else + # Otherwise, go the ugly way, don't bother the user in installing jq just for this need + url=$(_apicall $RELEASE_API_URL | grep -Eo 'https://[a-z0-9./_-]+' | grep -F "$pattern" | head -n1) + fi + + action_detail "$url" +} + +prepare_temp_folder() { + tmpfolder=$(mktemp -d) + # shellcheck disable=SC2064 + trap "test -d '$tmpfolder' && rm -rf -- '$tmpfolder'" EXIT + cd "$tmpfolder" +} + +action_static() { + set_download_url "linux-static-binary.tar.gz" + prepare_temp_folder + + _download "$url" + # we have just one archive file in the current temp directory + # shellcheck disable=SC2035 + tar xzf *.tar.gz + # at this point we have just one directory, named ovh-ttyrec-w.x.y.z, just use the shell completion to get in it! + cd ovh-ttyrec-*/ + action_done + + action_doing "Installing files" + for file in ttytime ttyrec ttyplay; do + action_detail "/usr/local/bin/$file" + install -m 0755 "$file" /usr/local/bin/ + done + cd docs + for file in *.1; do + action_detail "/usr/local/man/man1/$file" + install -m 0644 "$file" /usr/local/man/man1/ + done + action_done + + cd / +} + +action_debian() { + set_download_url ".deb" + prepare_temp_folder + + _download "$url" + action_done + + action_doing "Installing package" + if dpkg -i -- *.deb; then + action_done + else + action_error + fi + + cd / +} + +action_rpm() { + set_download_url ".rpm" + prepare_temp_folder + + _download "$url" + action_done + + action_doing "Installing package" + if rpm -Uvh -- *.rpm; then + action_done + else + action_error + fi + + cd / +} + +action_auto() { + action_doing "Detecting OS..." + action_detail "Found $OS_FAMILY" + if [ "$OS_FAMILY" = Linux ]; then + action_detail "Found distro $LINUX_DISTRO version $DISTRO_VERSION (major $DISTRO_VERSION_MAJOR), distro like $DISTRO_LIKE" + fi + action_done + + case "$DISTRO_LIKE" in + *debian*) action_debian;; + *rhel*) action_rpm;; + *suse*) action_rpm;; + *) + if [ "$OS_FAMILY" = Linux ]; then + action_static + else + echo "This script doesn't support this OS yet ($DISTRO_LIKE)" >&2 + exit 1 + fi;; + esac +} + +while getopts :sdrah arg; do + case "$arg" in + s) action_static; exit 0;; + d) action_debian; exit 0;; + r) action_rpm; exit 0;; + a) action_auto; exit 0;; + h) usage; exit 0;; + ?) echo "Invalid option: -$OPTARG"; usage; exit 1;; + esac +done +usage diff --git a/docker/Dockerfile.centos7 b/docker/Dockerfile.centos7 index f8b19ee..89067ab 100644 --- a/docker/Dockerfile.centos7 +++ b/docker/Dockerfile.centos7 @@ -1,14 +1,11 @@ FROM centos:7 LABEL maintainer="stephane.lesimple+bastion@ovhcloud.com" -# cache builds efficiently: just copy the needed script to build ttyrec first -COPY bin/admin/build-and-install-ttyrec.sh /opt/bastion/bin/admin/ -COPY lib/shell /opt/bastion/lib/shell/ -RUN ["/opt/bastion/bin/admin/build-and-install-ttyrec.sh"] - -# then just some more bits to install the packages -COPY bin/admin/packages-check.sh /opt/bastion/bin/admin/ +# cache builds efficiently: just copy the scripts to install packages first +COPY bin/admin/install-ttyrec.sh bin/admin/packages-check.sh /opt/bastion/bin/admin/ +COPY lib/shell /opt/bastion/lib/shell/ RUN ["/opt/bastion/bin/admin/packages-check.sh","-i","-d","-s"] +RUN ["/opt/bastion/bin/admin/install-ttyrec.sh","-r"] # disable /dev/kmsg handling by syslog-ng and explicitely enable /dev/log RUN test -e /etc/syslog-ng/syslog-ng.conf && \ diff --git a/docker/Dockerfile.centos8 b/docker/Dockerfile.centos8 index 89cfb2d..c73ad6d 100644 --- a/docker/Dockerfile.centos8 +++ b/docker/Dockerfile.centos8 @@ -1,14 +1,11 @@ FROM centos:8 LABEL maintainer="stephane.lesimple+bastion@ovhcloud.com" -# cache builds efficiently: just copy the needed script to build ttyrec first -COPY bin/admin/build-and-install-ttyrec.sh /opt/bastion/bin/admin/ -COPY lib/shell /opt/bastion/lib/shell/ -RUN ["/opt/bastion/bin/admin/build-and-install-ttyrec.sh"] - -# then just some more bits to install the packages -COPY bin/admin/packages-check.sh /opt/bastion/bin/admin/ +# cache builds efficiently: just copy the scripts to install packages first +COPY bin/admin/install-ttyrec.sh bin/admin/packages-check.sh /opt/bastion/bin/admin/ +COPY lib/shell /opt/bastion/lib/shell/ RUN ["/opt/bastion/bin/admin/packages-check.sh","-i","-d","-s"] +RUN ["/opt/bastion/bin/admin/install-ttyrec.sh","-r"] # disable /dev/kmsg handling by syslog-ng and explicitely enable /dev/log RUN test -e /etc/syslog-ng/syslog-ng.conf && \ diff --git a/docker/Dockerfile.debian10 b/docker/Dockerfile.debian10 index 35e08d3..a40d78e 100644 --- a/docker/Dockerfile.debian10 +++ b/docker/Dockerfile.debian10 @@ -1,14 +1,11 @@ FROM debian:buster LABEL maintainer="stephane.lesimple+bastion@ovhcloud.com" -# cache builds efficiently: just copy the needed script to build ttyrec first -COPY bin/admin/build-and-install-ttyrec.sh /opt/bastion/bin/admin/ -COPY lib/shell /opt/bastion/lib/shell/ -RUN ["/opt/bastion/bin/admin/build-and-install-ttyrec.sh"] - -# then just some more bits to install the packages -COPY bin/admin/packages-check.sh /opt/bastion/bin/admin/ +# cache builds efficiently: just copy the scripts to install packages first +COPY bin/admin/install-ttyrec.sh bin/admin/packages-check.sh /opt/bastion/bin/admin/ +COPY lib/shell /opt/bastion/lib/shell/ RUN ["/opt/bastion/bin/admin/packages-check.sh","-i","-d","-s"] +RUN ["/opt/bastion/bin/admin/install-ttyrec.sh","-d"] # handle locales RUN echo "en_US.UTF-8 UTF-8" >> /etc/locale.gen && locale-gen diff --git a/docker/Dockerfile.debian8 b/docker/Dockerfile.debian8 index a683f06..30eded6 100644 --- a/docker/Dockerfile.debian8 +++ b/docker/Dockerfile.debian8 @@ -1,14 +1,11 @@ FROM debian:jessie LABEL maintainer="stephane.lesimple+bastion@ovhcloud.com" -# cache builds efficiently: just copy the needed script to build ttyrec first -COPY bin/admin/build-and-install-ttyrec.sh /opt/bastion/bin/admin/ -COPY lib/shell /opt/bastion/lib/shell/ -RUN ["/opt/bastion/bin/admin/build-and-install-ttyrec.sh"] - -# then just some more bits to install the packages -COPY bin/admin/packages-check.sh /opt/bastion/bin/admin/ +# cache builds efficiently: just copy the scripts to install packages first +COPY bin/admin/install-ttyrec.sh bin/admin/packages-check.sh /opt/bastion/bin/admin/ +COPY lib/shell /opt/bastion/lib/shell/ RUN ["/opt/bastion/bin/admin/packages-check.sh","-i","-d","-s"] +RUN ["/opt/bastion/bin/admin/install-ttyrec.sh","-d"] # handle locales RUN echo "en_US.UTF-8 UTF-8" >> /etc/locale.gen && locale-gen diff --git a/docker/Dockerfile.debian9 b/docker/Dockerfile.debian9 index 33485c6..543c54b 100644 --- a/docker/Dockerfile.debian9 +++ b/docker/Dockerfile.debian9 @@ -1,14 +1,11 @@ FROM debian:stretch LABEL maintainer="stephane.lesimple+bastion@ovhcloud.com" -# cache builds efficiently: just copy the needed script to build ttyrec first -COPY bin/admin/build-and-install-ttyrec.sh /opt/bastion/bin/admin/ -COPY lib/shell /opt/bastion/lib/shell/ -RUN ["/opt/bastion/bin/admin/build-and-install-ttyrec.sh"] - -# then just some more bits to install the packages -COPY bin/admin/packages-check.sh /opt/bastion/bin/admin/ +# cache builds efficiently: just copy the scripts to install packages first +COPY bin/admin/install-ttyrec.sh bin/admin/packages-check.sh /opt/bastion/bin/admin/ +COPY lib/shell /opt/bastion/lib/shell/ RUN ["/opt/bastion/bin/admin/packages-check.sh","-i","-d","-s"] +RUN ["/opt/bastion/bin/admin/install-ttyrec.sh","-d"] # handle locales RUN echo "en_US.UTF-8 UTF-8" >> /etc/locale.gen && locale-gen diff --git a/docker/Dockerfile.opensuse15 b/docker/Dockerfile.opensuse15 index fdebde0..33c604c 100644 --- a/docker/Dockerfile.opensuse15 +++ b/docker/Dockerfile.opensuse15 @@ -1,14 +1,11 @@ FROM opensuse/leap:15.0 LABEL maintainer="stephane.lesimple+bastion@ovhcloud.com" -# cache builds efficiently: just copy the needed script to build ttyrec first -COPY bin/admin/build-and-install-ttyrec.sh /opt/bastion/bin/admin/ -COPY lib/shell /opt/bastion/lib/shell/ -RUN ["/opt/bastion/bin/admin/build-and-install-ttyrec.sh"] - -# then just some more bits to install the packages -COPY bin/admin/packages-check.sh /opt/bastion/bin/admin/ +# cache builds efficiently: just copy the scripts to install packages first +COPY bin/admin/install-ttyrec.sh bin/admin/packages-check.sh /opt/bastion/bin/admin/ +COPY lib/shell /opt/bastion/lib/shell/ RUN ["/opt/bastion/bin/admin/packages-check.sh","-i","-d","-s"] +RUN ["/opt/bastion/bin/admin/install-ttyrec.sh","-r"] # disable /dev/kmsg handling by syslog-ng and explicitely enable /dev/log RUN test -e /etc/syslog-ng/syslog-ng.conf && \ diff --git a/docker/Dockerfile.opensuse151 b/docker/Dockerfile.opensuse151 index 892c00d..4090de7 100644 --- a/docker/Dockerfile.opensuse151 +++ b/docker/Dockerfile.opensuse151 @@ -1,14 +1,11 @@ FROM opensuse/leap:15.1 LABEL maintainer="stephane.lesimple+bastion@ovhcloud.com" -# cache builds efficiently: just copy the needed script to build ttyrec first -COPY bin/admin/build-and-install-ttyrec.sh /opt/bastion/bin/admin/ -COPY lib/shell /opt/bastion/lib/shell/ -RUN ["/opt/bastion/bin/admin/build-and-install-ttyrec.sh"] - -# then just some more bits to install the packages -COPY bin/admin/packages-check.sh /opt/bastion/bin/admin/ +# cache builds efficiently: just copy the scripts to install packages first +COPY bin/admin/install-ttyrec.sh bin/admin/packages-check.sh /opt/bastion/bin/admin/ +COPY lib/shell /opt/bastion/lib/shell/ RUN ["/opt/bastion/bin/admin/packages-check.sh","-i","-d","-s"] +RUN ["/opt/bastion/bin/admin/install-ttyrec.sh","-r"] # disable /dev/kmsg handling by syslog-ng and explicitely enable /dev/log RUN test -e /etc/syslog-ng/syslog-ng.conf && \ diff --git a/docker/Dockerfile.ubuntu1404 b/docker/Dockerfile.ubuntu1404 index 08adbfb..0b1ad0c 100644 --- a/docker/Dockerfile.ubuntu1404 +++ b/docker/Dockerfile.ubuntu1404 @@ -1,14 +1,11 @@ FROM ubuntu:14.04 LABEL maintainer="stephane.lesimple+bastion@ovhcloud.com" -# cache builds efficiently: just copy the needed script to build ttyrec first -COPY bin/admin/build-and-install-ttyrec.sh /opt/bastion/bin/admin/ -COPY lib/shell /opt/bastion/lib/shell/ -RUN ["/opt/bastion/bin/admin/build-and-install-ttyrec.sh"] - -# then just some more bits to install the packages -COPY bin/admin/packages-check.sh /opt/bastion/bin/admin/ +# cache builds efficiently: just copy the scripts to install packages first +COPY bin/admin/install-ttyrec.sh bin/admin/packages-check.sh /opt/bastion/bin/admin/ +COPY lib/shell /opt/bastion/lib/shell/ RUN ["/opt/bastion/bin/admin/packages-check.sh","-i","-d","-s"] +RUN ["/opt/bastion/bin/admin/install-ttyrec.sh","-d"] # handle locales RUN echo "en_US.UTF-8 UTF-8" >> /etc/locale.gen && locale-gen diff --git a/docker/Dockerfile.ubuntu1604 b/docker/Dockerfile.ubuntu1604 index 12d1c45..cc6e043 100644 --- a/docker/Dockerfile.ubuntu1604 +++ b/docker/Dockerfile.ubuntu1604 @@ -1,14 +1,11 @@ FROM ubuntu:16.04 LABEL maintainer="stephane.lesimple+bastion@ovhcloud.com" -# cache builds efficiently: just copy the needed script to build ttyrec first -COPY bin/admin/build-and-install-ttyrec.sh /opt/bastion/bin/admin/ -COPY lib/shell /opt/bastion/lib/shell/ -RUN ["/opt/bastion/bin/admin/build-and-install-ttyrec.sh"] - -# then just some more bits to install the packages -COPY bin/admin/packages-check.sh /opt/bastion/bin/admin/ +# cache builds efficiently: just copy the scripts to install packages first +COPY bin/admin/install-ttyrec.sh bin/admin/packages-check.sh /opt/bastion/bin/admin/ +COPY lib/shell /opt/bastion/lib/shell/ RUN ["/opt/bastion/bin/admin/packages-check.sh","-i","-d","-s"] +RUN ["/opt/bastion/bin/admin/install-ttyrec.sh","-d"] # handle locales RUN echo "en_US.UTF-8 UTF-8" >> /etc/locale.gen && locale-gen diff --git a/docker/Dockerfile.ubuntu1804 b/docker/Dockerfile.ubuntu1804 index f8f0507..b136791 100644 --- a/docker/Dockerfile.ubuntu1804 +++ b/docker/Dockerfile.ubuntu1804 @@ -1,14 +1,11 @@ FROM ubuntu:18.04 LABEL maintainer="stephane.lesimple+bastion@ovhcloud.com" -# cache builds efficiently: just copy the needed script to build ttyrec first -COPY bin/admin/build-and-install-ttyrec.sh /opt/bastion/bin/admin/ -COPY lib/shell /opt/bastion/lib/shell/ -RUN ["/opt/bastion/bin/admin/build-and-install-ttyrec.sh"] - -# then just some more bits to install the packages -COPY bin/admin/packages-check.sh /opt/bastion/bin/admin/ +# cache builds efficiently: just copy the scripts to install packages first +COPY bin/admin/install-ttyrec.sh bin/admin/packages-check.sh /opt/bastion/bin/admin/ +COPY lib/shell /opt/bastion/lib/shell/ RUN ["/opt/bastion/bin/admin/packages-check.sh","-i","-d","-s"] +RUN ["/opt/bastion/bin/admin/install-ttyrec.sh","-d"] # handle locales RUN echo "en_US.UTF-8 UTF-8" >> /etc/locale.gen && locale-gen diff --git a/docker/Dockerfile.ubuntu2004 b/docker/Dockerfile.ubuntu2004 index b168c3a..b0313b5 100644 --- a/docker/Dockerfile.ubuntu2004 +++ b/docker/Dockerfile.ubuntu2004 @@ -1,14 +1,11 @@ FROM ubuntu:20.04 LABEL maintainer="stephane.lesimple+bastion@ovhcloud.com" -# cache builds efficiently: just copy the needed script to build ttyrec first -COPY bin/admin/build-and-install-ttyrec.sh /opt/bastion/bin/admin/ -COPY lib/shell /opt/bastion/lib/shell/ -RUN ["/opt/bastion/bin/admin/build-and-install-ttyrec.sh"] - -# then just some more bits to install the packages -COPY bin/admin/packages-check.sh /opt/bastion/bin/admin/ +# cache builds efficiently: just copy the scripts to install packages first +COPY bin/admin/install-ttyrec.sh bin/admin/packages-check.sh /opt/bastion/bin/admin/ +COPY lib/shell /opt/bastion/lib/shell/ RUN ["/opt/bastion/bin/admin/packages-check.sh","-i","-d","-s"] +RUN ["/opt/bastion/bin/admin/install-ttyrec.sh","-d"] # handle locales RUN echo "en_US.UTF-8 UTF-8" >> /etc/locale.gen && locale-gen