forked from 0x416e746f6e/.aws
-
Notifications
You must be signed in to change notification settings - Fork 1
/
awsup.sh
62 lines (46 loc) · 1.33 KB
/
awsup.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
60
61
62
#!/usr/bin/env bash
#
# https://github.com/flashbots/awsup
#
#
set -eo pipefail
echo "🆙 Starting awsup..."
TARGET_DIR="${HOME}/.aws"
REPO_URL="https://github.com/flashbots/awsup.git"
DATE=$(date +%Y-%m-%d_%H-%M-%S)
BACKUP_DIR="${TARGET_DIR}/backup-${DATE}"
TEMP_DIR="$( mktemp -d -t awsup-XXX )"
git_check() {
if ! command -v git &> /dev/null; then
echo "🚫 Git is not installed. Please install Git and try again."
exit 1
fi
}
handle_file_backup() {
echo "🔄 Backing up ${TARGET_DIR} to ${BACKUP_DIR}..."
mkdir -p "${BACKUP_DIR}"
# Only backup the files, not subdirectories
for item in "${TARGET_DIR}"/*; do
if [ -f "${item}" ]; then
mv "${item}" "${BACKUP_DIR}"
fi
done
}
handle_installation() {
echo "🔄 Downloading and installing..."
pushd "${TEMP_DIR}" > /dev/null 2>&1
git clone "${REPO_URL}" > /dev/null 2>&1
rm -rf awsup/.git
cp -r awsup/* "${TARGET_DIR}/"
if [[ "$OSTYPE" == "darwin"* ]]; then
sed -i '' "s|/Users/anton/|$HOME/|g" "${TARGET_DIR}/credentials"
else
sed -i "s|/Users/anton/|$HOME/|g" "${TARGET_DIR}/credentials"
fi
popd > /dev/null 2>&1
echo "✅ Installation complete! To finish setup, run:"
echo "✨ . ~/.aws/helper.sh --setup"
}
git_check
handle_file_backup
handle_installation