diff --git a/README.md b/README.md index 9dd4057b1760c86a79b8c84845028d17b37bc326..9e63ac4a53b593b81270e5934fe453de8d58cbc2 100644 --- a/README.md +++ b/README.md @@ -19,3 +19,7 @@ This project is to demonstrate a possibility to manage customization in a centra ## dependency coreutils bash grep sudo + +## TODO + +init order? what is one init depends on another? diff --git a/examples/archlinux-gnome/conf.d/basic.sh b/examples/archlinux-gnome/conf.d/01_basic.sh similarity index 100% rename from examples/archlinux-gnome/conf.d/basic.sh rename to examples/archlinux-gnome/conf.d/01_basic.sh diff --git a/examples/archlinux-gnome/conf.d/desktop.sh b/examples/archlinux-gnome/conf.d/10_desktop.sh similarity index 98% rename from examples/archlinux-gnome/conf.d/desktop.sh rename to examples/archlinux-gnome/conf.d/10_desktop.sh index ce27940ee50374ff1d753ac44a428ac702bb6830..f589be1448bfaeef9095bbf4a7bf64dab501146e 100644 --- a/examples/archlinux-gnome/conf.d/desktop.sh +++ b/examples/archlinux-gnome/conf.d/10_desktop.sh @@ -1,5 +1,6 @@ lc_assert_user_is_not root +# okay to stay inside lc_init() or outside lc_fsmap files/config.fish $HOME/.config/fish/config.fish lc_fsmap files/ssh_config $HOME/.ssh/config lc_fsmap files/vimrc $HOME/.vimrc diff --git a/examples/archlinux-gnome/masterconf.sh b/examples/archlinux-gnome/masterconf.sh index 6486203a316dea4fcdfc1bdac56e385f60bd8122..bf236a9c315858b260fb3b877b19d3ad33cfdaf4 100644 --- a/examples/archlinux-gnome/masterconf.sh +++ b/examples/archlinux-gnome/masterconf.sh @@ -1,4 +1,4 @@ # setup this linuxconf on fresh-installed archlinux +# ordered by filename. Explicit order your files if u don't like. lc_include conf.d/* - diff --git a/examples/template/files/test.conf b/examples/template/files/test.conf new file mode 100644 index 0000000000000000000000000000000000000000..be656774a37437ce42fe5c600c25501efa85ebc1 --- /dev/null +++ b/examples/template/files/test.conf @@ -0,0 +1 @@ +example=conf diff --git a/examples/template/files/vimrc b/examples/template/files/vimrc new file mode 100644 index 0000000000000000000000000000000000000000..4c731391cef41e3325c8846c20fe33ef9c6a24e6 --- /dev/null +++ b/examples/template/files/vimrc @@ -0,0 +1 @@ +example vimrc diff --git a/examples/template/masterconf.sh b/examples/template/masterconf.sh index fe2203897c1e12af12bc6e95bd5588f7c06b38ca..c7bf86b4712c9179caa57b29fbd83096dbd1ad72 100644 --- a/examples/template/masterconf.sh +++ b/examples/template/masterconf.sh @@ -12,6 +12,7 @@ # > conf.d/basic.sh should install pkgs, (possibly) create new user, (possibly) run `linuxconf register .` again with new user. # +# order by filename lc_include conf.d/* # If you have multiple user.. You might need this in your config file. @@ -19,7 +20,7 @@ lc_assert_user_is root lc_assert_user_is_not root # I strongly suggest u design lc_init() as an idempotent operation. Just in case u accidentally run `linuxconf register` elsewhere. -function lc_init () { +lc_init () { # as root / as user? # Some helpful functions.. To stop running current script: @@ -30,33 +31,24 @@ function lc_init () { gsettings set var=123 } -function lc_startup () { +lc_startup () { # as root / as user? # You want desktop env? Use lc_login() # want some daemon in background? lcf_bgrun /tmp/server.log my_server --arg1 123 --arg2 "hello world !" - lcf_bgrun /tmp/server.log auto_restart important_service --gg "example" + # Guaranteed! linuxconf dir is your current workdir. + lcf_bgrun /dev/null auto_restart important_service --config files/test.conf } -function lc_login () { +lc_login () { # Your desktop environment must implement "XDG autostart". Ref: https://wiki.archlinux.org/title/XDG_Autostart # Otherwise... Use lc_init to your task into wherever u'd like. # # Warning: Could be called multiple times if user logout/login again. - lc_login_is_x11? } -function lc_cron () { - # hourly / daily / weekly / monthly? - # as root / as user? - -} - -# Warning: watch out for unintended user -lc_fsmap files/vimrc $LC_USER_HOME/.vimrc - -# TODO: what if lc_fsmap depends on lc_init() ?? This is not recommended usage. -# e.g: 'git clone xxx $HOME/sh' and lc_fsmap $HOME/sh/something /usr/bin/fancy -# lc_fsmap should success even if $HOME/sh/something doesn't exist yet. (what if dest also not exist? let it fail...) +# watch out! does your user have access to target directory? +# okay to stay inside lc_init() or outside, okay if files/vimrc doesn't exist yet. +lc_fsmap files/vimrc $HOME/.vimrc diff --git a/linuxconf b/linuxconf index 49af2a080ede8a168e8617a0fd56f4ae1ab6d313..8aba565e13915b77b6a923aaccc85e8fd9ffff5b 100755 --- a/linuxconf +++ b/linuxconf @@ -57,15 +57,21 @@ function lc_include () { return 0 } -function lci_fsmap () { +function lc_fsmap () { # If existing symlink is correct, do nothing & return 0 (success). # Otherwise, delete the existing symlink. # If the existing item is file/folder, move to '$filename.linuxsync_backup'. # If target folder doesn't exist, create it. # Then create a symlink. - local content_path="$(realpath "$1")" || return $? + local content_path="$1" local symlink_path="$2" + + if [ ! -f "$content_path" ] && [[ "$content_path" == /* ]]; then + : # skip this specific failure case + else + content_path="$(realpath "$content_path")" || return $? + fi if [ -L "$symlink_path" ]; then if [ "$(readlink "$symlink_path")" = "$content_path" ]; then @@ -82,13 +88,6 @@ function lci_fsmap () { ln -s "$content_path" "$symlink_path" } -function lc_fsmap () { - lci_fsmap "$@" - local result=$? - [ $result = 0 ] || lcf_err "lc_fsmap returned error $result" - return $result -} - function lci_state_file_append () { local fname="$1" local prefix="$2"