#!/bin/sh
# %CopyrightBegin%
#
# SPDX-License-Identifier: Apache-2.0
#
# Copyright Ericsson AB 2017-2025. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# %CopyrightEnd%

UBUNTU_VER=${1:-16.04}

USER=sshtester
PWD=foobar

docker build \
    -t ssh_compat_suite-ubuntu \
    --build-arg https_proxy=$HTTPS_PROXY \
    --build-arg http_proxy=$HTTP_PROXY \
    - <<EOF

    FROM ubuntu:$UBUNTU_VER
    WORKDIR /buildroot

    # Prepare for installing OpenSSH
    RUN apt-get update
    RUN apt-get upgrade -y
    RUN apt-get -y install apt-utils
    RUN apt-get -y install build-essential zlib1g-dev
    RUN apt-get -y install sudo iputils-ping tcptraceroute net-tools
    RUN apt-get -y install sshpass expect
    RUN apt-get -y install libpam0g-dev

    # A user for the tests
    RUN (echo $PWD; echo $PWD; echo; echo; echo; echo; echo; echo ) | adduser $USER
    RUN adduser $USER sudo

    # Prepare the privsep preauth environment for openssh
    RUN  mkdir -p /var/empty
    RUN  chown root:sys /var/empty
    RUN  chmod 755 /var/empty
    RUN  groupadd -f sshd
    RUN  ls /bin/false
    RUN  id -u sshd 2> /dev/null || useradd -g sshd -c 'sshd privsep' -d /var/empty -s /bin/false sshd

EOF
