-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinstall.sh
executable file
·111 lines (94 loc) · 2.66 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
103
104
105
106
107
108
109
110
111
#!/bin/bash
UNINSTALL=0
INSTALL_MODE=git
# Parse command line arguments
for arg in "$@"; do
case $arg in
-h | --help)
echo "Usage: ./install.sh [OPTIONS]"
echo "Options:"
echo " -h, --help Display this help message"
echo " -u, --uninstall Uninstall the package"
echo " -e, --editable Install the package in editable mode from the current directory"
exit 0
;;
-u | --uninstall)
UNINSTALL=1
shift
;;
-e | --editable)
INSTALL_MODE=editable
shift
;;
-l | --local)
INSTALL_MODE=local
shift
;;
esac
done
# Create a directory for the installation
INSTALL_DIR=$HOME/.local/share/compy
uninstall() {
echo "Uninstalling compy..."
# Remove the installation directory
rm -rf $INSTALL_DIR
# Remove the symbolic link
rm $HOME/.local/bin/compy -f
echo "Uninstallation complete"
}
install() {
mkdir -p $INSTALL_DIR
# Check if python3 is installed
if ! command -v python3 > /dev/null; then
echo "Python3 is not installed"
exit 1
fi
# Check if venv is installed
if ! python3 -m venv --help > /dev/null; then
echo "The venv module is not installed"
exit 1
fi
# Check if git is installed
if [ $INSTALL_MODE == "git" ] && ! command -v git > /dev/null; then
echo "Git is not installed"
exit 1
fi
echo "Installing compy..."
# Create a virtual environment
python3 -m venv $INSTALL_DIR > /dev/null
# Install the package
case $INSTALL_MODE in
git)
$INSTALL_DIR/bin/pip install git+https://github.com/Etto48/compy > /dev/null
;;
local)
$INSTALL_DIR/bin/pip install . > /dev/null
;;
editable)
$INSTALL_DIR/bin/pip install -e . > /dev/null
;;
esac
# Create a symbolic link to the executable
mkdir -p $HOME/.local/bin
SCRIPT_PATH=$INSTALL_DIR/bin/compy
ln -fs $SCRIPT_PATH $HOME/.local/bin/compy
# check if .local/bin is in PATH
if [[ ":$PATH:" == *":$HOME/.local/bin:"* ]]; then
echo "~/.local/bin is already in PATH"
else
if [[ "$SHELL" == "/bin/zsh" ]]; then
echo "Add the following line in ~/.zshrc:"
elif [[ "$SHELL" == "/bin/bash" ]]; then
echo "Add the following line in ~/.bashrc:"
else
echo "Add the following line to your shell configuration file:"
fi
echo "export PATH=\$HOME/.local/bin:\$PATH"
fi
echo "Installation complete"
}
if [ $UNINSTALL -eq 1 ]; then
uninstall
else
install
fi