Separate home folder
13hannes11 opened this issue · 5 comments
13hannes11 commented
13hannes11 commented
For separate home folders: containers/toolbox#348
# Check if we're running inside a toolbox
TOOLBOX_NAME=""
if [ -f "/run/.containerenv" ]; then
TOOLBOX_NAME=$(sed -nr 's/^name="(.*)"$/\1/p' /run/.containerenv)
HOME="$HOME/.toolbox/homedir/$TOOLBOX_NAME/$USER"
mkdir -p "$HOME"
bash
exit 0
fi
13hannes11 commented
To launch applications prepend something like
export "HOME=/var/home/USER/.toolbox/homedir/rust/";
13hannes11 commented
- Create if not exists
~/.bashrc.d
- Create file (
toolbx_tuner_set_home.sh
) in~/.bashrc.d
that reflects application settings with home folders. - create folder
~/.bashrc.d/toolbx_tuner_settings
with the filesper_app
andglobal_settings
i.per_app
looks as follows:ii.Name,Path rust,Hello/ABC other,
global_settings
looks as followsand can be loaded withDEFAULT_HOME=$HOME/.toolbx/homedir USE_SEPERATE_HOME=false
source ~/.bashrc.d/toolbx_tuner_settings/global_settings
Unfinished Script for toolbx_tuner_set_home.sh
:
settings_folder=$HOME/.bashrc.d/toolbx_tuner_settings
per_app_settings_file=per_app
global_settings_file=global_settings
if [ -f "/run/.containerenv" ]; then
TOOLBOX_NAME=$(sed -nr 's/^name="(.*)"$/\1/p' /run/.containerenv)
not_found=true
# read individual settings
while IFS="," read tbx home_dir rest; do
if [ "$tbx" == $TOOLBOX_NAME ]; then # if tbx has individual settings stored
# Apply custom home dir if set
if [ "$home_dir" != "" ]; then
HOME="$home_dir"
mkdir -p "$HOME"
fi
not_found=false # set not_found to false to prevent use of global settings
break
fi
done < <(tail -n +2 $settings_folder/$per_app_settings_file) # read file from line 2 because of table headers
# apply global settings if no individual overrides
if $not_found; then # use global settings if not found
source $settings_folder/$global_settings_file # load global settings
if $USE_SEPERATE_HOME ; then
HOME="$DEFAULT_HOME/$TOOLBOX_NAME"
mkdir -p "$HOME"
fi
fi
# make sure we are not running recursively before entering new bash shell in toolbox
if [ -n "$RECURSIVE_PROTECTION" ]; then
RECURSIVE_PROTECTION=true # set recursive protection to prevent infinite loops
bash
exit 0
fi
fi
13hannes11 commented
Possible way to store settings:
source <file>
can be used to load global setting variables.
https://serverfault.com/questions/219306/control-a-bash-script-with-variables-from-an-external-file
13hannes11 commented
In rust use include_str!() to load the contents of the script files at compile time to then create the script files at runtime.