-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.sh
executable file
·83 lines (69 loc) · 2.09 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
#!/usr/bin/env bash
_pvem_version() {
echo "v0.1.4"
}
# Check which flags are set
local_flag=false
no_prompt_flag=false
for arg in "$@"; do
if [ "$arg" = "--local" ]; then
local_flag=true
fi
if [ "$arg" = "--no-prompt" ]; then
no_prompt_flag=true
fi
done
# Check if --local flag is set
if [ "$local_flag" = true ]; then
echo "Using local pvem source..."
mkdir -p /tmp/pvem-source
cp pvem.sh /tmp/pvem-source/pvem.sh
cp -r pvem /tmp/pvem-source/pvem
cp -r completions /tmp/pvem-source/completions
else
echo "Using remote pvem source. Downloading from GitHub..."
mkdir -p /tmp
wget -O /tmp/pvem-source.tar.gz -q "https://github.com/lucaspellegrinelli/pvem/archive/refs/tags/$( _pvem_version ).tar.gz"
tar -xf /tmp/pvem-source.tar.gz -C /tmp
mv "/tmp/pvem-$( _pvem_version | sed 's/v//g' )" /tmp/pvem-source
fi
INSTALL_PATH="${HOME}/.pvem"
if [ "$no_prompt_flag" = true ]; then
user_path=""
else
read -rp "Enter installation path [${INSTALL_PATH}]: " user_path
fi
if [ -n "${user_path}" ]; then
INSTALL_PATH="${user_path}"
fi
mkdir -p "${INSTALL_PATH}"
mv /tmp/pvem-source/pvem.sh "${INSTALL_PATH}/pvem.sh"
mkdir -p "${INSTALL_PATH}/pvem"
mv /tmp/pvem-source/pvem/* "${INSTALL_PATH}/pvem"
mkdir -p "${INSTALL_PATH}/completions"
mv /tmp/pvem-source/completions/* "${INSTALL_PATH}/completions"
if [ -f "${HOME}/.bashrc" ]; then
if ! grep -q "source ${INSTALL_PATH}/pvem.sh" "${HOME}/.bashrc"; then
{
echo ""
echo "export PVEM_PATH=${INSTALL_PATH}"
echo "source ${INSTALL_PATH}/pvem.sh"
} >> "${HOME}/.bashrc"
fi
fi
if [ -f "${HOME}/.zshrc" ]; then
if ! grep -q "source ${INSTALL_PATH}/pvem.sh" "${HOME}/.zshrc"; then
{
echo ""
echo "export PVEM_PATH=${INSTALL_PATH}"
echo "source ${INSTALL_PATH}/pvem.sh"
} >> "${HOME}/.zshrc"
fi
fi
if [ -d /tmp/pvem-source ]; then
rm -rf /tmp/pvem-source
fi
if [ -f /tmp/pvem-source.tar.gz ]; then
rm -f /tmp/pvem-source.tar.gz
fi
echo "pvem.sh has been installed to ${INSTALL_PATH}"