From 0d9b538970d363174b10f7b9fd995b3a632cfe4b Mon Sep 17 00:00:00 2001 From: "Keith F. Kelly" Date: Thu, 7 Sep 2023 14:20:37 -0700 Subject: [PATCH 1/5] add helpful script for producing compacted ini files that are faster for MiSTer's ini parser to read and shorter for human sharing --- compact_ini_files.sh | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 compact_ini_files.sh diff --git a/compact_ini_files.sh b/compact_ini_files.sh new file mode 100644 index 0000000..a977961 --- /dev/null +++ b/compact_ini_files.sh @@ -0,0 +1,12 @@ +#!/usr/bin/bash + +while IS='' read -r -d '' _path; do + _dir="${_path%/*}" + _name="${_path##*/}" + _stem="${_name%.*}" + _ext="${_name##*.}" + _compacted_name="$_dir/$_stem.compacted.$_ext" + echo "Compacting: $_name >> $_compacted_name" + sed -e 's/\r$//g; s/[\t ]*;.*$//g' $_path | grep -vx -F '' | sed -e 's/$/\r/g' > "$_compacted_name" +done < <(find /media/fat/Ini_Files/ -maxdepth 1 -type f -name "*.ini" -not -name "*.compacted.*" -not -name "*.sample.*" -print0) + From 7216bddfa43caa130269495f649ca8a23abe338c Mon Sep 17 00:00:00 2001 From: "Keith F. Kelly" Date: Thu, 7 Sep 2023 14:11:51 -0700 Subject: [PATCH 2/5] move sample file into Ini_Files subfolder, and other fixes --- update_sample_ini.sh | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/update_sample_ini.sh b/update_sample_ini.sh index e8f890d..64cee29 100644 --- a/update_sample_ini.sh +++ b/update_sample_ini.sh @@ -2,22 +2,21 @@ set -e -echo "Updating MiSTer_sample.ini..." -pushd /media/fat/ > /dev/null +SAMPLE_FILE=/media/fat/Ini_Files/MiSTer.sample.latest.ini +DOWNLOADED_FILE=/tmp/MiSTer.sample.ini +CHANGES_FILE=/media/fat/Ini_Files/MiSTer.sample.ini.CHANGES_$(date +%Y%m%d_%H%M%S) -curl -k -o ./MiSTer_sample.ini.NEW https://raw.githubusercontent.com/MiSTer-devel/Main_MiSTer/master/MiSTer.ini +echo "Updating: ${SAMPLE_FILE}" -TIMESTAMP=$(date +%Y%m%d_%H%M%S) -CHANGES_FILE=./MiSTer_sample.ini.CHANGES_$TIMESTAMP +curl --silent -k https://raw.githubusercontent.com/MiSTer-devel/Main_MiSTer/master/MiSTer.ini | sed -e 's/\r//g' > ${DOWNLOADED_FILE} -if [ -f ./MiSTer_sample.ini ]; then - diff -b -B -w -d -U 0 ./MiSTer_sample.ini ./MiSTer_sample.ini.NEW >> $CHANGES_FILE - if [ $(stat -c %s $CHANGES_FILE) -eq 0 ]; then - rm -f $CHANGES_FILE +if [ -f ${SAMPLE_FILE} ]; then + diff -b -B -w -d -U 0 ${SAMPLE_FILE} ${DOWNLOADED_FILE} | unix2dos > ${CHANGES_FILE} || true + if [ $(stat -c %s ${CHANGES_FILE}) -eq 0 ]; then + rm -f ${CHANGES_FILE} + else + echo "Diff saved to ${CHANGES_FILE}." fi fi -mv -f ./MiSTer_sample.ini.NEW ./MiSTer_sample.ini - -popd > /dev/null -echo "Done." +mv -f ${DOWNLOADED_FILE} ${SAMPLE_FILE} From 5b267c390eebf80126c9823e492a4de4ce11c2ea Mon Sep 17 00:00:00 2001 From: "Keith F. Kelly" Date: Wed, 7 Feb 2024 18:42:26 -0800 Subject: [PATCH 3/5] Rename and restructure INI files folder and sample INI file --- compact_ini_files.sh | 17 ++++++++--------- update_sample_ini.sh | 26 +++++++++++++++----------- 2 files changed, 23 insertions(+), 20 deletions(-) diff --git a/compact_ini_files.sh b/compact_ini_files.sh index a977961..1b54a72 100644 --- a/compact_ini_files.sh +++ b/compact_ini_files.sh @@ -1,12 +1,11 @@ #!/usr/bin/bash -while IS='' read -r -d '' _path; do - _dir="${_path%/*}" - _name="${_path##*/}" - _stem="${_name%.*}" - _ext="${_name##*.}" - _compacted_name="$_dir/$_stem.compacted.$_ext" - echo "Compacting: $_name >> $_compacted_name" - sed -e 's/\r$//g; s/[\t ]*;.*$//g' $_path | grep -vx -F '' | sed -e 's/$/\r/g' > "$_compacted_name" -done < <(find /media/fat/Ini_Files/ -maxdepth 1 -type f -name "*.ini" -not -name "*.compacted.*" -not -name "*.sample.*" -print0) +INPUT_DIR=/media/fat/ini/source +OUTPUT_DIR=/media/fat/ini/compacted +if [ -d "$OUTPUT_DIR" ]; then rm "$OUTPUT_DIR"/*; else mkdir "$OUTPUT_DIR"; fi + +while IFS='' read -r -d '' INI_FILE_NAME; do + echo "Compacting: $INI_FILE_NAME" + sed -e 's/\r$//g; s/[\t ]*;.*$//g' "$INPUT_DIR/$INI_FILE_NAME" | grep -vx -F '' | sed -e 's/$/\r/g' > "$OUTPUT_DIR/$INI_FILE_NAME" +done < <(cd $INPUT_DIR; find * -maxdepth 1 -type f -name "*.ini" -print0) diff --git a/update_sample_ini.sh b/update_sample_ini.sh index 64cee29..8891a85 100644 --- a/update_sample_ini.sh +++ b/update_sample_ini.sh @@ -2,21 +2,25 @@ set -e -SAMPLE_FILE=/media/fat/Ini_Files/MiSTer.sample.latest.ini -DOWNLOADED_FILE=/tmp/MiSTer.sample.ini -CHANGES_FILE=/media/fat/Ini_Files/MiSTer.sample.ini.CHANGES_$(date +%Y%m%d_%H%M%S) +SAMPLE_DIR=/media/fat/ini/sample +NEW_FILE=$SAMPLE_DIR/MiSTer.ini +OLD_FILE=$SAMPLE_DIR/MiSTer.ini.old +DIFF_FILE=$SAMPLE_DIR/$(date +%Y%m%d_%H%M%S).diff -echo "Updating: ${SAMPLE_FILE}" +echo "Updating: ${NEW_FILE}" -curl --silent -k https://raw.githubusercontent.com/MiSTer-devel/Main_MiSTer/master/MiSTer.ini | sed -e 's/\r//g' > ${DOWNLOADED_FILE} +mv "${NEW_FILE}" "${OLD_FILE}" +curl --silent -k https://raw.githubusercontent.com/MiSTer-devel/Main_MiSTer/master/MiSTer.ini | sed -e 's/\r//g' > "${NEW_FILE}" -if [ -f ${SAMPLE_FILE} ]; then - diff -b -B -w -d -U 0 ${SAMPLE_FILE} ${DOWNLOADED_FILE} | unix2dos > ${CHANGES_FILE} || true - if [ $(stat -c %s ${CHANGES_FILE}) -eq 0 ]; then - rm -f ${CHANGES_FILE} +if [ -f "${NEW_FILE}" ]; then + diff -b -B -w -d -U 0 "${OLD_FILE}" "${NEW_FILE}" | unix2dos > "${DIFF_FILE}" || true + if [ $(stat -c %s "${DIFF_FILE}") -eq 0 ]; then + rm -f "${DIFF_FILE}" else - echo "Diff saved to ${CHANGES_FILE}." + echo "Diff saved to ${DIFF_FILE}." fi +else + mv "${OLD_FILE}" "${NEW_FILE}" fi -mv -f ${DOWNLOADED_FILE} ${SAMPLE_FILE} +rm "${OLD_FILE}" From d33434ada4660c464a41de8c97df4c5851325a35 Mon Sep 17 00:00:00 2001 From: "Keith F. Kelly" Date: Wed, 7 Feb 2024 18:59:23 -0800 Subject: [PATCH 4/5] Add handy bash alias 'vimini' to edit a source ini file and then automatically regenerate the compacted form --- nice-linux/.bash_functions | 5 +++++ nice-linux/.bashrc | 6 ++++++ 2 files changed, 11 insertions(+) create mode 100644 nice-linux/.bash_functions diff --git a/nice-linux/.bash_functions b/nice-linux/.bash_functions new file mode 100644 index 0000000..c376e53 --- /dev/null +++ b/nice-linux/.bash_functions @@ -0,0 +1,5 @@ +function vimini() { + vim "$*" + compact_ini_files.sh +} + diff --git a/nice-linux/.bashrc b/nice-linux/.bashrc index 7e99ece..bfbc86e 100644 --- a/nice-linux/.bashrc +++ b/nice-linux/.bashrc @@ -42,6 +42,10 @@ fi # ~/.bash_aliases, instead of adding them here directly. # See /usr/share/doc/bash-doc/examples in the bash-doc package. +if [ -f ~/.bash_functions ]; then + . ~/.bash_functions +fi + if [ -f ~/.bash_aliases ]; then . ~/.bash_aliases fi @@ -56,3 +60,5 @@ if ! shopt -oq posix; then . /etc/bash_completion fi fi + +cd /media/fat/ From cedfd0c0a5d3745c87f8739704c6f58ba66a6ca1 Mon Sep 17 00:00:00 2001 From: "Keith F. Kelly" Date: Wed, 7 Feb 2024 19:20:49 -0800 Subject: [PATCH 5/5] Remember to copy the new .bash_functions file --- make_linux_nice.sh | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/make_linux_nice.sh b/make_linux_nice.sh index fa48edb..6756e9a 100644 --- a/make_linux_nice.sh +++ b/make_linux_nice.sh @@ -4,16 +4,17 @@ set -e echo "Making Linux nice..." -this_dir="$(cd "$(dirname "$0")" && pwd -P)" +THIS_DIR="$(cd "$(dirname "$0")" && pwd -P)" echo " - Modifying root user settings..." -cp -f "$this_dir/nice-linux/.bashrc" /root/ -cp -f "$this_dir/nice-linux/.bash_aliases" /root/ -cp -f "$this_dir/nice-linux/.bash_logout" /root/ -cp -f "$this_dir/nice-linux/.bash_prompt" /root/ -cp -f "$this_dir/nice-linux/.profile" /root/ -cp -f "$this_dir/nice-linux/.vimrc" /root/ -cp -rf "$this_dir/nice-linux/.ssh" /root/ +cp -f "$THIS_DIR/nice-linux/.bashrc" /root/ +cp -f "$THIS_DIR/nice-linux/.bash_aliases" /root/ +cp -f "$THIS_DIR/nice-linux/.bash_functions" /root/ +cp -f "$THIS_DIR/nice-linux/.bash_logout" /root/ +cp -f "$THIS_DIR/nice-linux/.bash_prompt" /root/ +cp -f "$THIS_DIR/nice-linux/.profile" /root/ +cp -f "$THIS_DIR/nice-linux/.vimrc" /root/ +cp -rf "$THIS_DIR/nice-linux/.ssh" /root/ echo " - Configuring ssh KeepAlive settings..." sed -i -E 's|^#[[:blank:]]*ClientAliveInterval[[:blank:]]*.*$|ClientAliveInterval 60|g; s|^#[[:blank:]]*ClientAliveCountMax[[:blank:]]*.*$|ClientAliveCountMax 10|g' /etc/ssh/sshd_config