-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·55 lines (47 loc) · 2.06 KB
/
install.sh
File metadata and controls
executable file
·55 lines (47 loc) · 2.06 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
#!/bin/bash
set -e # Exit on error
# Ensure the script is run as root
if [ "$(id -u)" -ne 0 ]; then
echo "This script must be run as root. Try: sudo $0"
exit 1
fi
# Get the invoking user
USER_HOME=$(eval echo ~$SUDO_USER)
USER_SHELL=$(getent passwd "$SUDO_USER" | cut -d: -f7)
echo "Building aishell as $SUDO_USER..."
sudo -u "$SUDO_USER" env PATH="$USER_HOME/.cargo/bin:$PATH" cargo build --release
echo "Installing aishell..."
sudo rm -f /usr/local/bin/aishell
mv target/release/aishell /usr/local/bin
echo "Initializing aishell for $SUDO_USER..."
for shell_config in "$USER_HOME/.bashrc" "$USER_HOME/.zshrc"; do
if [ -f "$shell_config" ]; then
if ! grep -q 'eval "$(aishell init' "$shell_config"; then
echo "Adding aishell init to $shell_config"
echo 'eval "$(aishell init bash)"' >> "$shell_config"
echo 'aishell_suggestion() {' >> "$shell_config"
echo ' local suggestion_file="/tmp/aishell_suggestion"' >> "$shell_config"
echo ' if [ -f "$suggestion_file" ]; then' >> "$shell_config"
echo ' fix=$(< "$suggestion_file")' >> "$shell_config"
echo ' rm -f "$suggestion_file"' >> "$shell_config"
echo ' READLINE_LINE="$fix"' >> "$shell_config"
echo ' READLINE_POINT=${#fix}' >> "$shell_config"
echo ' else' >> "$shell_config"
echo ' echo "No suggestion available."' >> "$shell_config"
echo ' fi' >> "$shell_config"
echo '}' >> "$shell_config"
#echo 'bind -x \'"\\C-t":aishell_suggestion\'' >> "$shell_config"
printf "bind -x '\\\"\\\\C-t\\\":aishell_suggestion'\n" >> "$shell_config"
else
echo "aishell already initialized in $shell_config"
fi
fi
done
echo "Reloading shell configuration..."
echo -e "\e[32mTo reload your shell configuration, run:\e[0m"
if [ -f "$USER_HOME/.bashrc" ]; then
echo -e "\e[32msource $USER_HOME/.bashrc\e[0m"
elif [ -f "$USER_HOME/.zshrc" ]; then
echo -e "\e[32msource $USER_HOME/.zshrc\e[0m"
fi
echo "Done."