Skip to content

Commit a79c785

Browse files
committed
fix: revert to current for testing
1 parent c7884d0 commit a79c785

File tree

1 file changed

+67
-54
lines changed

1 file changed

+67
-54
lines changed

scripts/base/ampstart.sh

Lines changed: 67 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,68 +1,81 @@
11
#!/bin/bash
22

3-
set -Eeuo pipefail
4-
trap 'echo "[ERR] line $LINENO: $BASH_COMMAND (exit $?)"' ERR
3+
echo "[Info] AMPStart for Docker - v23.07.1"
4+
INSTALLED_DEPS_FILE="/AMP/InstalledDeps.json"
55

6-
echo "[Info] AMPStart for Docker"
7-
ARCH=$(uname -m)
6+
if [ -z "${AMPUSERID}" ]; then
7+
echo "[Info] This docker image cannot be used directly by itself - it must be started by ampinstmgr"
8+
exit 100
9+
fi
810

9-
# Context check
10-
[ -z "${AMPUSERID}" ] && { echo "[Error] This docker image cannot be used directly by itself - it must be started by ampinstmgr"; exit 100; }
11+
#Check if the AMP user already exists
12+
getent passwd amp &> /dev/null
1113

12-
# Create /etc/machine-id (addresses Proton/dbus issues)
13-
mkdir -p /var/lib/dbus
14-
rm -f /etc/machine-id /var/lib/dbus/machine-id
15-
dbus-uuidgen --ensure=/etc/machine-id
16-
ln -s /etc/machine-id /var/lib/dbus/machine-id
14+
if [ "$?" == "0" ]; then
15+
echo "[Info] AMP user already exists, continuing..."
16+
else
17+
echo "[Info] Performing first-time container setup..."
18+
groupadd -r -g $AMPGROUPID amp > /dev/null
19+
useradd -m -d /home/amp -s /bin/bash -c "AMP Process User" -u $AMPUSERID -g $AMPGROUPID amp > /dev/null
20+
touch /home/amp/.gitconfig
21+
chown -R amp:amp /home/amp 2> /dev/null
22+
usermod -aG tty amp
23+
chmod +x /AMP/AMP_Linux_x86_64
24+
echo "[Info] Container setup complete."
25+
fi
1726

18-
# Set up amp user and group
19-
: "${AMPUSERID:?[Error] AMPUSERID not set}"
20-
: "${AMPGROUPID:?[Error] AMPGROUPID not set}"
21-
echo "[Info] Setting up amp user and group..."
22-
getent group "${AMPGROUPID}" >/dev/null 2>&1 || groupadd -r -g "${AMPGROUPID}" amp
23-
id -u amp >/dev/null 2>&1 || useradd -m -d /home/amp -s /bin/bash -c "AMP Process User" -u "${AMPUSERID}" -g "${AMPGROUPID}" amp
24-
usermod -aG tty amp
25-
touch /home/amp/.gitconfig
26-
chown -R amp:amp /home/amp 2>/dev/null
27+
if [ -f "$INSTALLED_DEPS_FILE" ]; then
28+
INSTALLED_DEPS=$(jq -r '.[]' $INSTALLED_DEPS_FILE)
29+
else
30+
INSTALLED_DEPS=""
31+
echo "[]" > $INSTALLED_DEPS_FILE
32+
fi
2733

28-
# Make AMP binary executable
29-
export AMP_BIN="/AMP/AMP_Linux_${ARCH}"
30-
[ -f "${AMP_BIN}" ] && chmod +x "${AMP_BIN}"
34+
REQUIRED_DEPS=$(echo $AMP_CONTAINER_DEPS | jq -r '.[]')
3135

