-
Notifications
You must be signed in to change notification settings - Fork 7
/
setup-multi-repo.sh
executable file
·69 lines (55 loc) · 1.93 KB
/
setup-multi-repo.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
63
64
65
66
67
68
69
#!/data/data/com.termux/files/usr/bin/bash
# Arguments:
# $1: local path to git repo (required)
# $2: git branch name (optional, default "main")
# $3: repo name (optional, default extracted repo name, used as a suffix for script names)
GIT_REPO_PATH=$1
GIT_BRANCH_NAME=$2
REPO_NAME=$3
if [[ -z "${GIT_REPO_PATH}" ]]; then
echo -e "Path to local Git repository not provided!\nUsage: $(basename "$0") git-path\nAs an alternative you can also use the interactive setup script: setup-interactive.sh"
exit 1
fi
if [[ -z "${GIT_BRANCH_NAME}" ]]; then
GIT_BRANCH_NAME=main
fi
if [[ -z "${REPO_NAME}" ]]; then
REPO_NAME=$(basename "$GIT_REPO_PATH")
fi
MY_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
###########################################
# First copy the latest version of open-repo.sh to home
cp "$MY_DIR/open-repo.sh" "$HOME/open-repo.sh"
chmod +x "$HOME/open-repo.sh"
# shellcheck source=open-repo.sh
if ! source "$HOME/open-repo.sh" "${GIT_REPO_PATH}"
then
echo "Open repo '${GIT_REPO_PATH}' failed!"
exit 1
fi
if [[ ! $(git branch --list "${GIT_BRANCH_NAME}") ]]; then
echo "Git branch '${GIT_BRANCH_NAME}' does not exist!"
exit 1
fi
# Configure git repository
source "$MY_DIR/configure-git.sh"
# Setup scripts for Termux:Widget and Termux:Tasker
rsync -a --delete "$MY_DIR/scripts/" "$MY_DIR/temp/"
cd "$MY_DIR/temp/" || exit 1
for file in *.sh; do
sed -i "s|\$1|${GIT_REPO_PATH}|g" "$file"
filename=$(basename "$file" .sh)
new_filename="${filename}_${REPO_NAME}.sh"
mv "$file" "$new_filename"
done
mkdir -p "$HOME/.shortcuts"
chmod 700 -R "$HOME/.shortcuts"
rsync -r "$MY_DIR/temp/" "$HOME/.shortcuts/"
chmod +x "$HOME"/.shortcuts/*.sh
mkdir -p "$HOME/.termux/tasker"
chmod 700 -R "$HOME/.termux"
rsync -r "$MY_DIR/temp/" "$HOME/.termux/tasker/"
chmod +x "$HOME"/.termux/tasker/*.sh
cd "$MY_DIR" || exit 1
rm -r "$MY_DIR/temp"
echo "Setup auto-sync of '${REPO_NAME}' was successful! (multi-repo setup)"