-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·83 lines (69 loc) · 2.02 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·83 lines (69 loc) · 2.02 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
#!/bin/bash
UCD_PATH="$1"
if [ -z "$1" ]; then
echo "You need to pass directory of installation as first argument"
exit 2
fi
if [ ! -d "$UCD_PATH" ]; then
echo "Error: '$UCD_PATH' is not recognized as path."
exit 1
fi
SRC_BIN="./_internal_ucd"
if [ -f "${UCD_PATH}_internal_ucd" ]; then
SRC_BIN="${UCD_PATH}_internal_ucd"
fi
# Check if the binary exists, and if not, run the build script
if [ ! -f "$SRC_BIN" ]; then
echo "Binary not found. Attempting to build it..."
if [ -f "./build.sh" ]; then
chmod +x ./build.sh
./build.sh
if [ ! -f "$SRC_BIN" ]; then
echo "Error: Build failed or binary still not found."
exit 3
fi
else
echo "Error: Build script (build.sh) not found."
exit 3
fi
fi
# Detect the shell using the SHELL environment variable
case "$SHELL" in
*/zsh)
SHELL_RC="$HOME/.zshrc"
;;
*/bash)
SHELL_RC="$HOME/.bashrc"
;;
*)
echo "Unsupported shell. Please try manual installation."
exit 4
;;
esac
# Remove existing ucd function and UCD_PATH export from the shell configuration file
sed -i '/^ucd() {/,/^}/d' "$SHELL_RC"
sed -i '/^export UCD_PATH=/d' "$SHELL_RC"
# Move the binary to the target directory
mv "$SRC_BIN" "$UCD_PATH/_internal_ucd"
# Append the new ucd function and UCD_PATH export to the shell configuration file
cat <<EOF >> "$SHELL_RC"
export UCD_PATH="$UCD_PATH";
ucd() {
origin="\$HOME/.local/share/ucd/"
cachePath="\${origin}ucd"
pathPath="\${origin}tmp"
mkdir -p "\$origin"
[ -f "\$cachePath" ] || touch "\$cachePath"
[ -f "\$pathPath" ] || touch "\$pathPath"
"${UCD_PATH}/_internal_ucd" "\$cachePath" "\$pathPath" "\$@"
l=""
if [ -s "\$pathPath" ]; then
l=\$(<"\$pathPath")
if [ -n "\$l" ]; then
cd "\$l" || echo "Failed to cd into \$l"
fi
fi
: > "\$pathPath"
}
EOF
echo "Installation is successful. Please restart your shell or run 'source $SHELL_RC' to apply changes."