Merge lp:~launchpad-baby-gnu/ubumirror/feature-set-config-and-log-files-from-command-line into lp:ubumirror

Proposed by Daniel Dehennin
Status: Needs review
Proposed branch: lp:~launchpad-baby-gnu/ubumirror/feature-set-config-and-log-files-from-command-line
Merge into: lp:ubumirror
Diff against target: 855 lines (+717/-46)
5 files modified
ubuarchive (+144/-10)
ubucdimage (+143/-9)
ubucloudimage (+144/-9)
ubuports (+143/-9)
uburelease (+143/-9)
To merge this branch: bzr merge lp:~launchpad-baby-gnu/ubumirror/feature-set-config-and-log-files-from-command-line
Reviewer Review Type Date Requested Status
Ubumirror Developers Pending
Review via email: mp+279600@code.launchpad.net

Description of the change

My patch add command line options to set the config file and the log file.

This avoid the duplication of the script when we want to mirror several repositories.

To post a comment you must log in.

Unmerged revisions

84. By Daniel Dehennin <email address hidden>

Set config and log files from command line

This enable the use by normal users without any access to “/etc/” or
“/var/log/” and the mirroring of several debian-like repositories, for
example:

    ./ubuarchive --conf ~/mirror1.conf --log ~/log/mirror1-archive.log
    ./ubucdimage --conf ~/mirror1.conf --log ~/log/mirror1-cdimage.log

    ./uburelease --conf ~/mirror2.conf --log ~/log/mirror2-release.log
    ./ubucdimage --conf ~/mirror2.conf --log ~/log/mirror2-cdimage.log

