13hannes11/toolbox-tuner

Separate home folder

13hannes11 opened this issue · 5 comments

  • Allow toolbox to use separate home folder (script exists)
  • Make seperate homefolder user configurable (#6 )
  • Allow users to create symbolic links between directories of seprate home and actual home directory (moved to seperate issue #33)

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

To launch applications prepend something like

export "HOME=/var/home/USER/.toolbox/homedir/rust/";
  1. Create if not exists ~/.bashrc.d
  2. Create file (toolbx_tuner_set_home.sh) in ~/.bashrc.d that reflects application settings with home folders.
  3. create folder ~/.bashrc.d/toolbx_tuner_settings with the files per_app and global_settings
    i. per_app looks as follows:
    Name,Path 
    rust,Hello/ABC
    other,
    
    ii. global_settings looks as follows
    DEFAULT_HOME=$HOME/.toolbx/homedir
    USE_SEPERATE_HOME=false
    and can be loaded with 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

In rust use include_str!() to load the contents of the script files at compile time to then create the script files at runtime.