Mylinux

An overview of the tool

6 min 1149 words

mylinux eases the interaction with larger programs according to my vision. The idea is to create a bash script, starting with my, following by the name of a famous tool (ssh, git, flatpak), which gives (myssh, mygit, myflatpak). Each script will include the most used arguments/options.

To give you an overview, I give some examples below. But first, lets introduce the concept of what I call GID (Group ID), which correponds to a dedicated namespace, it might represents a company, or a specific project. It's up to you, the idea is that each namespace is separated.

Imagine we have the two following GIDs: personal, and family. In the case of ssh, with myssh command, the configuration (ip/port, etc.) and private keys will be fetched from a path dedicated for this namespaces. Thus, you can imagine to have a computer with personal data, and another one with family accesses, or both (it depends to your need of isolation), and continue to use the same daily commands that you used. Its a kind of a more advanced alias that practitionner usually put in bashrc.

SSH

myssh will manage and use a ssh config file per GID.

# create an access, the public key will be returned, so you can add it into the corresponding server
lparment@po-lbl:~$ myssg --generate personal server-nextcloud xx.xx.xx.xx debian 22 
#ssh-rsa AAAAB3NzaC1yc2E...

# print information for a gid/server
lparment@po-lbl:~$ myssh --print-infos personal server-nextcloud 
Host server-nextcloud
        User debian
        Port 22
        HostName xx.xx.xx.xx
        IdentityFile /media/key/ssh/personal/server-nextcloud.key


# connect to a server
lparment@po-lbl:~$ myssh personal server-nextcloud
debian@...:~#  

# connect on sftp
lparment@po-lbl:~$ myssh --sftp personal server-nextcloud
Connected to server-nextcloud.
sftp> 

Git

There are so many commands and options with git, I know that git aliases solve more or less what mygit is doing, but I did know about it when I've built this command.

# generate a gid key for a gid
lparment@po-lbl:~$ mygit -g personal 

# load a private key related to a gid
lparment@po-lbl:~$ mygit -a personal 

# load a repository (it will check if repo exists in gitolite, if not it will check gitlab)
lparment@po-lbl:~/personal/$ mygit -l about 

# show current branch
lparment@po-lbl:~/personal/about$ mygit --current-branch
master

# show pretty print commits
lparment@po-lbl:~/personal/about$ mygit --pretty-print-commits 
* N 194a6ad - (HEAD -> master, origin/master) light change (20 hours ago) <Laurent Parmentier>
* N 79feb29 - light change (4 days ago) <Laurent Parmentier>

# I forgot to add some files into an old commit ? (inspired from https://stackoverflow.com/a/2719636)
lparment@po-lbl:~/personal/about$ mygit --edit-old-commit --step1 <commit_to_edit> 
# now I edit the file I need and add them into the INDEX, once done I do
lparment@po-lbl:~/personal/about$ mygit --edit-old-commit --step2
# now I just need to do a push force

Password manager

The mypass command relies on pass linux, which relies on bash, gpg and git. Here it will manage a git repo and a gpg key per GID.

# generate a password for the personal gid
lparment@po-lbl:~$ mypass personal pass generate //website/nextcloud.parmentier.io 20 -c 

# then you can save remotely within its dedicated git repo
lparment@po-lbl:~$ mypass personal pass git push origin master 

# there is also a specific gid (vaultwarden) which use vaultwarden cli
lparment@po-lbl:~$ mypass vaultwarden gitlab
...
? Master password: [hidden]
"Gitlab (Parmentier)" (url: "gitlab.parmentier.io", username: "xxx")

Containerized GUI

I'm using flatpak which is to my POV the best solution (for now) to containerized a GUI app, but it still has some limitations: see flatkill and flatpak is not the future arguments. To deal with that point, myflatpak will by default remove some accesses (host files, home files, webcam devices etc.). And within the script, I custom the accesses that I estimate for each application. It is not perfect, but its a first step.

lparment@po-lbl:~$ myflatpak -h
Command /home/lparment/bin/myflatpak package|option [package_arguments|flatpak_run_options]...

Package arguments:
 -n|--network (gives home access)
 -d|--directory directory (gives access to a directory)
 -i|--ipc (gives access ipc)
    --home (gives home access)
    --stable-commit (run specific commit if exists)

Options:
 -a|--access-directory directory package
 -i|--install package
 -u|--uninstall package [--delete-data]
 -l|--list [--simple-format|--installed-only]
 -k|--kill package
 -f|--flatseal
 -e|--enter package|pid
 -s|--shell package [package arguments]... (start a new pid)
 -r|--run package [-n|--network] cmd [args...]
 -p|--print-id package
    --install-from-hub remote_hub app_id
    --kill-all
    --info package
    --list-accesses package
    --list-extras
    --list-pids [package]
    --list-old-versions package [remote_hub]
    --checkout package commit|version
    --install-extra package extra


# start vikunja app (see https://gitlab.parmentier.io/lparmentier/flatpak-vikunja)
lparment@po-lbl:~$ myflatpak vikunja 
|Unshare ipc and network
|Disable some filesystem by default (home, host)
|Disable all device
|Disable access to ssh-auth
|Allow network for vikunja

Debian

I want to install some useful packages I need and configure them as well.

# "app" that can be configured (add configuration files, install dependencies if needed)
mydebsetup --list-app 
- htop
- tmux
- xterm
- konsole
- screen
- flatpack
- streamdeck
- parmentier.crt
- kubernetes-client
- login.defs
- vi

# lets configure one
lparment@po-lbl:~$ mydebsetup --configure tmux
|tmux configuration file added
|tmux's configuration dependency xclip installed

GPG

# generate a key
lparment@po-lbl:~$ mygpg -g personal me@gmail.com Laurent Parmentier

# using it to cipher
lparment@po-lbl:~$ mygpg --encrypt file.txt personal

Terminal

# open a term (e.g. xterm or konsole), with a window manager (e.g. tmux or screen), with a my custom layout
myterm konsole tmux-myflatpak-dev sandbox & 

# here tmux-myflatpak-dev will start neovim on the top pane, and a terminal on bottom pane. Then, with myflatpak commands, I can still go within the container to interact with the internal environments.

Myid

I can know what is currently running/loaded or not:

lparment@po-lbl:~$ myid -l
SSH: 
        - [] personal
        - [] family 
GIT: 
        - [] personal
        - [] family
GPG: 
        - [] personal

Misc

Copy a random passphrase in clipboard

lparment@po-lbl:~$ myrandom 20 | mytool --copy-to-clipboard

About to shutdown the computer, did I commit all my projects ?

lparment@po-lbl:~$ mycheck --forgotten-commits
|Files missing in commits for the directory /home/lparment/projects/personal/about/.git

Having azerty/qwerty keyboard and need a switch ?

lparment@po-lbl:~$ mytool --set-keyboard-layout fr

Conclusion

This was just an overview with the command I use the most. Since it was for a personal usage (no review, and the code evolve along more than 10 years since I wrote the first command), I have to refacto a lot of code before pusblishing it (unit tests, rename variable, ensure there is no sensible info, integration tests with different debian os releases, etc.).