From f3697306960d5175829a155eb83990927ef7b1fe Mon Sep 17 00:00:00 2001 From: jonas Date: Sat, 14 Oct 2006 09:51:31 +0000 Subject: Move config loading to new file common-settings, and rename file functions to commmon-functions. git-svn-id: svn+ssh://xayide/home/jonas/private_svn/fleshybrid/homebase@34 8f53b18a-e215-0410-8885-9f593d34873e --- 0_format.sh | 7 +-- 1_makerootfs.sh | 7 +-- 2_install.sh | 7 +-- 3_configure.sh | 7 +-- 9_resync.sh | 7 +-- chroot.sh | 5 +- common-functions | 151 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ common-settings | 12 +++++ functions | 151 ------------------------------------------------------- mount.sh | 5 +- umount.sh | 5 +- 11 files changed, 176 insertions(+), 188 deletions(-) create mode 100644 common-functions create mode 100644 common-settings delete mode 100644 functions diff --git a/0_format.sh b/0_format.sh index 6004327..9438b3e 100755 --- a/0_format.sh +++ b/0_format.sh @@ -2,11 +2,8 @@ set -e -. ./config-DEFAULTS || exit 1 -. ./config-HOST || exit 1 -. ./config-TARGET || exit 1 -. ./config-MANDATED || exit 1 -. ./functions || exit 1 +. ./common-setting || exit 1 +. ./common-functions || exit 1 #sfdisk -l "$usbdev_host" #TODO: Ask if you really want to erase shown partitions diff --git a/1_makerootfs.sh b/1_makerootfs.sh index e9f732c..84ec475 100755 --- a/1_makerootfs.sh +++ b/1_makerootfs.sh @@ -2,11 +2,8 @@ set -e -. ./config-DEFAULTS || exit 1 -. ./config-HOST || exit 1 -. ./config-TARGET || exit 1 -. ./config-MANDATED || exit 1 -. ./functions || exit 1 +. ./common-settings || exit 1 +. ./common-functions || exit 1 mkdir "$targettemp" case "$debootstrap" in diff --git a/2_install.sh b/2_install.sh index 6a7745c..830a294 100755 --- a/2_install.sh +++ b/2_install.sh @@ -2,11 +2,8 @@ set -e -. ./config-DEFAULTS || exit 1 -. ./config-HOST || exit 1 -. ./config-TARGET || exit 1 -. ./config-MANDATED || exit 1 -. ./functions || exit 1 +. ./common-settings || exit 1 +. ./common-functions || exit 1 # Save specs for debugging later if [ -f "$baseworkdir/specs" ]; then diff --git a/3_configure.sh b/3_configure.sh index 8bf169d..98199c7 100755 --- a/3_configure.sh +++ b/3_configure.sh @@ -2,11 +2,8 @@ set -e -. ./config-DEFAULTS || exit 1 -. ./config-HOST || exit 1 -. ./config-TARGET || exit 1 -. ./config-MANDATED || exit 1 -. ./functions || exit 1 +. ./common-settings || exit 1 +. ./common-functions || exit 1 # Check if already installed if ! ./chroot.sh grep -q 'root::' "/etc/shadow"; then diff --git a/9_resync.sh b/9_resync.sh index ed2dd13..8771aa5 100755 --- a/9_resync.sh +++ b/9_resync.sh @@ -2,11 +2,8 @@ set -e -. ./config-DEFAULTS || exit 1 -. ./config-HOST || exit 1 -. ./config-TARGET || exit 1 -. ./config-MANDATED || exit 1 -. ./functions || exit 1 +. ./common-settings || exit 1 +. ./common-functions || exit 1 mount "$rootdev_host" "$mountpoint" rsync -av --delete --one-file-system "$mountpoint/"* "$targettemp/" --exclude 'etc/shadow*' --exclude 'etc/gshadow*' --exclude 'etc/ssh/ssh_host_*_key*' --exclude 'root/**' --dry-run diff --git a/chroot.sh b/chroot.sh index 76db488..3bdc9b3 100755 --- a/chroot.sh +++ b/chroot.sh @@ -1,9 +1,6 @@ #!/bin/sh -. ./config-DEFAULTS || exit 1 -. ./config-HOST || exit 1 -. ./config-TARGET || exit 1 -. ./config-MANDATED || exit 1 +. ./common-settings || exit 1 if [ "$1" = "temp" ]; then shift diff --git a/common-functions b/common-functions new file mode 100644 index 0000000..58536cf --- /dev/null +++ b/common-functions @@ -0,0 +1,151 @@ +#!/bin/sh + +# Comments on coding style: +# * shift mandatory function arguments: Provokes error if missing +# * quote variables: We want to support oddities like spaces in paths + +function preserveolderfile() { + ## DESC: Preserve copy of file, unless one exists already + # File to tweak + file="$1"; shift + # Extension used for new backup + newext="$1" + # Space-delimited list of possible extensions, default last + extensions="orig old" + for ext in $extensions; do + backupfile="$file.$ext" + [ "$ext" = "$newext" ] && newext_valid="yes" + if [ -f "$backupfile" ]; then + [ -n "$DEBUG" ] && echo "DEBUG: Backup file \"$backupfile\" not found - continuing." >&2 + continue + elif [ -e "$backupfile" ]; then + echo "ERROR: Backup file \"$backupfile\" is not a regular file." >&2 + return 1 + else + [ -n "$DEBUG" ] && echo "DEBUG: Backup file \"$backupfile\" found - exit silently." >&2 + return 0 + fi + done + if [ -n "$newext" ];then + if [ "$newext_valid" = "yes" ]; then + backupfile="$file.$newext" + else + echo "WARNING: Backup extension \"$newext\" is invalid - using default instead" >&2 + fi + fi + if [ -f "$file" ]; then + cp -p "file" "$backupfile" + elif [ -e "$file" ]; then + echo "ERROR: Backup of file \"$file\" failed - not a regular file." >&2 + return 1 + else + touch "$backupfile" + fi + return 0 +} + +function enableoraddlines() { + ## DESC: Add lines to file, or replace if similar exist already + # File to tweak + file="$1"; shift + # Word number in line to search for and replace if found + # FIXME: This is broken - wordno unconditionally becomes firstword later on + wordno="$1"; shift + [ -e "$file" ] || touch "$file" + for line; do + [ -z "$line" ] && continue + firstword=$(echo "$line" | awk "{print \$$wordno}") + # FIXME: Why doesn't it work to print ARGVOUT in END block? + linemissing=$(perl -i -pe "END { print \"$line\\n\" unless \$seen } s¡^[#;\s]*($firstword)\s.*¡$line\\n¡ and \$seen++" "$file") +#"This stray quote is only to please buggy mc (cooledit) code hiliting + [ -n "$linemissing" ] && echo $linemissing >> "$file" + done + # FIXME: Figure out what exits non-zero above + return 0 +} + +function preserveandaddlines() { + ## DESC: Backup older file and add lines to it + # File to tweak + file="$1"; shift + # Extension of backup file + ext="$1"; shift + # Word number in line to search for and replace if found + # FIXME: This is broken - wordno unconditionally becomes firstword later on + wordno="$1"; shift + preserveolderfile "$file" "$ext" +# enableoraddlines "$file" "$wordno" $@ + # FIXME: Somehow avoid expansion, to avoid having to duplicate the whole enableoraddlines() + [ -e "$file" ] || touch "$file" + for line; do + [ -z "$line" ] && continue + firstword=$(echo "$line" | awk "{print \$$wordno}") + # FIXME: Why doesn't it work to print ARGVOUT in END block? + linemissing=$(perl -i -pe "END { print \"$line\\n\" unless \$seen } s¡^[#;\s]*($firstword)\s.*¡$line\\n¡ and \$seen++" "$file") +#"This stray quote is only to please buggy mc (cooledit) code hiliting + [ -n "$linemissing" ] && echo $linemissing >> "$file" + done + # FIXME: Figure out what exits non-zero above + return 0 +} + +function preserveandhashdisablelines() { + ## DESC: Backup older file and disable lines in it + # File to tweak + file="$1"; shift + # Extension of backup file + ext="$1"; shift + # Word number in line to search for and replace if found + # FIXME: This is broken - wordno unconditionally becomes firstword later on + wordno="$1"; shift + preserveolderfile "$file" "$ext" +# disablelines "$file" "$wordno" "#" $@ + # FIXME: Somehow avoid expansion, to make possibe a separate disablelines() + [ -e "$file" ] || touch "$file" + for line; do + [ -z "$line" ] && continue + firstword=$(echo "$line" | awk "{print \$$wordno}") + # FIXME: Why doesn't it work to print ARGVOUT in END block? + linemissing=$(perl -i -pe "END { print \"$line\\n\" unless \$seen } s¡^(\s*$firstword)\s.*¡#$line\\n¡ and \$seen++" "$file") +#"This stray quote is only to please buggy mc (cooledit) code hiliting + [ -n "$linemissing" ] && echo >2 "Line \"$linemissing\" not found to disable in $file" + done + # FIXME: Figure out what exits non-zero above + return 0 +} + +function perlrelines() { + ## DESC: Apply perl regex to lines of a single file + # File to tweak + file=$1; shift + backupfile="`savebackupfile "$file"`" + for regexp; do + perl -pi -e "$regexp" "$file" + done + cleanbackupfile "$file" "$backupfile" + + # FIXME: Figure out what exits non-zero above + return 0 +} + +function mkgrubdevmap() { + ## DESC: Spit out GRUB config used for /boot/grub/devices.map + device="$1"; shift + cat <&2 - continue - elif [ -e "$backupfile" ]; then - echo "ERROR: Backup file \"$backupfile\" is not a regular file." >&2 - return 1 - else - [ -n "$DEBUG" ] && echo "DEBUG: Backup file \"$backupfile\" found - exit silently." >&2 - return 0 - fi - done - if [ -n "$newext" ];then - if [ "$newext_valid" = "yes" ]; then - backupfile="$file.$newext" - else - echo "WARNING: Backup extension \"$newext\" is invalid - using default instead" >&2 - fi - fi - if [ -f "$file" ]; then - cp -p "file" "$backupfile" - elif [ -e "$file" ]; then - echo "ERROR: Backup of file \"$file\" failed - not a regular file." >&2 - return 1 - else - touch "$backupfile" - fi - return 0 -} - -function enableoraddlines() { - ## DESC: Add lines to file, or replace if similar exist already - # File to tweak - file="$1"; shift - # Word number in line to search for and replace if found - # FIXME: This is broken - wordno unconditionally becomes firstword later on - wordno="$1"; shift - [ -e "$file" ] || touch "$file" - for line; do - [ -z "$line" ] && continue - firstword=$(echo "$line" | awk "{print \$$wordno}") - # FIXME: Why doesn't it work to print ARGVOUT in END block? - linemissing=$(perl -i -pe "END { print \"$line\\n\" unless \$seen } s¡^[#;\s]*($firstword)\s.*¡$line\\n¡ and \$seen++" "$file") -#"This stray quote is only to please buggy mc (cooledit) code hiliting - [ -n "$linemissing" ] && echo $linemissing >> "$file" - done - # FIXME: Figure out what exits non-zero above - return 0 -} - -function preserveandaddlines() { - ## DESC: Backup older file and add lines to it - # File to tweak - file="$1"; shift - # Extension of backup file - ext="$1"; shift - # Word number in line to search for and replace if found - # FIXME: This is broken - wordno unconditionally becomes firstword later on - wordno="$1"; shift - preserveolderfile "$file" "$ext" -# enableoraddlines "$file" "$wordno" $@ - # FIXME: Somehow avoid expansion, to avoid having to duplicate the whole enableoraddlines() - [ -e "$file" ] || touch "$file" - for line; do - [ -z "$line" ] && continue - firstword=$(echo "$line" | awk "{print \$$wordno}") - # FIXME: Why doesn't it work to print ARGVOUT in END block? - linemissing=$(perl -i -pe "END { print \"$line\\n\" unless \$seen } s¡^[#;\s]*($firstword)\s.*¡$line\\n¡ and \$seen++" "$file") -#"This stray quote is only to please buggy mc (cooledit) code hiliting - [ -n "$linemissing" ] && echo $linemissing >> "$file" - done - # FIXME: Figure out what exits non-zero above - return 0 -} - -function preserveandhashdisablelines() { - ## DESC: Backup older file and disable lines in it - # File to tweak - file="$1"; shift - # Extension of backup file - ext="$1"; shift - # Word number in line to search for and replace if found - # FIXME: This is broken - wordno unconditionally becomes firstword later on - wordno="$1"; shift - preserveolderfile "$file" "$ext" -# disablelines "$file" "$wordno" "#" $@ - # FIXME: Somehow avoid expansion, to make possibe a separate disablelines() - [ -e "$file" ] || touch "$file" - for line; do - [ -z "$line" ] && continue - firstword=$(echo "$line" | awk "{print \$$wordno}") - # FIXME: Why doesn't it work to print ARGVOUT in END block? - linemissing=$(perl -i -pe "END { print \"$line\\n\" unless \$seen } s¡^(\s*$firstword)\s.*¡#$line\\n¡ and \$seen++" "$file") -#"This stray quote is only to please buggy mc (cooledit) code hiliting - [ -n "$linemissing" ] && echo >2 "Line \"$linemissing\" not found to disable in $file" - done - # FIXME: Figure out what exits non-zero above - return 0 -} - -function perlrelines() { - ## DESC: Apply perl regex to lines of a single file - # File to tweak - file=$1; shift - backupfile="`savebackupfile "$file"`" - for regexp; do - perl -pi -e "$regexp" "$file" - done - cleanbackupfile "$file" "$backupfile" - - # FIXME: Figure out what exits non-zero above - return 0 -} - -function mkgrubdevmap() { - ## DESC: Spit out GRUB config used for /boot/grub/devices.map - device="$1"; shift - cat <