Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Separate home folder #10

Closed
2 of 3 tasks
13hannes11 opened this issue Apr 3, 2022 · 5 comments
Closed
2 of 3 tasks

Separate home folder #10

13hannes11 opened this issue Apr 3, 2022 · 5 comments
Labels
enhancement New feature or request

Comments

@13hannes11
Copy link
Owner

13hannes11 commented Apr 3, 2022

@13hannes11 13hannes11 added this to the 0.1.0 MVP milestone Apr 3, 2022
@13hannes11
Copy link
Owner Author

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
Copy link
Owner Author

To launch applications prepend something like

export "HOME=/var/home/USER/.toolbox/homedir/rust/";

@13hannes11 13hannes11 added the enhancement New feature or request label Jul 30, 2022
@13hannes11
Copy link
Owner Author

13hannes11 commented Jul 30, 2022

  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

@13hannes11
Copy link
Owner Author

13hannes11 commented Aug 6, 2022

@13hannes11
Copy link
Owner Author

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

@13hannes11 13hannes11 mentioned this issue Aug 14, 2022
3 tasks
@13hannes11 13hannes11 modified the milestones: 0.1.0 MVP, 0.3.0 All Power to Power Users Jul 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant