summaryrefslogtreecommitdiff
path: root/localcowbuilder-create
diff options
context:
space:
mode:
authorJonas Smedegaard <dr@jones.dk>2008-01-14 19:44:31 +0000
committerJonas Smedegaard <dr@jones.dk>2008-01-14 19:44:31 +0000
commit27524b69887ae4d3af570d5ed5428e16b5f6850e (patch)
treeb31f2ee4402cff74c31430e2e45eb595afbf3662 /localcowbuilder-create
parent65db6323b21b34fc4209d07e6b1e02a0a8c7f2de (diff)
Add ask function. Remove basepath as needed if permitted. Fix exit1 function.
Diffstat (limited to 'localcowbuilder-create')
-rwxr-xr-xlocalcowbuilder-create55
1 files changed, 34 insertions, 21 deletions
diff --git a/localcowbuilder-create b/localcowbuilder-create
index 94264c0..14495d3 100755
--- a/localcowbuilder-create
+++ b/localcowbuilder-create
@@ -4,11 +4,6 @@ set -e
PRG=$(basename "$0")
-exit() {
- echo "ERROR: $1"
- exit 1
-}
-
showhelp() {
cat <<EOF
Usage: $PRG POOL [ DISTRIBUTION [ OTHERMIRROR] ]
@@ -19,6 +14,25 @@ Examples:
EOF
}
+exit1() {
+ echo "ERROR: $1"
+ exit 1
+}
+
+ask() {
+ echo -n "$1 (y/N)? "
+ read response
+ case "$response" in
+ y|Y)
+ :
+ ;;
+ *)
+ return 1
+ ;;
+ esac
+ return
+}
+
if [ $# -eq 0 ]; then
showhelp
exit1 "not enough parameters"
@@ -32,28 +46,27 @@ aptcache="/var/cache/pbuilder/aptcache-$pool/"
buildresult="$HOME/src/pbuild-$pool/"
makepaths=''
-for path in "$basepath" "$aptcache" "$buildresult"; do
+for path in "$aptcache" "$buildresult"; do
if [ ! -d "$path" ]; then
- echo "W: path \"$path\" does not exist"
+ echo "W: Needed path \"$path\" does not exist"
makepaths='yes'
fi
done
if [ "$makepaths" = 'yes' ]; then
- if [ "$force" != 'yes' ]; then
- echo -n 'Create the missing paths (y/N)? '
- read response
- case "$response" in
- y|Y)
- :
- ;;
- *)
- exit1 "Cannot continue without those missing paths"
- ;;
- esac
- fi
+ [ "$force" = 'yes' ] \
+ || ask 'Create the missing path(s)' \
+ || exit1 "Cannot continue without those missing paths"
mkdir -p "$buildresult"
- sudo mkdir -p "$basepath" "$aptcache"
-i
+ sudo mkdir -p "$aptcache"
+fi
+
+if [ -d "$basepath" ]; then
+ echo "W: Needed path \"$path\" already exists"
+ [ "$force" = 'yes' ] \
+ || ask 'Remove the path' \
+ || exit1 "Cannot continue with that path already there"
+ sudo rm -rf "$basepath"
+fi
sudo cowbuilder --create \
--buildresult "$buildresult" \