|
572 | 572 | # ** Enable shell history ** |
573 | 573 | # ********************************* |
574 | 574 |
|
575 | | -if [ "${ALLOW_SHELL_HISTORY}" = "true" ]; then |
576 | | - echo "Activating feature 'shell-history'" |
577 | | - echo "User: ${USERNAME} User home: ${user_home}" |
| 575 | +echo export ALLOW_SHELL_HISTORY="${ALLOW_SHELL_HISTORY}" > /tmp/env.sh |
| 576 | +echo export user_home="${user_home}" >> /tmp/env.sh |
| 577 | +echo export USERNAME="${USERNAME}" >> /tmp/env.sh |
578 | 578 |
|
579 | | - if ! command -v uuidgen &> /dev/null; then |
580 | | - sudo apt-get update |
581 | | - sudo apt-get install -y uuid-runtime |
582 | | - fi |
583 | | - # Create the shell history directory in the mounted volume |
584 | | - DEVCONTAINER_ID=$(uuidgen) |
585 | | - HISTORY_DIR="/devcontainers/${DEVCONTAINER_ID}/shellHistory" |
586 | | - USER_HISTORY_FILE="${user_home}/.bash_history" |
587 | | - VOLUME_HISTORY_FILE="${HISTORY_DIR}/.bash_history" |
588 | | - |
589 | | - # Create the history directory in the volume, if it doesn’t already exist |
590 | | - sudo mkdir -p "${HISTORY_DIR}" |
591 | | - sudo chown -R "${USERNAME}" "${HISTORY_DIR}" |
592 | | - sudo chmod -R u+rwx "${HISTORY_DIR}" |
593 | | - |
594 | | - # Ensure the volume's history file exists and set permissions |
595 | | - if [[ ! -f "${VOLUME_HISTORY_FILE}" ]]; then |
596 | | - # Create an empty history file if it doesn’t already exist |
597 | | - sudo touch "${VOLUME_HISTORY_FILE}" |
598 | | - sudo chown -R "${USERNAME}" "${VOLUME_HISTORY_FILE}" |
599 | | - sudo chmod -R u+rwx "${VOLUME_HISTORY_FILE}" |
600 | | - fi |
601 | | - |
602 | | - # Create or update the user’s .bash_history to append to the volume’s history |
603 | | - if [[ ! -f "${USER_HISTORY_FILE}" ]]; then |
604 | | - sudo touch "${USER_HISTORY_FILE}" |
605 | | - sudo chown -R "${USERNAME}" "${USER_HISTORY_FILE}" |
606 | | - sudo chmod -R u+rwx "${USER_HISTORY_FILE}" |
607 | | - fi |
608 | | - |
609 | | - # Symlink for Bash history |
610 | | - sudo ln -sf ${USER_HISTORY_FILE} ${VOLUME_HISTORY_FILE} |
611 | | - |
612 | | - # Configure immediate history saving to the volume |
613 | | - echo 'PROMPT_COMMAND="history -a; history -c; history -r"' >> "${user_home}/.bashrc" |
614 | | - |
615 | | - echo "Shell history setup for persistent appending is complete." |
616 | | -fi |
| 579 | +sudo chmod +x /tmp/env.sh |
617 | 580 |
|
618 | 581 | # ********************************* |
619 | 582 | # ** Ensure config directory ** |
|
0 commit comments