Skip to content

Commit

Permalink
refactor: rename and move files (#2134)
Browse files Browse the repository at this point in the history
  • Loading branch information
viceice authored Feb 5, 2024
1 parent 1c6f0aa commit cb7edfd
Show file tree
Hide file tree
Showing 8 changed files with 123 additions and 113 deletions.
12 changes: 8 additions & 4 deletions src/cli/install-tool/install-legacy-tool.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,13 @@ export class InstallLegacyToolService {
env.PIP_INDEX_URL = pipIndex;
}

await execa('/usr/local/containerbase/bin/install-tool', [tool, version], {
stdio: ['inherit', 'inherit', 1],
env,
});
await execa(
'/usr/local/containerbase/bin/install-tool.sh',
[tool, version],
{
stdio: ['inherit', 'inherit', 1],
env,
},
);
}
}
2 changes: 1 addition & 1 deletion src/cli/prepare-tool/prepare-legacy-tools.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { logger } from '../utils';
export class PrepareLegacyToolsService {
async execute(tools: string[]): Promise<void> {
logger.debug(`Preparing legacy tools ${tools.join(', ')} ...`);
await execa('/usr/local/containerbase/bin/prepare-tool', tools, {
await execa('/usr/local/containerbase/bin/prepare-tool.sh', tools, {
stdio: ['inherit', 'inherit', 1],
});
}
Expand Down
110 changes: 2 additions & 108 deletions src/usr/local/bin/install-containerbase
Original file line number Diff line number Diff line change
@@ -1,110 +1,4 @@
#!/bin/bash

set -e

# USER_NAME and USER_ID need to be defined as the
# decision which paths are used are based on this information
if [[ -z "${USER_NAME}" ]]; then
export USER_NAME=ubuntu
echo "No USER_NAME defined - using: ${USER_NAME}"
fi

if [[ -z "${USER_ID}" ]]; then
export USER_ID=1000
echo "No USER_ID defined - using: ${USER_ID}"
fi

if [[ -z "${PRIMARY_GROUP_ID}" ]]; then
export PRIMARY_GROUP_ID=0
echo "No PRIMARY_GROUP_ID defined - using: ${PRIMARY_GROUP_ID}"
fi

# shellcheck source=/dev/null
. /usr/local/containerbase/util.sh

if [[ -n "${BASH_ENV}" && "${BASH_ENV}" != "${ENV_FILE}" ]]; then
echo "Wrong BASH_ENV defined - skipping: ${BASH_ENV}"
exit 1;
fi

# no duplicate installs
if [[ -n "${CONTAINERBASE_ENV+x}" ]]; then
echo "CONTAINERBASE_ENV defined - skipping: ${CONTAINERBASE_ENV}"
exit 1;
fi

require_arch
require_distro
require_root

setup_env_files

echo "APT::Install-Recommends \"false\";" | tee -a /etc/apt/apt.conf.d/containerbase.conf
echo "APT::Get::Install-Suggests \"false\";" | tee -a /etc/apt/apt.conf.d/containerbase.conf

# Set up user and home directory
createUser

# create env helper paths
mkdir /usr/local/env.d
su "${USER_NAME}" -c "mkdir -p \"/home/${USER_NAME}/\"{env.d,bin}"

if [[ "$PATH" =~ (^|:)"/home/${USER_NAME}/bin"(:|$) ]]; then
echo "export PATH=\"/home/${USER_NAME}/bin:\${PATH}\"" >> "$ENV_FILE"
fi

# OpenShift
chmod -R g+w "/home/${USER_NAME}"

export_env DEBIAN_FRONTEND "noninteractive"
export_env LC_ALL "C.UTF-8"
export_env LANG "C.UTF-8"

# upgrade base packages
apt_upgrade

# install basic required packages
apt_install \
ca-certificates \
curl \
dumb-init \
gnupg \
jq \
libarchive-tools \
openssh-client \
unzip \
xz-utils \
zstd \
;

# check for /usr/local/share/ca-certificates/*.crt

if [[ "$(find /usr/local/share/ca-certificates/ -name "*.crt" -type f -printf '.' | wc -c)" -gt 0 ]]; then
echo "Found user certs, calling update-ca-certificates"
update-ca-certificates
fi

function link_tool () {
ln -sf /usr/local/containerbase/bin/containerbase-cli /usr/local/bin/containerbase-cli
ln -sf /usr/local/containerbase/bin/containerbase-cli /usr/local/bin/install-gem
ln -sf /usr/local/containerbase/bin/containerbase-cli /usr/local/bin/install-npm
ln -sf /usr/local/containerbase/bin/containerbase-cli /usr/local/bin/install-tool
ln -sf /usr/local/containerbase/bin/containerbase-cli /usr/local/bin/prepare-tool

containerbase-cli --version
}
link_tool


# do this at the end as we are overwriting certain env vars and functions
function prepare_v2_tools () {
# setup directories for v2 tools
# shellcheck source=/dev/null
. /usr/local/containerbase/utils/v2/overrides.sh

setup_directories
}
prepare_v2_tools

# cleanup
rm -rf /var/lib/apt/lists/* /var/log/dpkg.* /var/log/apt
# simple wrapper to install containerbase
/usr/local/containerbase/bin/install-containerbase.sh "$@"
File renamed without changes.
File renamed without changes.
112 changes: 112 additions & 0 deletions src/usr/local/containerbase/bin/install-containerbase.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
#!/bin/bash

set -e

# USER_NAME and USER_ID need to be defined as the
# decision which paths are used are based on this information
if [[ -z "${USER_NAME}" ]]; then
export USER_NAME=ubuntu
echo "No USER_NAME defined - using: ${USER_NAME}"
fi

if [[ -z "${USER_ID}" ]]; then
export USER_ID=1000
echo "No USER_ID defined - using: ${USER_ID}"
fi

if [[ -z "${PRIMARY_GROUP_ID}" ]]; then
export PRIMARY_GROUP_ID=0
echo "No PRIMARY_GROUP_ID defined - using: ${PRIMARY_GROUP_ID}"
fi

# shellcheck source=/dev/null
. /usr/local/containerbase/util.sh

if [[ -n "${BASH_ENV}" && "${BASH_ENV}" != "${ENV_FILE}" ]]; then
echo "Wrong BASH_ENV defined - skipping: ${BASH_ENV}"
exit 1;
fi

# no duplicate installs
if [[ -n "${CONTAINERBASE_ENV+x}" ]]; then
echo "CONTAINERBASE_ENV defined - skipping: ${CONTAINERBASE_ENV}"
exit 1;
fi

require_arch
require_distro
require_root

setup_env_files

echo "APT::Install-Recommends \"false\";" | tee -a /etc/apt/apt.conf.d/containerbase.conf
echo "APT::Get::Install-Suggests \"false\";" | tee -a /etc/apt/apt.conf.d/containerbase.conf

# Set up user and home directory
createUser

# create env helper paths
mkdir /usr/local/env.d
su "${USER_NAME}" -c "mkdir -p \"/home/${USER_NAME}/\"{env.d,bin}"

if [[ "$PATH" =~ (^|:)"/home/${USER_NAME}/bin"(:|$) ]]; then
echo "export PATH=\"/home/${USER_NAME}/bin:\${PATH}\"" >> "$ENV_FILE"
fi

# OpenShift
chmod -R g+w "/home/${USER_NAME}"

export_env DEBIAN_FRONTEND "noninteractive"
export_env LC_ALL "C.UTF-8"
export_env LANG "C.UTF-8"

# upgrade base packages
apt_upgrade

# install basic required packages
apt_install \
ca-certificates \
curl \
dumb-init \
gnupg \
jq \
libarchive-tools \
openssh-client \
unzip \
xz-utils \
zstd \
;

# check for /usr/local/share/ca-certificates/*.crt

if [[ "$(find /usr/local/share/ca-certificates/ -name "*.crt" -type f -printf '.' | wc -c)" -gt 0 ]]; then
echo "Found user certs, calling update-ca-certificates"
update-ca-certificates
fi

function link_tools () {
ln -sf /usr/local/containerbase/bin/docker-entrypoint.sh /usr/local/bin/docker-entrypoint.sh
ln -sf /usr/local/containerbase/bin/install-apt.sh /usr/local/bin/install-apt
ln -sf /usr/local/containerbase/bin/containerbase-cli /usr/local/bin/containerbase-cli
ln -sf /usr/local/containerbase/bin/containerbase-cli /usr/local/bin/install-gem
ln -sf /usr/local/containerbase/bin/containerbase-cli /usr/local/bin/install-npm
ln -sf /usr/local/containerbase/bin/containerbase-cli /usr/local/bin/install-tool
ln -sf /usr/local/containerbase/bin/containerbase-cli /usr/local/bin/prepare-tool

containerbase-cli --version
}
link_tools


# do this at the end as we are overwriting certain env vars and functions
function prepare_v2_tools () {
# setup directories for v2 tools
# shellcheck source=/dev/null
. /usr/local/containerbase/utils/v2/overrides.sh

setup_directories
}
prepare_v2_tools

# cleanup
rm -rf /var/lib/apt/lists/* /var/log/dpkg.* /var/log/apt

0 comments on commit cb7edfd

Please sign in to comment.