From 8757164335e8d14a49da5e13c8a1ccbbe9ba5a99 Mon Sep 17 00:00:00 2001 From: "Alex A. Naanou" Date: Wed, 20 Jul 2022 11:18:29 +0300 Subject: [PATCH 1/5] added platform scripts... Signed-off-by: Alex A. Naanou --- post-install | 115 +++++++++++++++++++++++++++++++++++---------------- 1 file changed, 79 insertions(+), 36 deletions(-) diff --git a/post-install b/post-install index fb5fd15..aa40ecd 100644 --- a/post-install +++ b/post-install @@ -30,6 +30,7 @@ USER_RC=~/.${CMD}rc SCRIPT_DIR=${0}.d/ + #---------------------------------------------------------------------- # configuration.... @@ -50,6 +51,7 @@ FEATURES=( user-copy scripts + platform-scripts ) @@ -67,6 +69,21 @@ DIR=( ~/work/EXTERNAL ) +# NOTE: $DIR and these are not run in order -- linking may need other +# stuff done before... +# XXX +CFG_USER_SOURCE=~/Sync/CONFIG/Linux/ +CFG_USER_LINK=( + .gitconfig + .vimrc .gvimrc .vim + .tmux.conf + .config/mc + .config/ulauncher +) +CFG_USER_COPY=( +) + + PKG_DNF=( # tools and recovery... @@ -139,18 +156,6 @@ SERVICES_USER_START=( ) -# XXX -CFG_USER_SOURCE=~/Sync/CONFIG/Linux/ -CFG_USER_LINK=( - .gitconfig - .vimrc .gvimrc .vim - .tmux.conf - .config/mc - .config/ulauncher -) -CFG_USER_COPY=( -) - # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -167,6 +172,35 @@ SAVE=( #---------------------------------------------------------------------- # Builtin features... +# default +# XXX this should be split into system and user sections... +ALL_FEATURES=( + # system... + dnf + flatpak + snap + npm + + #keyd + + start-services + + # user.. + dir + + user-link + user-copy + + #syncthing + + start-user-services + + # keep this last... + scripts + platform-scripts +) + + # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - function feature-dir(){ @setupList mkdir -p - ${DIR[@]} @@ -223,14 +257,14 @@ function feature-snap(){ # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - function feature-start-services(){ + @setupList sudo systemctl start - ${SERVICES_START[@]} @setupList sudo systemctl enable - ${SERVICES_START[@]} - @setupList sudo systemctl --user enable - ${SERVICES_USER_START[@]} } # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - function feature-start-user-services(){ - @setupList sudo systemctl start - ${SERVICES_START[@]} + @setupList sudo systemctl --user enable - ${SERVICES_USER_START[@]} @setupList sudo systemctl --user start - ${SERVICES_USER_START[@]} } @@ -314,41 +348,50 @@ function feature-snapshots(){ ( # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# XXX split these into: +# - system +# - machine -- get platform name +# - user function feature-scripts(){ ( - [ -d "$SCRIPT_DIR" ] \ + if ! [ -z "$1" ] ; then + local dir=$1 + else + local dir=$SCRIPT_DIR + fi + + # no script dir... + [ -d "$dir" ] \ || return 1 - cd "$SCRIPT_DIR" + cd "$dir"l + local script for script in * ; do echo "# $script:" ( @ ./$script ) done ) } +function feature-platform-scripts(){ + # System info... + if ! [ -z "$(type -t dmidecode )" ] ; then + # XXX should we be more specific here and include model number?? + local platform=$( dmidecode \ + | grep -A3 '^System Information' \ + | grep 'Version:' \ + | sed 's/\s*Version:\s*//' ) + else + local platform=default + fi + + feature-scripts "$SCRIPT_DIR/$platform" +} + + #---------------------------------------------------------------------- # feature api... -# default -ALL_FEATURES=( - dir - - dnf - flatpak - snap - npm - - start-services - start-user-services - - user-link - user-copy - - # keep this last... - scripts -) - function @feature(){ while ! [ -z "$1" ] ; do local feauture="$1" @@ -490,7 +533,7 @@ Available scripts: Examples: Only create dirs and links (features dir and user-link)... - \$ $CMD -all +die +user-link + \$ $CMD -all +dir +user-link Same as above... \$ FEATURES=( dir user-link ) $CMD From 92f47b689a013c9c55f93149695d4b8132f8e3c6 Mon Sep 17 00:00:00 2001 From: "Alex A. Naanou" Date: Wed, 20 Jul 2022 14:13:08 +0300 Subject: [PATCH 2/5] refactoring... Signed-off-by: Alex A. Naanou --- post-install | 3 ++- post-install.d/machine/README | 0 2 files changed, 2 insertions(+), 1 deletion(-) create mode 100644 post-install.d/machine/README diff --git a/post-install b/post-install index aa40ecd..1707b58 100644 --- a/post-install +++ b/post-install @@ -28,6 +28,7 @@ SYSTEM_RC=${0}rc USER_RC=~/.${CMD}rc SCRIPT_DIR=${0}.d/ +MACHINE_SCRIPT_DIR=$SCRIPT_DIR/michine/ @@ -383,7 +384,7 @@ function feature-platform-scripts(){ local platform=default fi - feature-scripts "$SCRIPT_DIR/$platform" + feature-scripts "$MACHINE_SCRIPT_DIR/$platform" } diff --git a/post-install.d/machine/README b/post-install.d/machine/README new file mode 100644 index 0000000..e69de29 From da9497c5ffb0a141c274f7b43f15d432cc6b2fd4 Mon Sep 17 00:00:00 2001 From: "Alex A. Naanou" Date: Wed, 20 Jul 2022 17:05:36 +0300 Subject: [PATCH 3/5] more refactoring... Signed-off-by: Alex A. Naanou --- post-install | 53 +++++++++++++++++-------- post-install.d/platform/README | 1 + post-install.d/{machine => user}/README | 0 3 files changed, 38 insertions(+), 16 deletions(-) create mode 100644 post-install.d/platform/README rename post-install.d/{machine => user}/README (100%) diff --git a/post-install b/post-install index 1707b58..1894699 100644 --- a/post-install +++ b/post-install @@ -7,6 +7,7 @@ # - edit system config files # - might be a good idea to add gui/no-gui options... # - ssh-keygen... +# - add --system and --user flags to only do system/user stuff... # # #---------------------------------------------------------------------- @@ -27,8 +28,22 @@ CMD=$(basename $0) SYSTEM_RC=${0}rc USER_RC=~/.${CMD}rc +# XXX do we need to split user and system scripts??? SCRIPT_DIR=${0}.d/ -MACHINE_SCRIPT_DIR=$SCRIPT_DIR/michine/ +USER_SCRIPT_DIR=${0}.d/user/ + +# System info... +if ! [ -z "$(type -t dmidecode )" ] ; then + # XXX should we be more specific here and include model number?? + PLATFORM=$( dmidecode \ + | grep -A3 '^System Information' \ + | grep 'Version:' \ + | sed 's/\s*Version:\s*//' ) +else + PLATFORM=unknown +fi + +PLATFORM_SCRIPT_DIR=${SCRIPT_DIR}/platform/${PLATFORM} @@ -53,6 +68,7 @@ FEATURES=( scripts platform-scripts + user-scripts ) @@ -199,6 +215,7 @@ ALL_FEATURES=( # keep this last... scripts platform-scripts + user-scripts ) @@ -349,10 +366,7 @@ function feature-snapshots(){ ( # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -# XXX split these into: -# - system -# - machine -- get platform name -# - user +# XXX skip scripts starting in "-" function feature-scripts(){ ( if ! [ -z "$1" ] ; then local dir=$1 @@ -373,18 +387,11 @@ function feature-scripts(){ ( ) } function feature-platform-scripts(){ - # System info... - if ! [ -z "$(type -t dmidecode )" ] ; then - # XXX should we be more specific here and include model number?? - local platform=$( dmidecode \ - | grep -A3 '^System Information' \ - | grep 'Version:' \ - | sed 's/\s*Version:\s*//' ) - else - local platform=default - fi + feature-scripts "$PLATFORM_SCRIPT_DIR" +} - feature-scripts "$MACHINE_SCRIPT_DIR/$platform" +function feature-user-scripts(){ + feature-scripts "$USER_SCRIPT_DIR" } @@ -521,6 +528,10 @@ Feature list manipulation: -FEATURE - remove FEATURE from list +FEATURE - add FEATURE to lost +Helpers: + --make-platform-dir - make platform directory for current platform + and exit. + Default features: ${FEATURES[@]} @@ -585,7 +596,17 @@ while ! [ -z "$1" ] ; do shift ;; + # helpers... + --make-platform-dir) + echo "# Patform script dir: $PLATFORM_SCRIPT_DIR" + [ -d "$PLATFORM_SCRIPT_DIR" ] \ + || @ mkdir -p "$PLATFORM_SCRIPT_DIR" + exit + ;; + + # feature manipulation... + # NOTE: keep these last... +all) FEATURES=( ${ALL_FEATURES[@]} ) shift diff --git a/post-install.d/platform/README b/post-install.d/platform/README new file mode 100644 index 0000000..c0fbc0c --- /dev/null +++ b/post-install.d/platform/README @@ -0,0 +1 @@ +This directory contains machine-specific scripts. diff --git a/post-install.d/machine/README b/post-install.d/user/README similarity index 100% rename from post-install.d/machine/README rename to post-install.d/user/README From c3d512baf89c684af28e89eeb324638475dead29 Mon Sep 17 00:00:00 2001 From: "Alex A. Naanou" Date: Wed, 20 Jul 2022 17:09:32 +0300 Subject: [PATCH 4/5] minor tweaks... Signed-off-by: Alex A. Naanou --- post-install | 3 +++ 1 file changed, 3 insertions(+) diff --git a/post-install b/post-install index 1894699..b4f5aec 100644 --- a/post-install +++ b/post-install @@ -381,6 +381,9 @@ function feature-scripts(){ ( cd "$dir"l local script for script in * ; do + ( [ "${script}" == "README" ] \ + || [ "${script:0:1}" == "-" ] )\ + && continue echo "# $script:" ( @ ./$script ) done From 03730bbfa9a405f25c91327a2ceaafe242359c31 Mon Sep 17 00:00:00 2001 From: "Alex A. Naanou" Date: Thu, 21 Jul 2022 11:11:16 +0300 Subject: [PATCH 5/5] notes... Signed-off-by: Alex A. Naanou --- post-install | 1 + 1 file changed, 1 insertion(+) diff --git a/post-install b/post-install index b4f5aec..d5a4615 100644 --- a/post-install +++ b/post-install @@ -381,6 +381,7 @@ function feature-scripts(){ ( cd "$dir"l local script for script in * ; do + # skip README and scripts starting with '-'... ( [ "${script}" == "README" ] \ || [ "${script:0:1}" == "-" ] )\ && continue