mirror of
https://github.com/cedar2025/hysteria.git
synced 2025-06-22 12:39:50 +00:00
fix install.sh
This commit is contained in:
parent
c1b380fc56
commit
e69b9b1faa
53
install.sh
53
install.sh
@ -247,50 +247,53 @@ install_hysteria() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
install_startup_service_file() {
|
install_startup_service_file() {
|
||||||
|
useradd -s /sbin/nologin --create-home hysteria
|
||||||
|
[ $? -eq 0 ] && echo "User hysteria has been added."
|
||||||
echo "[Unit]
|
echo "[Unit]
|
||||||
Description=Hysteria, a feature-packed network utility optimized for networks of poor quality
|
Description=Hysteria, a feature-packed network utility optimized for networks of poor quality
|
||||||
Documentation=https://github.com/HyNetwork/hysteria/wiki
|
Documentation=https://github.com/HyNetwork/hysteria/wiki
|
||||||
After=network-online.target nss-lookup.target
|
After=network.target
|
||||||
Wants=network-online.target systemd-networkd-wait-online.service
|
|
||||||
|
|
||||||
[Service]
|
[Service]
|
||||||
User=root
|
User=hysteria
|
||||||
CapabilityBoundingSet=CAP_NET_ADMIN CAP_NET_BIND_SERVICE
|
CapabilityBoundingSet=CAP_NET_BIND_SERVICE CAP_NET_RAW
|
||||||
AmbientCapabilities=CAP_NET_ADMIN CAP_NET_BIND_SERVICE
|
AmbientCapabilities=CAP_NET_BIND_SERVICE CAP_NET_RAW
|
||||||
NoNewPrivileges=true
|
NoNewPrivileges=true
|
||||||
|
WorkingDirectory=/etc/hysteria
|
||||||
|
Environment=HYSTERIA_LOG_LEVEL=info
|
||||||
ExecStart=/usr/local/bin/hysteria -c /etc/hysteria/config.json server
|
ExecStart=/usr/local/bin/hysteria -c /etc/hysteria/config.json server
|
||||||
Restart=on-failure
|
Restart=on-failure
|
||||||
RestartPreventExitStatus=1
|
RestartPreventExitStatus=1
|
||||||
RestartSec=5
|
RestartSec=5
|
||||||
|
|
||||||
[Install]
|
[Install]
|
||||||
WantedBy=multi-user.target" > /lib/systemd/system/hysteria.service
|
WantedBy=multi-user.target" > /lib/systemd/system/hysteria-server.service
|
||||||
echo "[Unit]
|
echo "[Unit]
|
||||||
Description=Hysteria, a feature-packed network utility optimized for networks of poor quality
|
Description=Hysteria, a feature-packed network utility optimized for networks of poor quality
|
||||||
Documentation=https://github.com/HyNetwork/hysteria/wiki
|
Documentation=https://github.com/HyNetwork/hysteria/wiki
|
||||||
After=network-online.target nss-lookup.target
|
After=network.target
|
||||||
Wants=network-online.target systemd-networkd-wait-online.service
|
|
||||||
|
|
||||||
[Service]
|
[Service]
|
||||||
User=root
|
User=hysteria
|
||||||
CapabilityBoundingSet=CAP_NET_ADMIN CAP_NET_BIND_SERVICE
|
CapabilityBoundingSet=CAP_NET_BIND_SERVICE CAP_NET_RAW
|
||||||
AmbientCapabilities=CAP_NET_ADMIN CAP_NET_BIND_SERVICE
|
AmbientCapabilities=CAP_NET_BIND_SERVICE CAP_NET_RAW
|
||||||
NoNewPrivileges=true
|
NoNewPrivileges=true
|
||||||
|
WorkingDirectory=/etc/hysteria
|
||||||
|
Environment=HYSTERIA_LOG_LEVEL=info
|
||||||
ExecStart=/usr/local/bin/hysteria -c /etc/hysteria/%i.json server
|
ExecStart=/usr/local/bin/hysteria -c /etc/hysteria/%i.json server
|
||||||
Restart=on-failure
|
Restart=on-failure
|
||||||
RestartPreventExitStatus=1
|
RestartPreventExitStatus=1
|
||||||
RestartSec=5
|
RestartSec=5
|
||||||
|
|
||||||
|
|
||||||
[Install]
|
[Install]
|
||||||
WantedBy=multi-user.target" > /lib/systemd/system/hysteria@.service
|
WantedBy=multi-user.target" > /lib/systemd/system/hysteria-server@.service
|
||||||
echo "info: Systemd service files have been installed successfully!"
|
echo "info: Systemd service files have been installed successfully!"
|
||||||
systemctl daemon-reload
|
systemctl daemon-reload
|
||||||
SYSTEMD='1'
|
SYSTEMD='1'
|
||||||
}
|
}
|
||||||
|
|
||||||
start_hysteria() {
|
start_hysteria() {
|
||||||
if [[ -f '/lib/systemd/system/hysteria.service' ]]; then
|
if [[ -f '/lib/systemd/system/hysteria-server.service' ]]; then
|
||||||
if systemctl start "${HYSTERIA_CUSTOMIZE:-hysteria}"; then
|
if systemctl start "${HYSTERIA_CUSTOMIZE:-hysteria}"; then
|
||||||
echo 'info: Start the Hystaria service.'
|
echo 'info: Start the Hystaria service.'
|
||||||
else
|
else
|
||||||
@ -301,9 +304,9 @@ start_hysteria() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
stop_hysteria() {
|
stop_hysteria() {
|
||||||
HYSTERIA_CUSTOMIZE="$(systemctl list-units | grep 'hysteria@' | awk -F ' ' '{print $1}')"
|
$HYSTERIA_CUSTOMIZE="$(systemctl list-units | grep 'hysteria@' | awk -F ' ' '{print $1}')"
|
||||||
if [[ -z "$VHYSTERIA_CUSTOMIZE" ]]; then
|
if [[ -z "$VHYSTERIA_CUSTOMIZE" ]]; then
|
||||||
local hysteria_daemon_to_stop='hysteria.service'
|
local hysteria_daemon_to_stop='hysteria-server.service'
|
||||||
else
|
else
|
||||||
local hysteria_daemon_to_stop="$HYSTERIA_CUSTOMIZE"
|
local hysteria_daemon_to_stop="$HYSTERIA_CUSTOMIZE"
|
||||||
fi
|
fi
|
||||||
@ -315,7 +318,7 @@ stop_hysteria() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
check_update() {
|
check_update() {
|
||||||
if [[ -f '/lib/systemd/system/hysteria.service' ]]; then
|
if [[ -f '/lib/systemd/system/hysteria-server.service' ]]; then
|
||||||
get_version
|
get_version
|
||||||
local get_ver_exit_code=$?
|
local get_ver_exit_code=$?
|
||||||
if [[ "$get_ver_exit_code" -eq '0' ]]; then
|
if [[ "$get_ver_exit_code" -eq '0' ]]; then
|
||||||
@ -336,14 +339,14 @@ remove_hysteria() {
|
|||||||
stop_hysteria
|
stop_hysteria
|
||||||
fi
|
fi
|
||||||
if ! ("rm" -r '/usr/local/bin/hysteria' \
|
if ! ("rm" -r '/usr/local/bin/hysteria' \
|
||||||
'/lib/systemd/system/hysteria.service' \
|
'/lib/systemd/system/hysteria-server.service' \
|
||||||
'/lib/systemd/system/hysteria@.service'); then
|
'/lib/systemd/system/hysteria-server@.service'); then
|
||||||
echo 'error: Failed to remove Hysteria.'
|
echo 'error: Failed to remove Hysteria.'
|
||||||
exit 1
|
exit 1
|
||||||
else
|
else
|
||||||
echo 'removed: /usr/local/bin/hysteria'
|
echo 'removed: /usr/local/bin/hysteria'
|
||||||
echo 'removed: /lib/systemd/system/hysteria.service'
|
echo 'removed: /lib/systemd/system/hysteria-server.service'
|
||||||
echo 'removed: /lib/systemd/system/hysteria@.service'
|
echo 'removed: /lib/systemd/system/hysteria-server@.service'
|
||||||
echo 'Please execute the command: systemctl disable hysteria'
|
echo 'Please execute the command: systemctl disable hysteria'
|
||||||
echo 'info: Hysteria has been removed.'
|
echo 'info: Hysteria has been removed.'
|
||||||
echo 'info: If necessary, manually delete the configuration and log files.'
|
echo 'info: If necessary, manually delete the configuration and log files.'
|
||||||
@ -364,10 +367,12 @@ show_help() {
|
|||||||
echo ' -c, --check Check if Hysteria can be updated'
|
echo ' -c, --check Check if Hysteria can be updated'
|
||||||
echo ' -f, --force Force installation of the latest version of Hysteria'
|
echo ' -f, --force Force installation of the latest version of Hysteria'
|
||||||
echo ' -h, --help Show help'
|
echo ' -h, --help Show help'
|
||||||
|
echo ' -l, --local Install Hysteria from a local file'
|
||||||
echo ' -p, --proxy Download through a proxy server, e.g., -p http://127.0.0.1:8118 or -p socks5://127.0.0.1:1080'
|
echo ' -p, --proxy Download through a proxy server, e.g., -p http://127.0.0.1:8118 or -p socks5://127.0.0.1:1080'
|
||||||
exit 0
|
exit 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
main() {
|
main() {
|
||||||
check_if_running_as_root
|
check_if_running_as_root
|
||||||
identify_the_operating_system_and_architecture
|
identify_the_operating_system_and_architecture
|
||||||
@ -429,8 +434,8 @@ main() {
|
|||||||
echo "installed: ${JSON_PATH}/config.json"
|
echo "installed: ${JSON_PATH}/config.json"
|
||||||
fi
|
fi
|
||||||
if [[ "$SYSTEMD" -eq '1' ]]; then
|
if [[ "$SYSTEMD" -eq '1' ]]; then
|
||||||
echo 'installed: /lib/systemd/system/hysteria.service'
|
echo 'installed: /lib/systemd/system/hysteria-server.service'
|
||||||
echo 'installed: /lib/systemd/system/hysteria@.service'
|
echo 'installed: /lib/systemd/system/hysteria-server@.service'
|
||||||
fi
|
fi
|
||||||
"rm" -r "$TMP_DIRECTORY"
|
"rm" -r "$TMP_DIRECTORY"
|
||||||
echo "removed: $TMP_DIRECTORY"
|
echo "removed: $TMP_DIRECTORY"
|
||||||
@ -441,7 +446,7 @@ main() {
|
|||||||
if [[ "$HYSTERIA_RUNNING" -eq '1' ]]; then
|
if [[ "$HYSTERIA_RUNNING" -eq '1' ]]; then
|
||||||
start_hysteria
|
start_hysteria
|
||||||
else
|
else
|
||||||
echo 'Please execute the command: systemctl enable hysteria; systemctl start hysteria'
|
echo 'Please execute the command: systemctl enable hysteria-server; systemctl start hysteria-server'
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user