Merge pull request #32 from ovh/ttyrec

enh: install-ttyrec.sh replaces build-and-install-ttyrec.sh
This commit is contained in:
Stéphane Lesimple 2020-11-05 13:33:47 +01:00 committed by GitHub
commit ae19dafe95
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
14 changed files with 209 additions and 137 deletions

View file

@ -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

View file

@ -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

162
bin/admin/install-ttyrec.sh Executable file
View file

@ -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 <<EOF
Options:
-s Download and install precompiled ttyrec static binaries in /usr/local/bin
-d Download the prebuilt Debian package, and install it (for Debian, Ubuntu and derivatives)
-r Download the prebuild RPM package, and install it (for RHEL, CentOS and derivatives)
-a Automatically detect the OS to install the proper package type, fallback to static binaries if no package applies
-h Show this help
EOF
}
set_download_url() {
pattern="$1"
action_doing "Checking for prerequisites..."
if command -v curl >/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

View file

@ -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 && \

View file

@ -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 && \

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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 && \

View file

@ -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 && \

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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