aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorDavid M. Syzdek <david@syzdek.net>2018-04-27 13:03:14 -0800
committerDavid M. Syzdek <david@syzdek.net>2018-04-27 13:03:14 -0800
commit6f1fe83a36d727aec9de7e44e1237e55ac78e51c (patch)
tree5eed584be945a6ba703390ebcd63d57fc551491e
parentd50b5114cfcc00136c4a89ad221cf0ac52bb0ead (diff)
downloadiperd-6f1fe83a36d727aec9de7e44e1237e55ac78e51c.tar.gz
iperd-6f1fe83a36d727aec9de7e44e1237e55ac78e51c.tar.bz2
iperd-6f1fe83a36d727aec9de7e44e1237e55ac78e51c.tar.xz
iperd-6f1fe83a36d727aec9de7e44e1237e55ac78e51c.zip
moving common functions to iperd.profile
-rw-r--r--src/scripts/configure.sh96
-rw-r--r--src/scripts/iperd.profile135
2 files changed, 141 insertions, 90 deletions
diff --git a/src/scripts/configure.sh b/src/scripts/configure.sh
index 38e258d..ba2cca3 100644
--- a/src/scripts/configure.sh
+++ b/src/scripts/configure.sh
@@ -38,38 +38,14 @@ ACTION="${1,,}"
38REGEN_FILE="${2,,}" 38REGEN_FILE="${2,,}"
39 39
40 40
41# set defaults 41# set PROG_NAME and load profile
42PROG_NAME="$(basename "${0}")" 42PROG_NAME="$(basename "${0}")"
43BASEDIR="$(dirname "${0}")/../../" 43IPERD_PROFILE="$(dirname "${0}")/iperd.profile"
44DISTRODIR="${DISTRODIR:-${BASEDIR}/src/distros}" 44if test ! -f "${IPERD_PROFILE}";then
45CONFIGDIR="${CONFIGDIR:-${BASEDIR}/var/config}" 45 echo "${PROG_NAME}: unable to find iperd.profile" 1>&2;
46CONFIG="${CONFIG:-${CONFIGDIR}/iperd.conf}" 46 exit 1;
47
48
49# load configuration
50if test -f ${CONFIG};then
51 . ${CONFIG}
52fi 47fi
53 48. "${IPERD_PROFILE}"
54
55# set missing defaults
56DEFAULT_PART_TYPE="hybrid"
57DEFAULT_PART_SIZE="0"
58DEFAULT_IMG_SIZE="1900"
59DEFAULT_ISO_TYPE="bios"
60CONFIG_PART_TYPE="${CONFIG_PART_TYPE:-${DEFAULT_PART_TYPE}}"
61CONFIG_PART_SIZE="${CONFIG_PART_SIZE:-${DEFAULT_PART_SIZE}}"
62CONFIG_IMG_SIZE="${CONFIG_IMG_SIZE:-${DEFAULT_IMG_SIZE}}"
63CONFIG_ISO_TYPE="${CONFIG_ISO_TYPE:-${DEFAULT_ISO_TYPE}}"
64
65
66# set exit codes to trigger specific xargs exit codes
67DIALOG_OK=0 # xargs => 0
68DIALOG_CANCEL=255 # xargs => 124
69DIALOG_ESC=255 # xargs => 124
70DIALOG_EXTRA=126 # xargs => 126
71DIALOG_HELP=0 # xargs => 0
72export DIALOG_OK DIALOG_CANCEL DIALOG_HELP DIALOG_EXTRA DIALOG_ESC
73 49
74 50
75############### 51###############
@@ -534,66 +510,6 @@ generate_cfg()
534} 510}
535 511
536 512
537list_cfg_distros()
538{
539 egrep '^#[[:alnum:]]+-' "${CONFIG}" \
540 |cut -d- -f1 \
541 |cut -d'#' -f2 \
542 |sort \
543 |uniq
544}
545
546
547list_distros()
548{
549 egrep '^[[:space:]]{0,}[a-zA-Z0-9]{1,}[[:space:]]' ${DISTRODIR}/*/option* \
550 |sed \
551 -e 's/^[a-zA-Z0-9/]\{1,\}://g' \
552 -e 's/ @[[:alnum:][:punct:]]\{1,\}@$//g' \
553 -e "s/[[:space:]]\{2,\}/ /g" \
554 -e 's/^ //g' \
555 -e 's/ $//g' \
556 |cut -d: -f2 \
557 |sort -n \
558 |uniq
559}
560
561
562list_vers()
563{
564 egrep '^[[:space:]]{0,}[a-zA-Z0-9]{1,}-' "${1}" \
565 |sed \
566 -e 's/[[:space:]]\{1,\}/ /g' \
567 -e 's/[-a-z0-9_/]\{1,\}: //g' \
568 -e 's/^ //g' \
569 |cut -d\ -f1 \
570 |sort -n \
571 |uniq
572}
573
574
575list_vers_opts()
576{
577 OPTFILE="${1}"
578
579 # generate list of options
580 for VERS in $(list_vers ${OPTFILE});do
581 grep "^#${VERS}$" "${CONFIG}.new" > /dev/null 2> /dev/null
582 if test $? -eq 0;then
583 STATE=on
584 else
585 STATE=off
586 fi
587 egrep "^[[:space:]]{0,}${VERS}[[:space:]]" ${OPTFILE} |sed -e "s/$/ ${STATE}/g"
588 done \
589 |sed \
590 -e "s/[[:space:]]\{1,\}/ /g" \
591 -e 's/^ //g' \
592 -e 's/ $//g' \
593 |sort -n
594}
595
596
597prereqs() 513prereqs()
598{ 514{
599 trap cleanup EXIT 515 trap cleanup EXIT
diff --git a/src/scripts/iperd.profile b/src/scripts/iperd.profile
new file mode 100644
index 0000000..90fb621
--- /dev/null
+++ b/src/scripts/iperd.profile
@@ -0,0 +1,135 @@
1#!/bin/sh
2#
3# IP Engineering Rescue Disk
4# Copyright (C) 2017, 2018 David M. Syzdek <david@syzdek.net>.
5#
6# @SYZDEK_BSD_LICENSE_START@
7#
8# Redistribution and use in source and binary forms, with or without
9# modification, are permitted provided that the following conditions are
10# met:
11#
12# * Redistributions of source code must retain the above copyright
13# notice, this list of conditions and the following disclaimer.
14# * Redistributions in binary form must reproduce the above copyright
15# notice, this list of conditions and the following disclaimer in the
16# documentation and/or other materials provided with the distribution.
17# * Neither the name of David M. Syzdek nor the
18# names of its contributors may be used to endorse or promote products
19# derived from this software without specific prior written permission.
20#
21# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
22# IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
23# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL DAVID M. SYZDEK BE LIABLE FOR
25# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31# SUCH DAMAGE.
32#
33# @SYZDEK_BSD_LICENSE_END@
34#
35
36# set defaults
37BASEDIR="$(dirname "${0}")/../../"
38DISTRODIR="${DISTRODIR:-${BASEDIR}/src/distros}"
39CONFIGDIR="${CONFIGDIR:-${BASEDIR}/var/config}"
40CONFIG="${CONFIG:-${CONFIGDIR}/iperd.conf}"
41
42
43# load configuration
44if test -f ${CONFIG};then
45 . ${CONFIG}
46fi
47
48
49# set missing defaults
50DEFAULT_PART_TYPE="hybrid"
51DEFAULT_PART_SIZE="0"
52DEFAULT_IMG_SIZE="1900"
53DEFAULT_ISO_TYPE="bios"
54CONFIG_PART_TYPE="${CONFIG_PART_TYPE:-${DEFAULT_PART_TYPE}}"
55CONFIG_PART_SIZE="${CONFIG_PART_SIZE:-${DEFAULT_PART_SIZE}}"
56CONFIG_IMG_SIZE="${CONFIG_IMG_SIZE:-${DEFAULT_IMG_SIZE}}"
57CONFIG_ISO_TYPE="${CONFIG_ISO_TYPE:-${DEFAULT_ISO_TYPE}}"
58
59
60# set exit codes to trigger specific xargs exit codes
61DIALOG_OK=0 # xargs => 0
62DIALOG_CANCEL=255 # xargs => 124
63DIALOG_ESC=255 # xargs => 124
64DIALOG_EXTRA=126 # xargs => 126
65DIALOG_HELP=0 # xargs => 0
66export DIALOG_OK DIALOG_CANCEL DIALOG_HELP DIALOG_EXTRA DIALOG_ESC
67
68
69###############
70# #
71# Functions #
72# #
73###############
74
75list_cfg_distros()
76{
77 egrep '^#[[:alnum:]]+-' "${CONFIG}" \
78 |cut -d- -f1 \
79 |cut -d'#' -f2 \
80 |sort \
81 |uniq
82}
83
84
85list_distros()
86{
87 egrep '^[[:space:]]{0,}[a-zA-Z0-9]{1,}[[:space:]]' ${DISTRODIR}/*/option* \
88 |sed \
89 -e 's/^[a-zA-Z0-9/]\{1,\}://g' \
90 -e 's/ @[[:alnum:][:punct:]]\{1,\}@$//g' \
91 -e "s/[[:space:]]\{2,\}/ /g" \
92 -e 's/^ //g' \
93 -e 's/ $//g' \
94 |cut -d: -f2 \
95 |sort -n \
96 |uniq
97}
98
99
100list_vers()
101{
102 egrep '^[[:space:]]{0,}[a-zA-Z0-9]{1,}-' "${1}" \
103 |sed \
104 -e 's/[[:space:]]\{1,\}/ /g' \
105 -e 's/[-a-z0-9_/]\{1,\}: //g' \
106 -e 's/^ //g' \
107 |cut -d\ -f1 \
108 |sort -n \
109 |uniq
110}
111
112
113list_vers_opts()
114{
115 OPTFILE="${1}"
116
117 # generate list of options
118 for VERS in $(list_vers ${OPTFILE});do
119 grep "^#${VERS}$" "${CONFIG}.new" > /dev/null 2> /dev/null
120 if test $? -eq 0;then
121 STATE=on
122 else
123 STATE=off
124 fi
125 egrep "^[[:space:]]{0,}${VERS}[[:space:]]" ${OPTFILE} |sed -e "s/$/ ${STATE}/g"
126 done \
127 |sed \
128 -e "s/[[:space:]]\{1,\}/ /g" \
129 -e 's/^ //g' \
130 -e 's/ $//g' \
131 |sort -n
132}
133
134
135# end of profile