-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathsetup-single-repo.sh
More file actions
executable file
·74 lines (59 loc) · 2.24 KB
/
Copy pathsetup-single-repo.sh
File metadata and controls
executable file
·74 lines (59 loc) · 2.24 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
71
72
73
74
#!/data/data/com.termux/files/usr/bin/bash
# Arguments:
# $1: local path to git repo (only required, if ~/repo.conf does not exist yet)
# $2: git branch name (optional, default "main")
GIT_REPO_PATH=$1
GIT_BRANCH_NAME=$2
if [[ -z "${GIT_BRANCH_NAME}" ]]; then
GIT_BRANCH_NAME=main
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"
# If repo.conf already exists, try to use it
if [[ -e "$HOME/repo.conf" ]]; then
echo 'Config file '"$HOME"/repo.conf' already exists. Try to use it ...'
if grep -q "GH_REPO" "$HOME/repo.conf"; then
echo 'Warning: File '"$HOME"/repo.conf' is using an outdated format! Consider deleting it ("rm ~/repo.conf") and rerun this script!'
exit 1
fi
# shellcheck source=open-repo.sh
if ! source "$HOME/open-repo.sh"
then
echo "Open repo with path defined in '"$HOME"/repo.conf' failed!"
exit 1
fi
# Otherwise create new config file
elif [[ -n "${GIT_REPO_PATH}" ]]; then
cp "${MY_DIR}/repo.conf.example" "$HOME/repo.conf"
sed -i "s|GIT_REPO_PATH=|GIT_REPO_PATH=${GIT_REPO_PATH}|" "$HOME/repo.conf"
# 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
else
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 [[ ! $(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
mkdir -p "$HOME/.shortcuts"
chmod 700 -R "$HOME/.shortcuts"
rsync -r "$MY_DIR/scripts/" "$HOME/.shortcuts/"
chmod +x "$HOME"/.shortcuts/*.sh
# Setup scripts for Termux:Tasker
mkdir -p "$HOME/.termux/tasker"
chmod 700 -R "$HOME/.termux"
rsync -r "$MY_DIR/scripts/" "$HOME/.termux/tasker/"
chmod +x "$HOME"/.termux/tasker/*.sh
REPO_NAME=$(basename "$GIT_REPO_PATH")
echo "Setup auto-sync of '${REPO_NAME}' was successful! (single-repo setup)"