#!/bin/bash #From https://github.com/spiritLHLS/addzram #Channel: https://t.me/vps_reviews #2023.08.30 utf8_locale=$(locale -a 2>/dev/null | grep -i -m 1 -E "UTF-8|utf8") if [[ -z "$utf8_locale" ]]; then echo "No UTF-8 locale found" else export LC_ALL="$utf8_locale" export LANG="$utf8_locale" export LANGUAGE="$utf8_locale" echo "Locale set to $utf8_locale" fi if [ ! -d /usr/local/bin ]; then mkdir -p /usr/local/bin fi # 自定义字体彩色和其他配置 Green="\033[32m" Font="\033[0m" Red="\033[31m" _red() { echo -e "\033[31m\033[01m$@\033[0m"; } _green() { echo -e "\033[32m\033[01m$@\033[0m"; } _yellow() { echo -e "\033[33m\033[01m$@\033[0m"; } _blue() { echo -e "\033[36m\033[01m$@\033[0m"; } reading() { read -rp "$(_green "$1")" "$2"; } zram_device="/dev/zram0" # 必须以root运行脚本 check_root() { [[ $(id -u) != 0 ]] && _red " The script must be run as root, you can enter sudo -i and then download and run again." && exit 1 } add_zram() { modprobe zram if [ $? -ne 0 ]; then _yellow "Not find zram module, please install it in kernel manually." exit 1 fi if [ -f /sys/block/zram0/comp_algorithm ]; then rm -rf /usr/local/bin/zram_algorithm output=$(cat /sys/block/zram0/comp_algorithm) IFS=' ' read -ra words <<<"$output" for word in "${words[@]}"; do if ! echo "$word" | grep -qE '^[0-9]+$'; then clean_word="${word//[\[\]]/}" echo "$clean_word" >>/usr/local/bin/zram_algorithm fi done fi if ! command -v zramctl >/dev/null; then _yellow "zramctl command not found. Please make sure zramctl is installed." exit 1 fi if ! command -v mkswap >/dev/null || ! command -v swapon >/dev/null; then _yellow "mkswap or swapon command not found. Please make sure these commands are installed." exit 1 fi readarray -t lines