forked from lyrebird-voice-changer/lyrebird
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.sh
executable file
·153 lines (120 loc) · 4.11 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
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
142
143
144
145
146
147
148
149
150
151
152
153
#!/bin/sh
# Lyrebird installer script. If running as root then will install at /usr/local/{bin,share},
# otherwise will install at ~/.local/{bin,share}.
VERSION="1.2.0"
VERBOSE=${VERBOSE:-1}
DRYRUN=${DRYRUN:-0}
# Initial setup
if [ $DRYRUN = 1 ]; then DRYRUN_INFO=" (dryrun)"; fi
ECHO_PREFIX="[lyrebird]$DRYRUN_INFO"
info_echo() {
echo "$ECHO_PREFIX $1"
}
warning_echo() {
echo "[warning]$DRYRUN_INFO $1"
}
verbose_echo() {
if [ $VERBOSE = 1 ]; then
echo "$ECHO_PREFIX $1"
fi
}
if [ "$(id -u)" -eq 0 ]; then
INSTALL_PREFIX="${INSTALL_PREFIX:-/usr/local}"
else
INSTALL_PREFIX="${INSTALL_PREFIX:-$HOME/.local}"
fi
verbose_echo "Installing Lyrebird to prefix: ${INSTALL_PREFIX}"
BIN_PATH="$INSTALL_PREFIX/bin"
SHARE_PATH="$INSTALL_PREFIX/share/lyrebird"
DESKTOP_PATH="$INSTALL_PREFIX/share/applications"
python_version_check() {
PYTHON_VERSION=$(python3 --version | grep -Po '3\.\d+')
PYTHON_MIN_MINOR=7
PYTHON_MINOR=${PYTHON_VERSION#*.}
invalid_python() {
info_echo "Lyrebird requires Python version 3.7 or higher"
}
if [ -z $PYTHON_VERSION ]; then
invalid_python
exit 1
elif [ "$PYTHON_MINOR" -lt "$PYTHON_MIN_MINOR" ]; then
invalid_python
exit 1
fi
}
python_version_check
# Removing previous versions
remove_deprecated_install() {
if [ -d "$1" ] || [ -f "$1" ] ; then
if [ $2 -eq 1 ] && [ "$(id -u)" -ne 0 ]; then
warning_echo "Deprecated install location found, cannot remove without root access: $1"
return
fi
info_echo "Removing old install location: $1"
if [ $DRYRUN != 1 ]; then rm -rf $1; fi
fi
}
remove_deprecated_install "/usr/local/bin/lyrebird/" 1
if [ "$(id -u)" -ne 0 ]; then
remove_deprecated_install "/usr/local/share/applications/Lyrebird.desktop" 1
remove_deprecated_install "/usr/local/share/applications/lyrebird.desktop" 1
fi
if [ -d "/etc/lyrebird/" ]; then
warning_echo "/etc/lyrebird/ is now deprecated, please relocate contents to ~/.config/lyrebird/ and delete"
fi
# Required pip3 modules space separated
REQUIRED_PIP_MODULES="toml"
# Create all of the directories if they don't exist
if [ ! -d "$BIN_PATH" ]; then
verbose_echo "Creating binary path: $BIN_PATH"
if [ $DRYRUN != 1 ]; then
mkdir -p "$BIN_PATH"
chmod -R 755 "$BIN_PATH"
fi
fi
if [ ! -d "$SHARE_PATH" ]; then
verbose_echo "Creating share path: $SHARE_PATH"
if [ $DRYRUN != 1 ]; then
mkdir -p "$SHARE_PATH"
chmod -R 755 "$SHARE_PATH"
fi
fi
if [ ! -d "$DESKTOP_PATH" ]; then
verbose_echo "Creating desktop path: $DESKTOP_PATH"
if [ $DRYRUN != 1 ]; then
mkdir -p "$DESKTOP_PATH"
fi
fi
install_python_modules() {
verbose_echo "Installing Python modules: $REQUIRED_PIP_MODULES"
if [ $DRYRUN != 1 ]; then
# Var not included in quotes so it installs each module
pip3 install --prefix $INSTALL_PREFIX $REQUIRED_PIP_MODULES
fi
}
install_binary_source() {
verbose_echo "Copying app/ to: $SHARE_PATH"
if [ $DRYRUN != 1 ]; then cp -rf app "$SHARE_PATH"; fi
verbose_echo "Copying icon.png to: $SHARE_PATH"
if [ $DRYRUN != 1 ]; then cp icon.png "$SHARE_PATH"; fi
verbose_echo "Copying app.py to: $SHARE_PATH"
if [ $DRYRUN != 1 ]; then cp app.py "$SHARE_PATH"; fi
verbose_echo "Copying lyrebird to: $BIN_PATH"
if [ $DRYRUN != 1 ]; then cp lyrebird "$BIN_PATH/lyrebird"; fi
verbose_echo "Setting permissions 755 recursively for: $SHARE_PATH"
if [ $DRYRUN != 1 ]; then chmod -R 755 "$SHARE_PATH"; fi
}
install_desktop() {
verbose_echo "Copying lyrebird.desktop to: $DESKTOP_PATH"
if [ $DRYRUN != 1 ]; then BIN_PATH=$BIN_PATH SHARE_PATH=$SHARE_PATH envsubst < lyrebird.desktop > $DESKTOP_PATH/lyrebird.desktop; fi
verbose_echo "Setting permission 644 for: $DESKTOP_PATH/lyrebird.desktop"
if [ $DRYRUN != 1 ]; then chmod -R 644 "$DESKTOP_PATH/lyrebird.desktop"; fi
}
verbose_space() { if [ $VERBOSE = 1 ]; then echo; fi }
install_python_modules
verbose_space
install_binary_source
verbose_space
install_desktop
verbose_space
info_echo "Installed Lyrebird v$VERSION"