Skip to content

Commit e1a09b5

Browse files
committed
perf: replace /dev/urandom | tr with openssl rand to fix CPU spike
1 parent 38d8723 commit e1a09b5

File tree

3 files changed

+25
-22
lines changed

3 files changed

+25
-22
lines changed

install.sh

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -76,37 +76,38 @@ is_port_in_use() {
7676
install_base() {
7777
case "${release}" in
7878
ubuntu | debian | armbian)
79-
apt-get update && apt-get install -y -q cron curl tar tzdata socat ca-certificates
79+
apt-get update && apt-get install -y -q cron curl tar tzdata socat ca-certificates openssl
8080
;;
8181
fedora | amzn | virtuozzo | rhel | almalinux | rocky | ol)
82-
dnf -y update && dnf install -y -q curl tar tzdata socat ca-certificates
82+
dnf -y update && dnf install -y -q curl tar tzdata socat ca-certificates openssl
8383
;;
8484
centos)
8585
if [[ "${VERSION_ID}" =~ ^7 ]]; then
86-
yum -y update && yum install -y curl tar tzdata socat ca-certificates
86+
yum -y update && yum install -y curl tar tzdata socat ca-certificates openssl
8787
else
88-
dnf -y update && dnf install -y -q curl tar tzdata socat ca-certificates
88+
dnf -y update && dnf install -y -q curl tar tzdata socat ca-certificates openssl
8989
fi
9090
;;
9191
arch | manjaro | parch)
92-
pacman -Syu && pacman -Syu --noconfirm curl tar tzdata socat ca-certificates
92+
pacman -Syu && pacman -Syu --noconfirm curl tar tzdata socat ca-certificates openssl
9393
;;
9494
opensuse-tumbleweed | opensuse-leap)
95-
zypper refresh && zypper -q install -y curl tar timezone socat ca-certificates
95+
zypper refresh && zypper -q install -y curl tar timezone socat ca-certificates openssl
9696
;;
9797
alpine)
98-
apk update && apk add curl tar tzdata socat ca-certificates
98+
apk update && apk add curl tar tzdata socat ca-certificates openssl
9999
;;
100100
*)
101-
apt-get update && apt-get install -y -q curl tar tzdata socat ca-certificates
101+
apt-get update && apt-get install -y -q curl tar tzdata socat ca-certificates openssl
102102
;;
103103
esac
104104
}
105105

106106
gen_random_string() {
107107
local length="$1"
108-
local random_string=$(LC_ALL=C tr -dc 'a-zA-Z0-9' </dev/urandom | fold -w "$length" | head -n 1)
109-
echo "$random_string"
108+
openssl rand -base64 $(( length * 2 )) \
109+
| tr -dc 'a-zA-Z0-9' \
110+
| head -c "$length"
110111
}
111112

112113
install_acme() {

update.sh

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -100,37 +100,38 @@ is_port_in_use() {
100100

101101
gen_random_string() {
102102
local length="$1"
103-
local random_string=$(LC_ALL=C tr -dc 'a-zA-Z0-9' </dev/urandom | fold -w "$length" | head -n 1)
104-
echo "$random_string"
103+
openssl rand -base64 $(( length * 2 )) \
104+
| tr -dc 'a-zA-Z0-9' \
105+
| head -c "$length"
105106
}
106107

107108
install_base() {
108109
echo -e "${green}Updating and install dependency packages...${plain}"
109110
case "${release}" in
110111
ubuntu | debian | armbian)
111-
apt-get update >/dev/null 2>&1 && apt-get install -y -q curl tar tzdata socat >/dev/null 2>&1
112+
apt-get update >/dev/null 2>&1 && apt-get install -y -q curl tar tzdata socat openssl >/dev/null 2>&1
112113
;;
113114
fedora | amzn | virtuozzo | rhel | almalinux | rocky | ol)
114-
dnf -y update >/dev/null 2>&1 && dnf install -y -q curl tar tzdata socat >/dev/null 2>&1
115+
dnf -y update >/dev/null 2>&1 && dnf install -y -q curl tar tzdata socat openssl >/dev/null 2>&1
115116
;;
116117
centos)
117118
if [[ "${VERSION_ID}" =~ ^7 ]]; then
118-
yum -y update >/dev/null 2>&1 && yum install -y -q curl tar tzdata socat >/dev/null 2>&1
119+
yum -y update >/dev/null 2>&1 && yum install -y -q curl tar tzdata socat openssl >/dev/null 2>&1
119120
else
120-
dnf -y update >/dev/null 2>&1 && dnf install -y -q curl tar tzdata socat >/dev/null 2>&1
121+
dnf -y update >/dev/null 2>&1 && dnf install -y -q curl tar tzdata socat openssl >/dev/null 2>&1
121122
fi
122123
;;
123124
arch | manjaro | parch)
124-
pacman -Syu >/dev/null 2>&1 && pacman -Syu --noconfirm curl tar tzdata socat >/dev/null 2>&1
125+
pacman -Syu >/dev/null 2>&1 && pacman -Syu --noconfirm curl tar tzdata socat openssl >/dev/null 2>&1
125126
;;
126127
opensuse-tumbleweed | opensuse-leap)
127-
zypper refresh >/dev/null 2>&1 && zypper -q install -y curl tar timezone socat >/dev/null 2>&1
128+
zypper refresh >/dev/null 2>&1 && zypper -q install -y curl tar timezone socat openssl >/dev/null 2>&1
128129
;;
129130
alpine)
130-
apk update >/dev/null 2>&1 && apk add curl tar tzdata socat >/dev/null 2>&1
131+
apk update >/dev/null 2>&1 && apk add curl tar tzdata socat openssl>/dev/null 2>&1
131132
;;
132133
*)
133-
apt-get update >/dev/null 2>&1 && apt install -y -q curl tar tzdata socat >/dev/null 2>&1
134+
apt-get update >/dev/null 2>&1 && apt install -y -q curl tar tzdata socat openssl >/dev/null 2>&1
134135
;;
135136
esac
136137
}

x-ui.sh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -243,8 +243,9 @@ reset_user() {
243243

244244
gen_random_string() {
245245
local length="$1"
246-
local random_string=$(LC_ALL=C tr -dc 'a-zA-Z0-9' </dev/urandom | fold -w "$length" | head -n 1)
247-
echo "$random_string"
246+
openssl rand -base64 $(( length * 2 )) \
247+
| tr -dc 'a-zA-Z0-9' \
248+
| head -c "$length"
248249
}
249250

250251
reset_webbasepath() {

0 commit comments

Comments
 (0)