-
Notifications
You must be signed in to change notification settings - Fork 3
/
3-apply-to-repos.sh
executable file
·54 lines (46 loc) · 1.87 KB
/
3-apply-to-repos.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
#!/bin/bash
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
. "$SCRIPT_DIR/config/config.ini"
SCOPES_LIST=`cat "$SCRIPT_DIR/config/$REPO_PREFIX-scopes.txt" | tr '\n' ' '`
# Need at least 5 args
if [ $# -le 4 ]
then
echo -e "\nUsage: $0 scope <fork-org> *<target-path>\n"
echo -e "Apply a patch or script in each repo\n"
echo -e "scope: specify a valid scope for \"$REPO_PREFIX\" repos from the list: $SCOPES_LIST"
echo -e "branch-name: the name of the new branch to be created."
echo -e "file-type: patch|script for a patch file or script to be executed as a child process"
echo -e "file-path: the path to the file to be applied to the root of the repo. Will be applied with \"patch -p1 < file-path\" if it's patch file, otherwise as a child process."
echo -e "commit-message: the commit message to use for the patch."
echo -e "target-path: optional argument specifying the path where the clone should be located. If not specified the current directory will be used.\n"
exit 1
fi
SCOPE=$1
BRANCH_NAME=$2
FILE_TYPE=$3
FILE_PATH=$4
COMMIT_MESSAGE=$5
TARGET_PATH=$6
. "$SCRIPT_DIR/helper/functions.sh"
#
# Check all the pre-requisites, if any fail a message will be printed and script will exit
#
check_valid_scope
echo -e "Apply $FILE_TYPE starting for \"$REPO_PREFIX\" repos with scope: $SCOPE\n"
TARGET_PATH=$(get_target_path)
check_target_path_exists
check_valid_file_type
check_valid_file_path
check_any_directories_missing_prior_to_run
#
# Now for every repo start patching!
#
while read line; do
REPO_NAME=`echo $line | awk '{print $1}'`
UPSTREAM_ORG=`echo $line | awk '{print $2}'`
BRANCH=`echo $line | awk '{print $3}'`
if [ "$SCOPE" = "all" ] || [ "$UPSTREAM_ORG" = "$SCOPE" ]
then
"$SCRIPT_DIR/3-apply-to-repo.sh" "$REPO_NAME" "$BRANCH_NAME" "$FILE_TYPE" "$FILE_PATH" "$COMMIT_MESSAGE" "$TARGET_PATH" "multi_run"
fi
done < "$SCRIPT_DIR/config/$REPO_PREFIX-repos.txt"