Anyone knows, yes, this is known all over the world. But let me say, shell script is such a powerful.
I have tried some ways of initial setup my linux environment like dotfiles repository
, nix
, chef
.
All of them are not so bad, but not perfect to me.
For example,
-
dotfiles repository
is separated from system package installation.- I know that all I need is just preparing single install script.
-
nix
is easy but complex and too large to me, sometimes building package time is so long. -
chef
is overspec for single host machine.
My requirements for setup are below.
- 100% for me
- I don't need a general system.
- Basically oneshot
- But I can setup as many times.
- Simple
- All I needed is just 2 layers of install packages and user configuration for packages.
- On Linux
- Use shell script, yeah.
- Always latest
- Arch like rolling release provides me this spec.
So, now I have had a non-difficut (for me) shell script of bash.
Detail
I need 2 layers of install
and configuration
.
Install
I defined install
as 2 type of standard install
and custom install
.
Standard install
Standard install
is just package manager of OS built-in.
In Arch, via pacman
. In Debian, via apt
.
Custom install
On the other hand custom install
is user-defined installation like using git
, curl
or make
.
Configuration
I defined configuration
is just configuration. No trick.
For example create a .bashrc
symlink to ${HOME}
, create a neovim
config directory symlink to ${XDG_CONFIG_HOME}/nvim
.
Picture
Constructure
So simple.
I put shell scripts for install and configuration and packages directory to detect my own necessary.
setup.sh
install_batch.sh
install_single.sh
configure_batch.sh
configure_single.sh
install_custom_batch.sh
install_custom_single.sh
configure_custom_batch.sh
configure_custom_single.sh
packages/
packages
directories has subdirectory for each pacakges.
packages/
bash/
.bashrc
.bash_profile
configure.sh
install.sh
tmux/
tmux.conf
install.sh
configure.sh
...
And each implementations are like this. Basicly, I don't create functions intentinally for maintenance.
I decided that each shellscript files should be seemed as isolated module or namespace.
# setup.sh
sh "./install_batch.sh"
sh "./configure_batch.sh"
sh "./install_custom_batch.sh"
sh "./configure_batch.sh"
# install_batch.sh
pushd packages
for package in *
do
sh "${package}/install.sh"
done
popd
# <pacakge name>/install.sh
sh "$(sh install_command.sh) ${1}"
About configure
is as same as install
.
This design allows me do install or configuration isolated for single package like sh ./install_single.sh podman
. 100% for me.
Conclusion
Shell script is powerful to make modular system.
Though I don't write any tests, maybe I can write test easily.