-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·141 lines (110 loc) · 3.69 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·141 lines (110 loc) · 3.69 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
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
#!/bin/bash
{ # This ensures the entire script is downloaded #
PROGRAM_NAME="ggc"
declare -r GGC_REPO="https://github.com/CamilleCodes/Glamorous-Git-Commits.git"
declare -r XDG_DATA_HOME="${XDG_DATA_HOME:-"$HOME/.local/share"}"
declare -r XDG_CONFIG_HOME="${XDG_CONFIG_HOME:-"$HOME/.config"}"
declare -r BIN_INSTALL_PATH="$HOME/.local/bin"
declare -r GGC_BASE_DIR="${GGC_BASE_DIR:-"$XDG_DATA_HOME/$PROGRAM_NAME"}"
declare -r GGC_COMMIT_FILE="$GGC_BASE_DIR/commit.sh"
declare -r GGC_CONFIG_DIR="${GGC_CONFIG_DIR:-"$XDG_CONFIG_HOME/$PROGRAM_NAME"}"
declare -r GGC_CONFIG_FILE="$GGC_CONFIG_DIR/commit_types.conf"
declare -r GGC_INSTALL_PATH="$BIN_INSTALL_PATH/$PROGRAM_NAME"
function msg() {
local format="\n\t%s\n\n"
local title="$1"
local text="$2"
printf "$title$format" "$text"
}
function conflict_check() {
if [ -f "$GGC_INSTALL_PATH" ]; then
msg "A program with the name '$PROGRAM_NAME' already exists at this path:" "$GGC_INSTALL_PATH"
echo "Installation aborted."
exit 1
fi
if command -v ggc &>/dev/null; then
echo "A program that uses command '$PROGRAM_NAME' already exists."
echo "Installation aborted."
exit 1
fi
}
# Check for required dependencies
function check_system_dependencies() {
# Git & Gum
if ! command -v git &>/dev/null; then
echo "Missing required dependency: Git"
exit 1
fi
if ! command -v gum &>/dev/null; then
echo "Missing required dependency: Gum"
exit 1
fi
}
# Clone repository
function clone_ggc() {
msg "Cloning repository:" "$GGC_REPO"
if [ -d "$GGC_BASE_DIR" ]; then
msg "Directory already exists:" "$GGC_BASE_DIR"
return
fi
if ! git clone "$GGC_REPO" "$GGC_BASE_DIR"; then
echo "Failed to clone repository. Installation failed."
exit 1
fi
}
# Copy commit types default configuration
function copy_config() {
if [ -f "$GGC_CONFIG_FILE" ]; then
# Backup the existing file
msg "Backing up:" "$GGC_CONFIG_FILE"
msg "to:" "$GGC_CONFIG_FILE.bak"
mv "$GGC_CONFIG_FILE" "$GGC_CONFIG_FILE.bak"
fi
[ ! -d "$GGC_CONFIG_DIR" ] && mkdir -p "$GGC_CONFIG_DIR"
cp "$GGC_BASE_DIR/commit_types.conf" "$GGC_CONFIG_DIR"
}
# Add symlink pointing to commit.sh in /local/bin/
function add_symlink() {
[ ! -d "$BIN_INSTALL_PATH" ] && mkdir -p "$BIN_INSTALL_PATH"
chmod u+x "$GGC_COMMIT_FILE"
ln -s "$GGC_COMMIT_FILE" "$GGC_INSTALL_PATH"
}
function verify_installation() {
echo "Verifying installation..."
if [ ! -f "$GGC_CONFIG_FILE" ]; then
echo "Couldn't find $GGC_CONFIG_FILE"
exit 1
fi
if [ ! -f "$GGC_COMMIT_FILE" ]; then
echo "Couldn't find $GGC_COMMIT_FILE"
exit 1
fi
if [ ! -f "$GGC_INSTALL_PATH" ]; then
echo "Couldn't find $GGC_INSTALL_PATH"
exit 1
fi
echo "Installation verified."
}
function print_cat() {
echo ""
echo " __..--''\`\`---....___ _..._ __"
echo " /// //_.-' .-/\"; \` \`\`<._ \`\`.''_ \`. / // /"
echo "///_.-' _..--.'_ \ \`( ) ) // //"
echo "/ (_..-' // (< _ ;_..__ ; \`' / ///"
echo " / // // // \`-._,_)' // / \`\`--...____..-' /// / //"
echo ""
}
function main() {
echo "Beginning Glamorous Git Commits installation..."
conflict_check
check_system_dependencies
clone_ggc
copy_config
add_symlink
verify_installation
print_cat
msg "Program installed at:" "$GGC_INSTALL_PATH"
echo "Installation complete."
}
main
} # This ensures the entire script is downloaded #