Here are the options common to all tools:

    -c, --conf <filename> Use the configuration file ”<filename>”.
                            Default: “/etc/ubumirror.conf"
    -l, --log <filename> Write log to file “<filename>”.
                            Default: “/etc/ubumirror.conf"
    -h, --help Show this message
    -v, --version Display version and copyright information
        --copyright Display copyright information
        --license Display license information
        --changes Display ChangeLog information

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'ubuarchive'
2--- ubuarchive 2014-06-08 05:58:41 +0000
3+++ ubuarchive 2015-12-04 13:54:55 +0000
4@@ -19,23 +19,157 @@
5 # along with this program. If not, see <http://www.gnu.org/licenses/>.
6 #
7
8+#------------------------------------------------------------------------
9+# Changes:
10+# 0.3ubuntu3 Manage command line options
11+
12+#------------------------------------------------------------------------
13+# Usage: ubuarchive [OPTION... ]
14+#
15+# Provides an easy way to sync packages from an Ubuntu archive mirror.
16+#
17+# Options:
18+# --------
19+#
20+# -c, --conf <filename> Use the configuration file ”<filename>”.
21+# Default: “/etc/ubumirror.conf"
22+# -l, --log <filename> Write log to file “<filename>”.
23+# Default: “/etc/ubumirror.conf"
24+# -h, --help Show this message
25+# -v, --version Display version and copyright information
26+# --copyright Display copyright information
27+# --license Display license information
28+# --changes Display ChangeLog information
29+#
30+# Mandatory dependencies:
31+# -----------------------
32+# * rsync
33+# * “sh” like shell
34+# * getopt
35+# * sed
36+#
37+# Optional dependencies:
38+# ----------------------
39+# None
40+#
41+# Bugs:
42+# ----
43+# Report bug to https://bugs.launchpad.net/ubuntu/+source/ubumirror
44+
45 set -e
46
47-if [ ! -f /etc/ubumirror.conf ]; then
48- echo "Configuration file /etc/ubumirror.conf not found."
49- exit 2
50-fi
51-
52-. /etc/ubumirror.conf
53-
54-LOGFILE="$LOGDIR/ubuarchive.log"
55+SELF_PATH=$(readlink -e "${0}")
56+SELF=$(basename "${SELF_PATH}")
57+
58+usage() {
59+ sed -n '/^# Usage/,/^$/ {s/^#[[:space:]]\?//p}' "${SELF_PATH}"
60+}
61+description() {
62+ self_version
63+ echo -n "ubuarchive ${SELF_VERSION} - "
64+ usage | sed -n '/^Usage/,/^Options/{//b; /^$/d; p}'
65+}
66+license() {
67+ description
68+ echo
69+ sed -n '/^#[[:space:]]*Copyright/,/^$/ s/^#[[:space:]]\{0,3\}//p' "${SELF_PATH}"
70+}
71+changes() {
72+ echo 'ubuarchive\n'
73+ sed -n '/^#[[:space:]]*Changes/,/^$/ s/^#[[:space:]]\?//p' "${SELF_PATH}"
74+}
75+self_version() {
76+ [ -z "${SELF_VERSION}" ] || return
77+ SELF_VERSION=$(changes \
78+ | sed -n '/^[[:space:]]\+[0-9.]*/ {s/^[[:space:]]\+\([^[:space:]]\+\).*/\1/p; q}')
79+}
80+
81+#------------------------------------------------------------------------
82+# Global variables:
83+#
84+# Use “export” to make them available to subprocesses
85+#
86+# Default log file
87+CONF=/etc/ubumirror.conf
88+LOGDIR=/var/log/ubumirror
89+LOGFILE="${LOGDIR}/ubuarchive.log"
90+
91+#------------------------------------------------------------------------
92+# Options
93+TEMP=$(getopt -o c:l:hv --long conf:,log:,help,version,copyright,license,changes -- "$@")
94+
95+test $? = 0 || exit 1
96+eval set -- "${TEMP}"
97+
98+while true
99+do
100+ case "${1}" in
101+ # Default options for utilities
102+ -h|--help)
103+ usage
104+ exit 0
105+ ;;
106+ -v|--version)
107+ license | head -n 3
108+ exit 0
109+ ;;
110+ --copyright)
111+ license | head -n +3
112+ exit 0
113+ ;;
114+ --license)
115+ license
116+ exit 0
117+ ;;
118+ --changes)
119+ changes
120+ exit 0
121+ ;;
122+
123+ # Program options
124+ -c|--conf)
125+ CONF="${2}"
126+ shift 2
127+ ;;
128+ -l|--log)
129+ LOGDIR=$(dirname "${2}")
130+ LOGFILE="${2}"
131+ shift 2
132+ ;;
133+ # End of options
134+ --)
135+ shift
136+ break
137+ ;;
138+ *)
139+ echo "Error: unknown argument “${1}”"
140+ exit 1
141+ ;;
142+ esac
143+done
144+
145+if [ ! -f "${CONF}" ]; then
146+ echo "Configuration file “${CONF}” not found."
147+ exit 2
148+fi
149+
150+if [ ! -w "${LOGDIR}" ]; then
151+ echo "Log directory “${LOGDIR}” not writable."
152+ exit 2
153+fi
154+
155+if [ -f "${LOGFILE}" -a ! -w "${LOGFILE}" ]; then
156+ echo "Log file “${LOGFILE}” exists but is not writable."
157+ exit 2
158+fi
159+
160+. ${CONF}
161
162 # Log all activity to file.
163 exec >> $LOGFILE 2>&1
164
165 if [ -z "$UBUARC_DIR" ]; then
166- echo -n "No Ubuntu archive target directory (UBUARC_DIR) set in "
167- echo "/etc/ubumirror.conf."
168+ echo "No Ubuntu archive target directory (UBUARC_DIR) set in “${CONF}”"
169 exit 2
170 fi
171
172
173=== modified file 'ubucdimage'
174--- ubucdimage 2014-08-15 07:45:45 +0000
175+++ ubucdimage 2015-12-04 13:54:55 +0000
176@@ -19,23 +19,157 @@
177 # along with this program. If not, see <http://www.gnu.org/licenses/>.
178 #
179
180+#------------------------------------------------------------------------
181+# Changes:
182+# 0.3ubuntu3 Manage command line options
183+
184+#------------------------------------------------------------------------
185+# Usage: ubucdimage [OPTION... ]
186+#
187+# Provides an easy way to sync daily ISO files from an Ubuntu CD image mirror.
188+#
189+# Options:
190+# --------
191+#
192+# -c, --conf <filename> Use the configuration file ”<filename>”.
193+# Default: “/etc/ubumirror.conf"
194+# -l, --log <filename> Write log to file “<filename>”.
195+# Default: “/etc/ubumirror.conf"
196+# -h, --help Show this message
197+# -v, --version Display version and copyright information
198+# --copyright Display copyright information
199+# --license Display license information
200+# --changes Display ChangeLog information
201+#
202+# Mandatory dependencies:
203+# -----------------------
204+# * rsync
205+# * “sh” like shell
206+# * getopt
207+# * sed
208+#
209+# Optional dependencies:
210+# ----------------------
211+# None
212+#
213+# Bugs:
214+# ----
215+# Report bug to https://bugs.launchpad.net/ubuntu/+source/ubumirror
216+
217 set -e
218
219-if [ ! -f /etc/ubumirror.conf ]; then
220- echo "Configuration file /etc/ubumirror.conf not found."
221- exit 2
222-fi
223-
224-. /etc/ubumirror.conf
225-
226+SELF_PATH=$(readlink -e "${0}")
227+SELF=$(basename "${SELF_PATH}")
228+
229+usage() {
230+ sed -n '/^# Usage/,/^$/ {s/^#[[:space:]]\?//p}' "${SELF_PATH}"
231+}
232+description() {
233+ self_version
234+ echo -n "ubuarchive ${SELF_VERSION} - "
235+ usage | sed -n '/^Usage/,/^Options/{//b; /^$/d; p}'
236+}
237+license() {
238+ description
239+ echo
240+ sed -n '/^#[[:space:]]*Copyright/,/^$/ s/^#[[:space:]]\{0,3\}//p' "${SELF_PATH}"
241+}
242+changes() {
243+ echo 'ubuarchive\n'
244+ sed -n '/^#[[:space:]]*Changes/,/^$/ s/^#[[:space:]]\?//p' "${SELF_PATH}"
245+}
246+self_version() {
247+ [ -z "${SELF_VERSION}" ] || return
248+ SELF_VERSION=$(changes \
249+ | sed -n '/^[[:space:]]\+[0-9.]*/ {s/^[[:space:]]\+\([^[:space:]]\+\).*/\1/p; q}')
250+}
251+
252+#------------------------------------------------------------------------
253+# Global variables:
254+#
255+# Use “export” to make them available to subprocesses
256+#
257+# Default log file
258+CONF=/etc/ubumirror.conf
259+LOGDIR=/var/log/ubumirror
260 LOGFILE="$LOGDIR/ubucdimage.log"
261
262+#------------------------------------------------------------------------
263+# Options
264+TEMP=$(getopt -o c:l:hv --long conf:,log:,help,version,copyright,license,changes -- "$@")
265+
266+test $? = 0 || exit 1
267+eval set -- "${TEMP}"
268+
269+while true
270+do
271+ case "${1}" in
272+ # Default options for utilities
273+ -h|--help)
274+ usage
275+ exit 0
276+ ;;
277+ -v|--version)
278+ license | head -n 3
279+ exit 0
280+ ;;
281+ --copyright)
282+ license | head -n +3
283+ exit 0
284+ ;;
285+ --license)
286+ license
287+ exit 0
288+ ;;
289+ --changes)
290+ changes
291+ exit 0
292+ ;;
293+
294+ # Program options
295+ -c|--conf)
296+ CONF="${2}"
297+ shift 2
298+ ;;
299+ -l|--log)
300+ LOGDIR=$(dirname "${2}")
301+ LOGFILE="${2}"
302+ shift 2
303+ ;;
304+ # End of options
305+ --)
306+ shift
307+ break
308+ ;;
309+ *)
310+ echo "Error: unknown argument “${1}”"
311+ exit 1
312+ ;;
313+ esac
314+done
315+
316+if [ ! -f "${CONF}" ]; then
317+ echo "Configuration file “${CONF}” not found."
318+ exit 2
319+fi
320+
321+if [ ! -w "${LOGDIR}" ]; then
322+ echo "Log directory “${LOGDIR}” not writable."
323+ exit 2
324+fi
325+
326+if [ -f "${LOGFILE}" -a ! -w "${LOGFILE}" ]; then
327+ echo "Log file “${LOGFILE}” exists but is not writable."
328+ exit 2
329+fi
330+
331+. ${CONF}
332+
333 # Log all activity to file.
334 exec >> $LOGFILE 2>&1
335
336 if [ -z "$UBUCDI_DIR" ]; then
337- echo -n "No Ubuntu cdimage target directory (UBUCDI_DIR) set in "
338- echo "/etc/ubumirror.conf."
339+ echo "No Ubuntu cdimage target directory (UBUCDI_DIR) set in “${CONF}”"
340 exit 2
341 fi
342
343
344=== modified file 'ubucloudimage'
345--- ubucloudimage 2014-08-20 23:04:22 +0000
346+++ ubucloudimage 2015-12-04 13:54:55 +0000
347@@ -19,23 +19,158 @@
348 # along with this program. If not, see <http://www.gnu.org/licenses/>.
349 #
350
351+#------------------------------------------------------------------------
352+# Changes:
353+# 0.3ubuntu3 Manage command line options
354+
355+#------------------------------------------------------------------------
356+# Usage: ubucloudimage [OPTION... ]
357+#
358+# Provides an easy way to sync cloud images from an ubuntu cloud-image mirror.
359+#
360+#
361+# Options:
362+# --------
363+#
364+# -c, --conf <filename> Use the configuration file ”<filename>”.
365+# Default: “/etc/ubumirror.conf"
366+# -l, --log <filename> Write log to file “<filename>”.
367+# Default: “/etc/ubumirror.conf"
368+# -h, --help Show this message
369+# -v, --version Display version and copyright information
370+# --copyright Display copyright information
371+# --license Display license information
372+# --changes Display ChangeLog information
373+#
374+# Mandatory dependencies:
375+# -----------------------
376+# * rsync
377+# * “sh” like shell
378+# * getopt
379+# * sed
380+#
381+# Optional dependencies:
382+# ----------------------
383+# None
384+#
385+# Bugs:
386+# ----
387+# Report bug to https://bugs.launchpad.net/ubuntu/+source/ubumirror
388+
389 set -e
390
391-if [ ! -f /etc/ubumirror.conf ]; then
392- echo "Configuration file /etc/ubumirror.conf not found."
393- exit 2
394-fi
395-
396-. /etc/ubumirror.conf
397-
398+SELF_PATH=$(readlink -e "${0}")
399+SELF=$(basename "${SELF_PATH}")
400+
401+usage() {
402+ sed -n '/^# Usage/,/^$/ {s/^#[[:space:]]\?//p}' "${SELF_PATH}"
403+}
404+description() {
405+ self_version
406+ echo -n "ubuarchive ${SELF_VERSION} - "
407+ usage | sed -n '/^Usage/,/^Options/{//b; /^$/d; p}'
408+}
409+license() {
410+ description
411+ echo
412+ sed -n '/^#[[:space:]]*Copyright/,/^$/ s/^#[[:space:]]\{0,3\}//p' "${SELF_PATH}"
413+}
414+changes() {
415+ echo 'ubuarchive\n'
416+ sed -n '/^#[[:space:]]*Changes/,/^$/ s/^#[[:space:]]\?//p' "${SELF_PATH}"
417+}
418+self_version() {
419+ [ -z "${SELF_VERSION}" ] || return
420+ SELF_VERSION=$(changes \
421+ | sed -n '/^[[:space:]]\+[0-9.]*/ {s/^[[:space:]]\+\([^[:space:]]\+\).*/\1/p; q}')
422+}
423+
424+#------------------------------------------------------------------------
425+# Global variables:
426+#
427+# Use “export” to make them available to subprocesses
428+#
429+# Default log file
430+CONF=/etc/ubumirror.conf
431+LOGDIR=/var/log/ubumirror
432 LOGFILE="$LOGDIR/ubucloudimage.log"
433
434+#------------------------------------------------------------------------
435+# Options
436+TEMP=$(getopt -o c:l:hv --long conf:,log:,help,version,copyright,license,changes -- "$@")
437+
438+test $? = 0 || exit 1
439+eval set -- "${TEMP}"
440+
441+while true
442+do
443+ case "${1}" in
444+ # Default options for utilities
445+ -h|--help)
446+ usage
447+ exit 0
448+ ;;
449+ -v|--version)
450+ license | head -n 3
451+ exit 0
452+ ;;
453+ --copyright)
454+ license | head -n +3
455+ exit 0
456+ ;;
457+ --license)
458+ license
459+ exit 0
460+ ;;
461+ --changes)
462+ changes
463+ exit 0
464+ ;;
465+
466+ # Program options
467+ -c|--conf)
468+ CONF="${2}"
469+ shift 2
470+ ;;
471+ -l|--log)
472+ LOGDIR=$(dirname "${2}")
473+ LOGFILE="${2}"
474+ shift 2
475+ ;;
476+ # End of options
477+ --)
478+ shift
479+ break
480+ ;;
481+ *)
482+ echo "Error: unknown argument '${1}'"
483+ exit 1
484+ ;;
485+ esac
486+done
487+
488+if [ ! -f "${CONF}" ]; then
489+ echo "Configuration file “${CONF}” not found."
490+ exit 2
491+fi
492+
493+if [ ! -w "${LOGDIR}" ]; then
494+ echo "Log directory “${LOGDIR}” not writable."
495+ exit 2
496+fi
497+
498+if [ -f "${LOGFILE}" -a ! -w "${LOGFILE}" ]; then
499+ echo "Log file “${LOGFILE}” exists but is not writable."
500+ exit 2
501+fi
502+
503+. ${CONF}
504+
505 # Log all activity to file.
506 exec >> $LOGFILE 2>&1
507
508 if [ -z "$UBUCLOUD_DIR" ]; then
509- echo -n "No Ubuntu cloud-image target directory (UBUCLOUD_DIR) set in "
510- echo "/etc/ubumirror.conf."
511+ echo "No Ubuntu cloud-image target directory (UBUCLOUD_DIR) set in “${CONF}”"
512 exit 2
513 fi
514
515
516=== modified file 'ubuports'
517--- ubuports 2014-06-08 05:58:41 +0000
518+++ ubuports 2015-12-04 13:54:55 +0000
519@@ -19,23 +19,157 @@
520 # along with this program. If not, see <http://www.gnu.org/licenses/>.
521 #
522
523+#------------------------------------------------------------------------
524+# Changes:
525+# 0.3ubuntu3 Manage command line options
526+
527+#------------------------------------------------------------------------
528+# Usage: ubuports [OPTION... ]
529+#
530+# Provides an easy way to sync packages from an Ubuntu ports mirror.
531+#
532+# Options:
533+# --------
534+#
535+# -c, --conf <filename> Use the configuration file ”<filename>”.
536+# Default: “/etc/ubumirror.conf"
537+# -l, --log <filename> Write log to file “<filename>”.
538+# Default: “/etc/ubumirror.conf"
539+# -h, --help Show this message
540+# -v, --version Display version and copyright information
541+# --copyright Display copyright information
542+# --license Display license information
543+# --changes Display ChangeLog information
544+#
545+# Mandatory dependencies:
546+# -----------------------
547+# * rsync
548+# * “sh” like shell
549+# * getopt
550+# * sed
551+#
552+# Optional dependencies:
553+# ----------------------
554+# None
555+#
556+# Bugs:
557+# ----
558+# Report bug to https://bugs.launchpad.net/ubuntu/+source/ubumirror
559+
560 set -e
561
562-if [ ! -f /etc/ubumirror.conf ]; then
563- echo "Configuration file /etc/ubumirror.conf not found."
564- exit 2
565-fi
566-
567-. /etc/ubumirror.conf
568-
569+SELF_PATH=$(readlink -e "${0}")
570+SELF=$(basename "${SELF_PATH}")
571+
572+usage() {
573+ sed -n '/^# Usage/,/^$/ {s/^#[[:space:]]\?//p}' "${SELF_PATH}"
574+}
575+description() {
576+ self_version
577+ echo -n "ubuarchive ${SELF_VERSION} - "
578+ usage | sed -n '/^Usage/,/^Options/{//b; /^$/d; p}'
579+}
580+license() {
581+ description
582+ echo
583+ sed -n '/^#[[:space:]]*Copyright/,/^$/ s/^#[[:space:]]\{0,3\}//p' "${SELF_PATH}"
584+}
585+changes() {
586+ echo 'ubuarchive\n'
587+ sed -n '/^#[[:space:]]*Changes/,/^$/ s/^#[[:space:]]\?//p' "${SELF_PATH}"
588+}
589+self_version() {
590+ [ -z "${SELF_VERSION}" ] || return
591+ SELF_VERSION=$(changes \
592+ | sed -n '/^[[:space:]]\+[0-9.]*/ {s/^[[:space:]]\+\([^[:space:]]\+\).*/\1/p; q}')
593+}
594+
595+#------------------------------------------------------------------------
596+# Global variables:
597+#
598+# Use “export” to make them available to subprocesses
599+#
600+# Default log file
601+CONF=/etc/ubumirror.conf
602+LOGDIR=/var/log/ubumirror
603 LOGFILE="$LOGDIR/ubuports.log"
604
605+#------------------------------------------------------------------------
606+# Options
607+TEMP=$(getopt -o c:l:hv --long conf:,log:,help,version,copyright,license,changes -- "$@")
608+
609+test $? = 0 || exit 1
610+eval set -- "${TEMP}"
611+
612+while true
613+do
614+ case "${1}" in
615+ # Default options for utilities
616+ -h|--help)
617+ usage
618+ exit 0
619+ ;;
620+ -v|--version)
621+ license | head -n 3
622+ exit 0
623+ ;;
624+ --copyright)
625+ license | head -n +3
626+ exit 0
627+ ;;
628+ --license)
629+ license
630+ exit 0
631+ ;;
632+ --changes)
633+ changes
634+ exit 0
635+ ;;
636+
637+ # Program options
638+ -c|--conf)
639+ CONF="${2}"
640+ shift 2
641+ ;;
642+ -l|--log)
643+ LOGDIR=$(dirname "${2}")
644+ LOGFILE="${2}"
645+ shift 2
646+ ;;
647+ # End of options
648+ --)
649+ shift
650+ break
651+ ;;
652+ *)
653+ echo "Error: unknown argument “${1}”"
654+ exit 1
655+ ;;
656+ esac
657+done
658+
659+if [ ! -f "${CONF}" ]; then
660+ echo "Configuration file “${CONF}” not found."
661+ exit 2
662+fi
663+
664+if [ ! -w "${LOGDIR}" ]; then
665+ echo "Log directory “${LOGDIR}” not writable."
666+ exit 2
667+fi
668+
669+if [ -f "${LOGFILE}" -a ! -w "${LOGFILE}" ]; then
670+ echo "Log file “${LOGFILE}” exists but is not writable."
671+ exit 2
672+fi
673+
674+. ${CONF}
675+
676 # Log all activity to file.
677 exec >> $LOGFILE 2>&1
678
679 if [ -z "$UBUPOR_DIR" ]; then
680- echo -n "No Ubuntu ports target directory (UBUPOR_DIR) set in "
681- echo "/etc/ubumirror.conf."
682+ echo "No Ubuntu cloud-image target directory (UBUCLOUD_DIR) set in “${CONF}”"
683 exit 2
684 fi
685
686
687=== modified file 'uburelease'
688--- uburelease 2014-08-18 13:55:44 +0000
689+++ uburelease 2015-12-04 13:54:55 +0000
690@@ -19,23 +19,157 @@
691 # along with this program. If not, see <http://www.gnu.org/licenses/>.
692 #
693
694+#------------------------------------------------------------------------
695+# Changes:
696+# 0.3ubuntu3 Manage command line options
697+
698+#------------------------------------------------------------------------
699+# Usage: uburelease [OPTION... ]
700+#
701+# Provides an easy way to sync official ISO images from an Ubuntu releases mirror.
702+#
703+# Options:
704+# --------
705+#
706+# -c, --conf <filename> Use the configuration file ”<filename>”.
707+# Default: “/etc/ubumirror.conf"
708+# -l, --log <filename> Write log to file “<filename>”.
709+# Default: “/etc/ubumirror.conf"
710+# -h, --help Show this message
711+# -v, --version Display version and copyright information
712+# --copyright Display copyright information
713+# --license Display license information
714+# --changes Display ChangeLog information
715+#
716+# Mandatory dependencies:
717+# -----------------------
718+# * rsync
719+# * “sh” like shell
720+# * getopt
721+# * sed
722+#
723+# Optional dependencies:
724+# ----------------------
725+# None
726+#
727+# Bugs:
728+# ----
729+# Report bug to https://bugs.launchpad.net/ubuntu/+source/ubumirror
730+
731 set -e
732
733-if [ ! -f /etc/ubumirror.conf ]; then
734- echo "File /etc/ubumirror.conf does not exist!"
735- exit 1
736-fi
737-
738-. /etc/ubumirror.conf
739-
740+SELF_PATH=$(readlink -e "${0}")
741+SELF=$(basename "${SELF_PATH}")
742+
743+usage() {
744+ sed -n '/^# Usage/,/^$/ {s/^#[[:space:]]\?//p}' "${SELF_PATH}"
745+}
746+description() {
747+ self_version
748+ echo -n "ubuarchive ${SELF_VERSION} - "
749+ usage | sed -n '/^Usage/,/^Options/{//b; /^$/d; p}'
750+}
751+license() {
752+ description
753+ echo
754+ sed -n '/^#[[:space:]]*Copyright/,/^$/ s/^#[[:space:]]\{0,3\}//p' "${SELF_PATH}"
755+}
756+changes() {
757+ echo 'ubuarchive\n'
758+ sed -n '/^#[[:space:]]*Changes/,/^$/ s/^#[[:space:]]\?//p' "${SELF_PATH}"
759+}
760+self_version() {
761+ [ -z "${SELF_VERSION}" ] || return
762+ SELF_VERSION=$(changes \
763+ | sed -n '/^[[:space:]]\+[0-9.]*/ {s/^[[:space:]]\+\([^[:space:]]\+\).*/\1/p; q}')
764+}
765+
766+#------------------------------------------------------------------------
767+# Global variables:
768+#
769+# Use “export” to make them available to subprocesses
770+#
771+# Default log file
772+CONF=/etc/ubumirror.conf
773+LOGDIR=/var/log/ubumirror
774 LOGFILE="$LOGDIR/uburelease.log"
775
776+#------------------------------------------------------------------------
777+# Options
778+TEMP=$(getopt -o c:l:hv --long conf:,log:,help,version,copyright,license,changes -- "$@")
779+
780+test $? = 0 || exit 1
781+eval set -- "${TEMP}"
782+
783+while true
784+do
785+ case "${1}" in
786+ # Default options for utilities
787+ -h|--help)
788+ usage
789+ exit 0
790+ ;;
791+ -v|--version)
792+ license | head -n 3
793+ exit 0
794+ ;;
795+ --copyright)
796+ license | head -n +3
797+ exit 0
798+ ;;
799+ --license)
800+ license
801+ exit 0
802+ ;;
803+ --changes)
804+ changes
805+ exit 0
806+ ;;
807+
808+ # Program options
809+ -c|--conf)
810+ CONF="${2}"
811+ shift 2
812+ ;;
813+ -l|--log)
814+ LOGDIR=$(dirname "${2}")
815+ LOGFILE="${2}"
816+ shift 2
817+ ;;
818+ # End of options
819+ --)
820+ shift
821+ break
822+ ;;
823+ *)
824+ echo "Error: unknown argument “${1}”"
825+ exit 1
826+ ;;
827+ esac
828+done
829+
830+if [ ! -f "${CONF}" ]; then
831+ echo "Configuration file “${CONF}” not found."
832+ exit 2
833+fi
834+
835+if [ ! -w "${LOGDIR}" ]; then
836+ echo "Log directory “${LOGDIR}” not writable."
837+ exit 2
838+fi
839+
840+if [ -f "${LOGFILE}" -a ! -w "${LOGFILE}" ]; then
841+ echo "Log file “${LOGFILE}” exists but is not writable."
842+ exit 2
843+fi
844+
845+. ${CONF}
846+
847 # Log all activity to file.
848 exec >> $LOGFILE 2>&1
849
850 if [ -z "$UBUREL_DIR" ]; then
851- echo -n "No Ubuntu release target directory (UBUREL_DIR) set in "
852- echo "/etc/ubumirror.conf."
853+ echo "No Ubuntu release target directory (UBUREL_DIR) set in “${CONF}”"
854 exit 2
855 fi
856

Subscribers

People subscribed via source and target branches

to status/vote changes: