From 361949b8bc76ae8054b049eb30d027baa6e03247 Mon Sep 17 00:00:00 2001 From: jsalatiel Date: Thu, 6 Jun 2024 07:36:42 -0300 Subject: [PATCH 1/2] Add a sysext for vim-huge There are several cases when the user needs to edit k8s yamls inplace directly on the master nodes and having syntax highlighting and advanced formatting of vim available is a nice feature since the default vim of flatcar have those disabled. --- create_vim-huge_sysext.sh | 49 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 create_vim-huge_sysext.sh diff --git a/create_vim-huge_sysext.sh b/create_vim-huge_sysext.sh new file mode 100644 index 0000000..412ea81 --- /dev/null +++ b/create_vim-huge_sysext.sh @@ -0,0 +1,49 @@ +#!/usr/bin/env bash +set -euo pipefail + +export ARCH="${ARCH-x86-64}" +SCRIPTFOLDER="$(dirname "$(readlink -f "$0")")" + +if [ $# -lt 2 ] || [ "$1" = "-h" ] || [ "$1" = "--help" ]; then + echo "Usage: $0 VERSION SYSEXTNAME" + echo "The script will download the vim version you choose (e.g. 9.0.1678 ), build a static binary and create a sysext squashfs image with the name SYSEXTNAME.raw in the current folder." + echo "A temporary directory named SYSEXTNAME in the current folder will be created and deleted again." + echo "All files in the sysext image will be owned by root." + echo "The build process requires docker" + "${SCRIPTFOLDER}"/bake.sh --help + exit 1 +fi + +VERSION="$1" +SYSEXTNAME="$2" + +if ! command -v docker &>/dev/null; then + echo Missing docker in path + exit 1 +fi + +SUFFIX= +if [ "${ARCH}" = "x86-64" ] || [ "${ARCH}" = "x86_64" ]; then + ARCH=amd64 +elif [ "${ARCH}" = "aarch64" ] || [ "${ARCH}" = "arm64" ]; then + ARCH="arm64" + SUFFIX="v8" +fi +IMG=docker.io/"${ARCH}${SUFFIX}"/alpine:3.19 +mkdir -p "${SYSEXTNAME}" +cat >"${SYSEXTNAME}"/build.sh < Date: Thu, 1 Aug 2024 10:50:34 -0300 Subject: [PATCH 2/2] Improve vimrc defaults --- create_vim-huge_sysext.sh | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) mode change 100644 => 100755 create_vim-huge_sysext.sh diff --git a/create_vim-huge_sysext.sh b/create_vim-huge_sysext.sh old mode 100644 new mode 100755 index 412ea81..7b0da05 --- a/create_vim-huge_sysext.sh +++ b/create_vim-huge_sysext.sh @@ -45,5 +45,32 @@ EOF chmod +x "${SYSEXTNAME}"/build.sh docker run -v "${PWD}/${SYSEXTNAME}":/install_root/ --rm "${IMG}" /bin/sh -c /install_root/build.sh rm -f "${SYSEXTNAME}"/build.sh +cat > "${SYSEXTNAME}"/usr/share/vim/vimrc <<-"EOF" +" Vim will load $VIMRUNTIME/defaults.vim if the user does not have a vimrc. +" This happens after /etc/vim/vimrc(.local) are loaded, so it will override +" any settings in these files. +" Thus we source the default and disable load defaults afterwords so we can override +" options in these files. +" Use :verbose set $option? or :scriptnames to see the where any option is being set from +if filereadable("/usr/share/vim/vim90/defaults.vim") + source /usr/share/vim/vim90/defaults.vim +endif +let g:skip_defaults_vim = 1 + +" Read vimrc.local from /etc if it exists. (read-write root images) +if filereadable("/etc/vim/vimrc.local") + source /etc/vim/vimrc.local +endif + +" Useful config for editing yaml files +set ai ts=2 sw=2 et +set pastetoggle= +set ignorecase +set mouse-=a +inoremap +map :set cursorcolumn! +set maxmempattern=50000 +EOF + RELOAD=1 "${SCRIPTFOLDER}"/bake.sh "${SYSEXTNAME}" rm -rf "${SYSEXTNAME}"