11#! /bin/bash
2- # sas-startup.sh — Pre-deployment setup for SAS Analytics Pro on VWB GCE.
2+ # sas-startup.sh — Runtime setup for SAS Analytics Pro on VWB GCE.
33#
44# Mounted at /opt/sas/aou/sas-startup.sh and invoked via PRE_DEPLOY_SCRIPT
5- # before SAS services start. The entrypoint writes PRE_DEPLOY_SCRIPT to
6- # /tmp/pre_deploy.sh and runs it, so we must NOT mount at that path .
5+ # before SAS services start. Only handles steps that depend on the /data
6+ # volume or runtime state; build-time setup is in the Dockerfile .
77#
88# All steps are idempotent so container restarts are fast.
99
1010set -o errexit
1111set -o nounset
1212set -o pipefail
1313
14- # ##############################################################################
15- # Package-manager compatibility
16- # Workbench startup scripts (post-startup.sh, resource-mount.sh) expect
17- # apt-get / apt. These shims delegate to yum on this RHEL-based SAS image.
18- # ##############################################################################
19- if [ ! -f /usr/local/bin/apt-get ]; then
20- cat > /usr/local/bin/apt-get << 'SHIM '
21- #!/bin/bash
22- case "$1" in
23- update) exec yum makecache -y ;;
24- install) shift; exec yum install -y "$@" ;;
25- *) exec yum "$@" ;;
26- esac
27- SHIM
28- chmod +x /usr/local/bin/apt-get
29- cp /usr/local/bin/apt-get /usr/local/bin/apt
30- chmod +x /usr/local/bin/apt
31- fi
32-
33- # ##############################################################################
34- # System packages required by Workbench startup scripts
35- # ##############################################################################
36- yum install -y jq curl fuse fuse-libs tar wget sudo git 2> /dev/null || true
37-
38- # ##############################################################################
39- # gcsfuse — GCS bucket mounting
40- # ##############################################################################
41- if ! command -v gcsfuse & > /dev/null; then
42- cat > /etc/yum.repos.d/gcsfuse.repo << 'EOF '
43- [gcsfuse]
44- name=gcsfuse (packages.cloud.google.com)
45- baseurl=https://packages.cloud.google.com/yum/repos/gcsfuse-el7-x86_64
46- enabled=1
47- gpgcheck=1
48- repo_gpgcheck=0
49- gpgkey=https://packages.cloud.google.com/yum/doc/yum-key.gpg
50- https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg
51- EOF
52- yum install -y gcsfuse || true
53- fi
54-
55- # ##############################################################################
56- # Google Cloud SDK
57- # ##############################################################################
58- if ! command -v gcloud & > /dev/null; then
59- curl -O https://dl.google.com/dl/cloudsdk/channels/rapid/downloads/google-cloud-cli-565.0.0-linux-x86_64.tar.gz \
60- && tar -xf google-cloud-cli-565.0.0-linux-x86_64.tar.gz \
61- && ./google-cloud-sdk/install.sh -q \
62- && ln -sf /google-cloud-sdk/bin/* /bin/ \
63- && rm -f google-cloud-cli-565.0.0-linux-x86_64.tar.gz \
64- || true
65- fi
66-
67- # ##############################################################################
68- # AoU user (non-root, no sudo)
69- # ##############################################################################
70- AOU_GID=${AOU_GID:- 1001}
71- groupadd -f -g " ${AOU_GID} " aougroup
72- id aou & > /dev/null || useradd -g aougroup -m -d /data -s /bin/bash aou
73- echo " aou:aou" | chpasswd
74- rm -f /etc/sudoers.d/aou
75-
7614# ##############################################################################
7715# Data directories (on the sas-data volume)
7816# ##############################################################################
@@ -98,49 +36,3 @@ if [ -d /opt/sas/aou ]; then
9836 grep -q " load-env.sh" /data/.bashrc 2> /dev/null || \
9937 echo " source /data/load-env.sh" >> /data/.bashrc
10038fi
101-
102- # ##############################################################################
103- # SAS configuration
104- # ##############################################################################
105- USERMODS_CFG=/opt/sas/viya/config/etc/workspaceserver/default/sasv9_usermods.cfg
106- grep -q " saswork" " ${USERMODS_CFG} " 2> /dev/null || \
107- echo " -work /data/saswork" >> " ${USERMODS_CFG} "
108- grep -q " utilloc" " ${USERMODS_CFG} " 2> /dev/null || \
109- echo " -utilloc /data/utilloc" >> " ${USERMODS_CFG} "
110-
111- sed -Ei ' s#^USERMODS=(.*)#USERMODS=-allowxcmd \1#g' \
112- /opt/sas/viya/config/etc/spawner/default/spawner_usermods.sh
113-
114- # ##############################################################################
115- # Apache proxy — auto-login and header cleanup
116- # ##############################################################################
117- PROXY_CONF=/etc/httpd/conf.d/dkrapro-proxy.conf
118-
119- # Comment out default RequestHeader lines from the SAS image, then re-add
120- # exactly the ones we need. Use a marker so restarts are idempotent.
121- if ! grep -q " AOU-CONFIGURED" " ${PROXY_CONF} " ; then
122- sed -i " s/RequestHeader/#RequestHeader/g" " ${PROXY_CONF} "
123-
124- # Force Apache to generate https:// URLs in redirects (RedirectMatch etc.)
125- # since the Workbench proxy terminates TLS upstream.
126- sed -i ' s|^ServerName localhost$|ServerName https://localhost|' " ${PROXY_CONF} "
127-
128- sed -i ' /ProxyPreserveHost On/a # AOU-CONFIGURED' " ${PROXY_CONF} "
129-
130- # Auto-login (base64 of "aou:aou" = YW91OmFvdQ==)
131- sed -i ' /AOU-CONFIGURED/a RequestHeader set X-SAS-Authorization "Basic YW91OmFvdQ=="' \
132- " ${PROXY_CONF} "
133- sed -i ' /AOU-CONFIGURED/a RequestHeader set X-Forwarded-Proto "https"' \
134- " ${PROXY_CONF} "
135-
136- # Strip framing restrictions so SAS Studio can be iframed by the Workbench UI.
137- sed -i ' /AOU-CONFIGURED/a Header unset X-Frame-Options' \
138- " ${PROXY_CONF} "
139- sed -i ' /AOU-CONFIGURED/a Header unset Content-Security-Policy' \
140- " ${PROXY_CONF} "
141-
142- # SameSite=None cookies require the Secure flag. The app sees HTTP
143- # (proxy terminates TLS) so SAS omits it — add it via Apache.
144- sed -i ' /AOU-CONFIGURED/a Header edit Set-Cookie "^(.*SameSite=None.*)$" "$1; Secure"' \
145- " ${PROXY_CONF} "
146- fi
0 commit comments