32-
# Install extra dependencies if needed
33-
REQUIRED_DEPS=()
34-
if [[ -n "${AMP_CONTAINER_DEPS:-}" ]]; then
35-
# shellcheck disable=SC2207
36-
REQUIRED_DEPS=($(jq -r '.[]? | select(type=="string" and length>0)' <<<"${AMP_CONTAINER_DEPS}" || echo))
37-
fi
38-
if ((${#REQUIRED_DEPS[@]})); then
39-
echo "[Info] Installing extra dependencies..."
40-
apt-get update
41-
apt-get install -o APT::Keep-Downloaded-Packages="false" -y --no-install-recommends --allow-downgrades "${REQUIRED_DEPS[@]}"
42-
apt-get clean
43-
rm -rf /var/lib/apt/lists/*
44-
fi
36+
DEPS_TO_INSTALL=()
37+
for DEP in $REQUIRED_DEPS; do
38+
if ! [[ $INSTALLED_DEPS =~ $DEP ]]; then
39+
DEPS_TO_INSTALL+=($DEP)
40+
fi
41+
done
4542

46-
# Set custom mountpoint permissions if needed
47-
if [ -n "${AMP_MOUNTPOINTS}" ]; then
48-
echo "[Info] Updating custom mountpoint permissions..."
49-
IFS=':' read -r -a dirs <<< "${AMP_MOUNTPOINTS}"
50-
for dir in "${dirs[@]}"; do
51-
[ -n "${dir}" ] || continue
52-
chown -R amp:amp "${dir}"
53-
done
43+
if [ ${#DEPS_TO_INSTALL[@]} -ne 0 ]; then
44+
echo "[Info] Installing dependencies..."
45+
apt-get update
46+
apt-get install --allow-downgrades -y ${DEPS_TO_INSTALL[@]}
47+
48+
# for DEP in ${DEPS_TO_INSTALL[@]}; do
49+
# jq --arg dep "$DEP" '. += [$dep]' $INSTALLED_DEPS_FILE > temp && mv temp $INSTALLED_DEPS_FILE
50+
# done
51+
52+
apt-get clean
53+
rm -rf /var/lib/apt/lists/*
54+
echo "[Info] Installation complete."
55+
else
56+
echo "[Info] No missing dependencies to install."
5457
fi
5558

56-
# Run custom start script if it exists
57-
if [ -f "/AMP/customstart.sh" ]; then
58-
echo "[Info] Running customstart.sh..."
59-
chmod +x /AMP/customstart.sh
60-
/AMP/customstart.sh
59+
if [ -n "$AMP_MOUNTPOINTS" ]; then
60+
echo "[Info] Updating mountpoint permissions..."
61+
IFS=':' read -r -a dirs <<< "$AMP_MOUNTPOINTS"
62+
63+
for dir in "${dirs[@]}"; do
64+
echo "[Info] - Updating $dir..."
65+
chown -R amp:amp "$dir"
66+
done
6167
fi
6268

63-
# Handoff
64-
echo "[Info] Starting AMP..."
69+
export AMPHOSTPLATFORM
70+
export AMP_CONTAINER
71+
export AMPMEMORYLIMIT
72+
export AMPSWAPLIMIT
73+
export AMPCONTAINERCPUS
74+
export AMP_CONTAINER_HOST_NETWORK
75+
#export AMP_SHARED_INSTALL
76+
#export DOTNET_GCHeapHardLimit=0x10000000
77+
6578
ARGS=$@
66-
exec su -l -s /bin/bash \
67-
-w AMPHOSTPLATFORM,AMP_CONTAINER,AMPMEMORYLIMIT,AMPSWAPLIMIT,AMPCONTAINERCPUS,AMP_CONTAINER_HOST_NETWORK,LANG,LANGUAGE,LC_ALL \
68-
amp -c "export LD_LIBRARY_PATH=/opt/cubecoders/amp:/AMP; ampinstmgr -sync-certs; cd /AMP; HOME=/home/amp ${AMP_BIN} ${ARGS}"
79+
exec su -l -w AMPHOSTPLATFORM,AMP_CONTAINER,AMPMEMORYLIMIT,AMP_CONTAINER_HOST_NETWORK,AMPSWAPLIMIT,AMPCONTAINERCPUS,LANG,LANGUAGE,LC_ALL -c "export LD_LIBRARY_PATH=/opt/cubecoders/amp:/AMP; cd /AMP; HOME=/home/amp /AMP/AMP_Linux_x86_64 ${ARGS}; exit $?" -- amp
80+
exit $?
81+

0 commit comments

Comments
 (0)