How to manage dotfiles across multiple environments with different users? - zsh

Scenario: I want my Zsh and Oh-My-Zsh setup to be the same across my personal Mac, my work Mac, my Linux Desktop, my raspberry pis.
Each of these have different usernames (and even different paths to their home directory /Users/MyUserName for Mac and /home/MyUserName for Linux.
I tried creating a git repo for my .zshrc and created some basic scripts that git pull all my plugins but the problems arose when i tried to install on a new raspberry pi and noticed that the path to my home directory depended on my system and .oh-my-zsh install script uses the ZSH environmental variable to install itself. This meant that i needed to create a pre-oh-my-zsh .zshrc that detected the system with uname -s and set the prefix for the ZSH variable appropriately.
Unfortunately .oh-my-zsh just overwrites this so whenever I would want to make edits to my config and push it the git repo i'll have to re-install each time. It seems like there must be a solution.
How do I make it so my zsh dotfiles are agnostic to my machine environment and my username for paths so that I can install .oh-my-zsh and make updates to my dotfiles that I can propagate to my other machines?

I would recommend keeping your config dotfiles in a single git config repo but then creating symlinks to where they ought to live on your machine. Properties of symlinks are such that they are more maintainable than copying and pasting configs around.
They allow updates to be made either in the config-repo directory or where you created the symlink.
For example, I would recommend creating a config repo with your .zshrc file and cloning it to all relevant machines. Next, I would create a symlink for your .zshrc from your config repo, ~/dev/config/.zshrc, to its default location, the home directory on all your machines.
cd ~
ln -s ~/dev/config/.zshrc .
Now if that git managed .zshrc file is ever updated on one machine the changes can be pulled on another via the config repo and the .zshrc file symlinked to the home directory is also updated. And visa versa if ~/.zshrc is updated the changes are reflected in the config repo change log and can easily be committed and pushed for other machines to pull.
This setup also works for your oh-my-zsh config. I would recommend following the standard install procedure on each machine thanks to it essentially cloning from source into at own local git directory. However, the .oh-my-zsh/custom directory is what you'll want to be in sync for your custom functions, aliases, templates, plugins, etc.
cd ~/.oh-my-zsh
rm -rf custom
ln -s ~/dev/config/oh-my-zsh/custom .
This solution enables tracking your zsh and oh-my-zsh configs in version control for maintainability and enables interoperability between machines. This can of course be extended to any type of config files/directories.
Note: all of this could of course be automated with a provisioning config tool like puppet, anasable, or chef. Furthermore, the management of the symlinks could be assisted with a solution such as Stow.

You should use a dotfiles manager, there are many different ones.
I would recommend yadm
You can see an example in my dotfiles repo:
https://github.com/khongi/dotfiles

Related

Permissions and performance issues using Windows 11 + WSL2 (Ubuntu), Docker Desktop & WordPress via docker-compose local environment

I am working on a project handed over by a previous developer which utilises docker desktop and a docker-compose.yml file to bring up a WordPress project on my Windows PC. This worked okay on my last PC (Windows 10), I've now upgraded to a new PC running on Windows 11.
The project worked fine with a non WSL version of docker, just using hyper-v and docker-compose with some mounted volumes to create the containers and code up a bespoke WordPress theme (running on roots/sage 8).
Since moving to Windows 11, the project has been almost unusable due to massively slow pagespeed (30 seconds minimum to load just about anything).
I tried to solve this by switching to WSL2. I followed tutorials from Microsoft & Docker to get WSL2 setup with Ubuntu.
I did a totally clean install of:
WSL2
Ubuntu
Docker Desktop
VS Code
My understanding is that adding the project files directly into Ubuntu is the best way to go as it should be a lot faster than trying to mount the files from Windows, so I setup SSH keys and cloned the repo into my /home/andy/ directory.
Running docker-compose up successfully fires up the website but I then get hit with loads of issues I never encountered while running the project via docker desktop without WSL2.
WordPress or the web user seems to be lacking permissions to write to the wp-content directory
-- Can't install any plugins
-- Can't upload media
VS code (launched via code . in the project directory) doesn't have permission to write to anywhere in wp-content
FileZilla is unable to create any folders within wp-content including in wp-content/uploads
I need to get this project working, I'm obviously not a docker or linux expert, I just need to get it fired up so I can continue coding with WordPress!
I've trawled through most pages of Google's search results for people having similar issues and I've done a fresh install of the WSL2/Docker setup multiple times after trying different things to get this to work but nothing is working.
I've tried:
adding to the docker-entrypoint.sh chown -R www-data:www-data /var/www/html
-- This was to try and give the www-data user ownership of everything mounted into the var/www/html directory, which appeared initially to help but broke other permissions, like Filezilla being able to write to wp-content
Ensured that all the directories/files in my project folder had the correct permissions for WordPress 755 for directories & 644 for files
-- Had no effect on the issue
Attempted to set 777 recursively on the entire project directory in Ubuntu
-- Still had issues with FileZilla & VS Code, and for some reason, when I did docker-compose up the permissions on wp-content reset themselves from 777 to 755
Added user:$USER within the wordpress part of the docker-compose.yml file, and then did USER=root docker-compose up
-- This appeared to give WordPress the permissions/access needed in order to write to wp-content as I could now download and install plugins, and upload media, but the entire backend of WordPress was very slow and I still couldn't save files with VS code, or download with FileZilla.
Attempted to take ownership of the /home/andy directory where my project files live via sudo chown -R andy /home/andy/
-- This allowed VS Code & FileZilla to both work as expected, saving files and downloading files from a remote server into Ubuntu via WSL2
With weird root user hacky solution + chown on the user directory, I appeared to have got everything "working", but wp-admin was so ridiculously slow, it was barely usable.
Another post I came across said that using .local to access the site was a bad idea since that could cause slow performance with docker, so I then changed the website url in my hosts file, and did a find and replace on the DB/Files to reflect the change, and now the backend of WordPress works fast, but appears to have permissions issues as lots of plugins are complaining about not having the correct permissions and I'm unable to download / install or even deactivate existing plugins.
I'm basically at a total loss at this point as for how to get this working. If anyone has any suggestions I'd be very grateful.
Thanks!

Where to install "guile-git" on Ubuntu 14?

I got stuck installing "git clone https://gitlab.com/guile-git/guile-git.git". In which directory is this supposed to be cloned and installed?
Dunno if you're still looking for an answer but it doesn't seem you need this installed to install guix; the read-me of the repository says that you can install it via guix. guix is an agnostic package manager that you can install on any Linux distribution alongside the default package manager and guix is the default package manager of the GuixSD operating system (https://www.gnu.org/software/guix/).
If you're on a distro which doesn't use guix, you may not want to install guix (I've yet to find reason enough to, yet); if you use a lot of GNU tools or Guile (some Guile packages are available through guix), you may want to.
Most repositories that don't have a binary for you to run follow the build process of configure, make, and [sudo ]make install.
I cloned the repository, myself, and find that this one does, as well.
Get a terminal (if you haven't been using one, yet) and cd into the directory you cloned the repository to and then cd into the guile-git directory (cd guile-git).
If we do ls -l, we'll see that the only executable file there is the bootstrap one; I've never seen one before but doing ./bootstrap generates the configure file and sets up the make process for us. So now back in familiar territory.
Given these are Guile files, we'll probably want to install this under the same prefix as where Guile is installed so run which guile. I believe, if you install it under Ubuntu (I'm running Linux Mint), it'll install to /usr/bin/ but, if you install it manually, it'll install to /usr/local/bin/.
The latter is where mine is and that's the default prefix that configure uses so I can just do ./configure; if you wanted to install it under /usr/, run /.configure --prefix=/usr/.
This'll verify that all of the necessary libraries and programs that guile-git needs are installed and properly setup. Heads up that configure balked at me over not having the Guile module bytestructures installed (https://github.com/TaylanUB/scheme-bytestructures) so you may need to do that.
I'm not going to run through everything to get it installed but, once you can run it without any errors, run make to build it within the directory.
If you want to install it permanently on your computer with the rest of your operating system able to detect it, run make install. Since you'll likely've specified a directory under /usr, you'll have to do sudo make install so that the make process can have permissions to install under /usr/local or /usr.
Sorry if I reiterated anything you already knew; 'just didn't want to assume you knew something and result in confusion.

How to correctly install dokku - with or without sudo?

I'm learning dokku right now for simple web deployment. Offical install instructions state this command:
wget -qO- https://raw.github.com/progrium/dokku/v0.3.12/bootstrap.sh | sudo DOKKU_TAG=v0.3.12 bash
I'm not a devop or admin, but as far as I understand this line, it performs all bootstrapping and installation under the root account, thanks to sudo. So dokku will be checked out into a directory with root access rights, and all additional directories like /var/lib/dokku/ will also have root access rights.
The problem is - all articles across the internet about dokku instructs to execute dokku command or do dokku-related actions without sudo. For example, instructions about this dokku database plugin, https://github.com/krisrang/dokku-mariadb, instructs to install it via:
cd /var/lib/dokku/plugins
git clone https://github.com/krisrang/dokku-mariadb mariadb
dokku plugins-install
This is not working, since /var/lib/dokku/plugins have root access rights and git clone will fail with acces denied. It's hard to be a non-admin nowadays, but maybe someone will hint what I'm doing wrong? Do I need to install dokku some other way, or all dokku-related tutorials across internet assume that I'm executing them under root (which is, by my limited admin knowledge, highly not recommended for security reasons).
You should run those three commands as sudo:
sudo su -
The dokku binary will run code as the dokku user even if you execute as root. So it should be fine to run that as is. Once you are the sudo user, just run the install instructions listed in your question. Hope my answer helps ! :)
I also contacted them as they mentioned:
In the future, we'll have a method to install plugins directly with a
dokku command
As far as I can tell, you need to run it as root. A traditional way to install a program without root-privileges is to download the source and compile it, which can be done by running:
git clone https://github.com/progrium/dokku.git
make
make install
Dokku's makefile depends on apt-get, which requires root access to run.
I'm not familiar with dokku or dokku-mariadb, but I think the author of dokku-mariadb also assumes root access.
For people running into the question on wether its fine to install through root user (on fresh created VMs as per the guide), try checking this Github issue:
https://github.com/dokku/dokku/issues/961
Since the commands related to dokku are prefixed with # rather than $, it means that its not necessary to run them from non-root user. It also makes writing suddo unnecessary (and form my experience counterproductive).

OpenShift Custom Cartridge and NPM

I am working with a community-developed OpenShift cartridge for nginx. The cartridge's build script (without any modifications) works well; it starts the nginx server with the configuration file that I provide it. However, I am trying to modify the build script so that it first changes directory into my OpenShift repository, runs npm install and then grunt build to build an Angular application that I have created.
When I do this, I continuously get the error EACCES, mkdir '/var/lib/openshift/xxxxxxxxxx/.npm' when the script gets to npm install. Some OpenShift forum posts have attempted to solve the issue, but it appears as though a different solution is required (at least in my case).
Thus, I am interested in whether or not it is possible to use npm in this way, or if I need to create a cartridge that does all of this myself.
Since we do not typically have the access required to create ~/.npm, we have to find ways of moving the npm cache (normally ~/.npm) and the npm user configuration (normally ~/.npmrc) to accessible folders to get things going. The following information comes partially from a bug report that I submitted to Redhat on this matter.
We must begin by creating an environmental variable to control the location of .npmrc. I created a file (with shell access to my application) called .env in $OPENSHIFT_DATA_DIR. Within this file, I have placed:
export NPM_CONFIG_USERCONFIG=$OPENSHIFT_HOMEDIR/app-root/build-dependencies/.npmrc
This moves the .npmrc directory to a place where we have the privileges to read/write. Naturally, I have to also create the directory .npmrc in $OPENSHIFT_HOMEDIR/app-root/build-dependencies/. Then, in my pre-start webhook/early in my build script, I have placed:
touch $OPENSHIFT_DATA_DIR/.env
This ensures that the environmental variable that configures the location of .npmrc will be accessible each time we deploy/build. Now we can move the location of the npm cache. Start by running touch on the .env file manually, and create the .npm directory in $OPENSHIFT_HOMEDIR/app-root/build-dependencies/. Run the following to complete the reconfiguration:
npm config set cache $OPENSHIFT_HOMEDIR/app-root/build-dependencies/.npm
NPM should now be accessible each time we deploy, even if we are not using the NodeJS cartridge. The above directory choices may be changed as desired.
You do not have write access to the ~/.npm directory in your gear. You might try reviewing how the native node.js cartridge is setup (https://github.com/openshift/origin-server/tree/master/cartridges/openshift-origin-cartridge-nodejs) and see if you can apply it to your custom cartridge.

Installing Nginx-auth-ldap on Debian

I tried to install Nginx-auth-ldap on my Debian server, but I can't understand how to do it right. I have been looking on https://github.com/kvspb/nginx-auth-ldap/wiki/How-to-install and tried the commands for Linux.
The thing I can't understand is
./configure --add-module=path_to_http_auth_ldap_module
make install
I don't have a folder called configure in the Nginx folder.
Please help me to understand how I will make that work.
The key is one sentence from the linked page that you skipped. The whole instructions say:
cd ~ && git clone https://github.com/kvspb/nginx-auth-ldap.git
in nginx source folder
./configure --add-module=path_to_http_auth_ldap_module
make install
"In nginx source folder" refers to a directory where you would have the source code of nginx. This means you are supposed to re-build nginx with the new module.
What you should do
Download the nginx sources 1
Download the nginx-auth-ldap module
Compile nginx with the module
However, I did not test this, so it is possible that you need additional libraries or sources like the ones for ldap...
Don't install nginx through Debian's package manager. Instead, as jasperado suggested, you'll want to download nginx from source.
You can download the mainline version thus:
wget http://nginx.org/download/nginx-1.9.2.tar.gz && tar xzf nginx-1.9.2.tar.gz
Before you build, you may want to make sure PCRE3 is installed on your system because ngx_http_rewrite_module requires it, and the installer will try to load this module.
When ready, you go into the nginx source directory and then you can do the whole configure and make thing. You might find this article helpful.
For example,
./configure --prefix=/usr/local --with-http_stub_status_module --add-module=$HOME/nginx-auth-ldap
make
sudo make install

Resources