-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.sh
executable file
·102 lines (93 loc) · 3.12 KB
/
install.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#!/usr/bin/env bash
# install.sh - installation and update script for git_sync
# Author: Abdelaziz Elrashed (@vzool)
# Version: 0.0.2-dev
# Date: 2024-01-12
# URL: https://github.com/vzool/git_sync
# License: MIT
# Check for dependencies and exit if not found
for cmd in curl git sed jq
do
if ! command -v $cmd &> /dev/null
then
echo "[ERROR] `$cmd` command could not be found, please install it!"
exit 1
fi
done
# set destination directory path and local bin
LOCAL_BIN="$HOME/.local/bin"
DST="$HOME/.local/git_sync"
# remove command
if [ "$1" == "remove" ]
then
echo "[INFO] removing git_sync..."
if [ ! -d $DST ]
then
echo "[ERROR] git_sync not found, already removed?"
fi
rm -rf $DST
if [ ! -L $LOCAL_BIN/git_sync ]
then
echo "[ERROR] git_sync symbolic link not found, already removed?"
fi
rm -rf $LOCAL_BIN/git_sync
echo "[INFO] git_sync removed successfully!"
exit 0
fi
# check if destination directory exists, if not, clone the repo
if [ ! -d $DST ]
then
FRESH_INSTALL=true
echo "[INFO] git_sync not found, cloning it..."
git clone https://github.com/vzool/git_sync.git $DST
else
echo "[INFO] git_sync found, updating it..."
cd $DST
git checkout -f
git fetch --all
rm -fr ".git/rebase-merge"
git rebase origin/main
git pull origin main
fi
# create local_bin if not exists
if [ ! -d $LOCAL_BIN ]
then
echo "[INFO] local_bin not found in home directory, creating it..."
mkdir -p $LOCAL_BIN
else
echo "[INFO] local_bin found in home directory, skipping it!"
fi
# check if destination directory is added to environment variables, if not, add it
if [[ ":$PATH:" != *"$LOCAL_BIN"* ]]
then
echo "[INFO] local_bin directory not found in PATH, adding it..."
[ -f "$HOME/.bashrc" ] && echo "export PATH=\"\$PATH:$LOCAL_BIN\"" >> $HOME/.bashrc
[ -f "$HOME/.zshrc" ] && echo "export PATH=\"\$PATH:$LOCAL_BIN\"" >> $HOME/.zshrc
[ -f "$HOME/.profile" ] && echo "export PATH=\"\$PATH:$LOCAL_BIN\"" >> $HOME/.profile
[ -f "$HOME/.bash_profile" ] && echo "export PATH=\"\$PATH:$LOCAL_BIN\"" >> $HOME/.bash_profile && $HOME/.bash_profile
[ -f "$HOME/.config/fish/config.fish" ] && echo "export PATH=\"\$PATH:$LOCAL_BIN\"" >> $HOME/.config/fish/config.fish
[ -f "$HOME/.config/fish/fish.config" ] && echo "export PATH=\"\$PATH:$LOCAL_BIN\"" >> $HOME/.config/fish/fish.config
else
echo "[INFO] local_bin directory found in PATH, skipping it!"
fi
# create symbolic link to git_sync if not exists
if [ ! -L $LOCAL_BIN/git_sync ]
then
echo "[INFO] git_sync symbolic link not found, creating it..."
ln -s $DST/git_sync $LOCAL_BIN/git_sync
else
echo "[INFO] git_sync symbolic link found, skipping it!"
fi
# check git_sync has execution permission, if not, add it
if [ ! -x $DST ]
then
echo "[INFO] git_sync not executable, adding it..."
chmod +x $DST
else
echo "[INFO] git_sync is already an executable file, skipping it!"
fi
# if FRESH_INSTALL is true, then print the installation message
if [ "$FRESH_INSTALL" = true ]
then
echo "[INFO] git_sync installed successfully, please open a new terminal to use it!"
fi