-
Notifications
You must be signed in to change notification settings - Fork 81
/
Copy pathreposado-add-new-products.sh
executable file
·59 lines (53 loc) · 1.23 KB
/
reposado-add-new-products.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/bin/bash
# ======================================
# reposado-add-new-products.sh
#
# Script to add new products to a branch
# ======================================
REPOUTIL="/var/git/reposado/code/repoutil"
function usage () {
echo "Usage: $0 <branch1> <branch2> ..."
exit
}
# We need a branch.
if [ -z $1 ]; then
echo "Missing branch"
usage
exit 1
fi
# Print the products to be added
echo "Getting a list of new products..."
IFS="
"
NEW_PRODUCTS=( $("${REPOUTIL}" --products | grep -e " \[\] \$") )
if [[ ${#NEW_PRODUCTS[@]} -eq 0 ]]; then
echo "No new products"
exit 0
fi
for (( i=0; i<${#NEW_PRODUCTS[@]}; i++ )); do
echo ${NEW_PRODUCTS[$i]}
done
unset IFS
echo ""
# Ask for confirmation
while true; do
if [ $# -gt 1 ]; then
read -p "Add products to catalog $1? [y]n: " yn
else
read -p "Add products to catalogs: $*? [y]n: " yn
fi
case $yn in
[Yy]* )
NEW_PRODUCT_IDS=( $("${REPOUTIL}" --products | grep -e " \[\] \$" | awk '{print $1}') )
while [ "$1" != "" ]; do
echo "$REPOUTIL --add-products ${NEW_PRODUCT_IDS[@]} $1"
#"${REPOUTIL}" --add-products ${NEW_PRODUCT_IDS[@]} $1
echo ""
shift
done
break;;
[Nn]* )
exit;;
* ) echo "Please answer yes or no.";;
esac
done