diff --git a/compact_ini_files.sh b/compact_ini_files.sh new file mode 100644 index 0000000..1b54a72 --- /dev/null +++ b/compact_ini_files.sh @@ -0,0 +1,11 @@ +#!/usr/bin/bash + +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/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 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/ diff --git a/update_sample_ini.sh b/update_sample_ini.sh index e8f890d..8891a85 100644 --- a/update_sample_ini.sh +++ b/update_sample_ini.sh @@ -2,22 +2,25 @@ set -e -echo "Updating MiSTer_sample.ini..." -pushd /media/fat/ > /dev/null +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 -curl -k -o ./MiSTer_sample.ini.NEW https://raw.githubusercontent.com/MiSTer-devel/Main_MiSTer/master/MiSTer.ini +echo "Updating: ${NEW_FILE}" -TIMESTAMP=$(date +%Y%m%d_%H%M%S) -CHANGES_FILE=./MiSTer_sample.ini.CHANGES_$TIMESTAMP +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 ./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 "${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 ${DIFF_FILE}." fi +else + mv "${OLD_FILE}" "${NEW_FILE}" fi -mv -f ./MiSTer_sample.ini.NEW ./MiSTer_sample.ini - -popd > /dev/null -echo "Done." +rm "${OLD_FILE}"