-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdate-repos-script-linux.sh
More file actions
71 lines (57 loc) · 2 KB
/
Copy pathupdate-repos-script-linux.sh
File metadata and controls
71 lines (57 loc) · 2 KB
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
60
61
62
63
64
65
66
67
68
69
70
# Specify the file containing the profiles
file="/Users/itsnotsagar/.aws/config"
# Initialize array to store profile names
profiles=()
# Read each line from the file
while IFS= read -r line; do
# Check if it's a profile line
if [[ $line =~ \[profile\ (.*)\] ]]; then
profiles+=("${BASH_REMATCH[1]}")
fi
done < "$file"
# Print all profile names
echo "Profiles found:"
for profile in "${profiles[@]}"; do
echo "$profile"
done
# Ask the user if they want to update the SSO profile
read -p "Do you want to update the SSO profile? (yes/no) " updateSsoProfile
if [[ $updateSsoProfile == "yes" ]]; then
# Ask the user for which profile they want to login to AWS SSO
read -p "Enter the profile you want to login to AWS SSO with (leave empty to update all profiles): " selectedProfile
if [[ -n $selectedProfile ]]; then
if [[ " ${profiles[@]} " =~ " $selectedProfile " ]]; then
# Run aws sso login command for the selected profile
echo "Logging in to AWS SSO with profile $selectedProfile"
aws sso login --profile "$selectedProfile"
else
echo "Profile $selectedProfile not found"
fi
else
# Run aws sso login command for all profiles
for profile in "${profiles[@]}"; do
echo "Logging in to AWS SSO with profile $profile"
aws sso login --profile "$profile"
done
fi
fi
# Specify the directory containing the repos
dir="/Users/itsnotsagar/REPO"
# Get all subdirectories
directories=$(find "$dir" -type d)
# Function to update a single repo
update_repo() {
directory="$1"
cd "$directory"
# Check if it's a git repository
if [[ -d .git ]]; then
echo "Updating $directory"
# Checkout main branch and pull
git checkout main
git pull
fi
}
# Export the function to make it available to xargs
export -f update_repo
# Update repos in parallel using xargs
echo "$directories" | xargs -I {} -P 4 bash -c 'update_repo "$@"' _ {}