之前分享过trilium的本地sh更新方法,适用性有点差,于是我写了一个一键脚本。 github链接不稳定建议使用本地代码。
仅适用于 Linux amd64/arm64 平台。
安装 1 curl -fsSL "https://raw.githubusercontent.com/midormeepo/trilium_bash/main/trilium.sh" | bash -s install
更新 1 curl -fsSL "https://raw.githubusercontent.com/midormeepo/trilium_bash/main/trilium.sh" | bash -s update
卸载 1 curl -fsSL "https://raw.githubusercontent.com/midormeepo/trilium_bash/main/trilium.sh" | bash -s uninstall
#自定义路径 默认安装在 /opt/trilium 中。 自定义安装路径请自行修改代码。
以下是脚本源码:
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 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 #!/bin/bash # INSTALL_PATH='/opt/trilium' VERSION='latest' if [ ! -n "$2" ]; then INSTALL_PATH='/opt/trilium' else if [[ $2 == */ ]]; then INSTALL_PATH=${2%?} else INSTALL_PATH=$2 fi if ! [[ $INSTALL_PATH == */trilium ]]; then INSTALL_PATH="$INSTALL_PATH/trilium" fi fi RED_COLOR='\e[1;31m' GREEN_COLOR='\e[1;32m' YELLOW_COLOR='\e[1;33m' BLUE_COLOR='\e[1;34m' PINK_COLOR='\e[1;35m' SHAN='\e[1;33;5m' RES='\e[0m' clear # Get platform if command -v arch >/dev/null 2>&1; then platform=$(arch) else platform=$(uname -m) fi ARCH="UNKNOWN" if [ "$platform" = "x86_64" ]; then ARCH=amd64 elif [ "$platform" = "aarch64" ]; then ARCH=arm64 fi if [ "$(id -u)" != "0" ]; then echo -e "\r\n${RED_COLOR}出错了,请使用 root 权限重试!${RES}\r\n" 1>&2 exit 1 elif [ "$ARCH" == "UNKNOWN" ]; then echo -e "\r\n${RED_COLOR}出错了${RES},一键安装目前仅支持 x86_64和arm64 平台。" exit 1 elif ! command -v systemctl >/dev/null 2>&1; then echo -e "\r\n${RED_COLOR}出错了${RES},无法确定你当前的 Linux 发行版。\r\n建议手动安装。" exit 1 else if command -v netstat >/dev/null 2>&1; then check_port=$(netstat -lnp | grep 8080 | awk '{print $7}' | awk -F/ '{print $1}') else echo -e "${GREEN_COLOR}端口检查 ...${RES}" if command -v yum >/dev/null 2>&1; then yum install net-tools -y >/dev/null 2>&1 check_port=$(netstat -lnp | grep 8080 | awk '{print $7}' | awk -F/ '{print $1}') else apt-get update >/dev/null 2>&1 apt-get install net-tools -y >/dev/null 2>&1 check_port=$(netstat -lnp | grep 8080 | awk '{print $7}' | awk -F/ '{print $1}') fi fi fi CHECK() { if [ -d "$INSTALL_PATH" ]; then echo "此位置已经安装,请选择其他位置,或使用更新命令" exit 0 fi if [ $check_port ]; then kill -9 $check_port fi if [ ! -d "$INSTALL_PATH/" ]; then mkdir -p $INSTALL_PATH else rm -rf $INSTALL_PATH && mkdir -p $INSTALL_PATH fi } DOWNLOAD(){ cd /opt echo -e "${GREEN_COLOR}下载 trilium $VERSION ...${RES}" release_url=$(curl -s "https://api.github.com/repos/Nriver/trilium-translation/releases/latest" | grep "browser_download_url.*trilium-cn-linux-x64-server.zip" | cut -d : -f 2,3 | tr -d \") curl -L -o trilium.zip $release_url $CURL_BAR; if [ -f "$INSTALL_PATH/trilium.zip" ]; then echo -e "${GREEN_COLOR} 下载成功 ${RES}" else echo -e "${RED_COLOR}下载 trilium 失败!${RES}" exit 1 fi } INSTALL() { # 下载 trilium 程序 DOWNLOAD echo -e "${GREEN_COLOR}解压压缩包 ...${RES}" unzip trilium.zip >/dev/null 2>&1; echo -e "${GREEN_COLOR}正在更新 ...${RES}" sudo mv trilium-linux-x64-server $INSTALL_PATH } INIT() { if [ ! -f "$INSTALL_PATH/trilium.sh" ]; then echo -e "\r\n${RED_COLOR}出错了${RES},当前系统未安装 trilium\r\n" exit 1 fi # 创建 systemd cat >/etc/systemd/system/trilium.service <<EOF [Unit] Description=Trilium Daemon After=syslog.target network.target [Service] Type=simple ExecStart=$INSTALL_PATH/trilium.sh WorkingDirectory=$INSTALL_PATH TimeoutStopSec=20 Restart=always [Install] WantedBy=multi-user.target EOF # 添加开机启动 systemctl daemon-reload systemctl enable trilium >/dev/null 2>&1 } SUCCESS() { clear echo "trilium 安装成功!" echo -e "\r\n访问地址:${GREEN_COLOR}http://YOUR_IP:8080/${RES}\r\n" echo -e "启动服务中" systemctl restart trilium echo echo -e "查看状态:${GREEN_COLOR}systemctl status trilium${RES}" echo -e "启动服务:${GREEN_COLOR}systemctl start trilium${RES}" echo -e "重启服务:${GREEN_COLOR}systemctl restart trilium${RES}" echo -e "停止服务:${GREEN_COLOR}systemctl stop trilium${RES}" echo -e "\r\n温馨提示:如果端口无法正常访问,请检查 \033[36m服务器安全组、本机防火墙、trilium状态\033[0m" echo } UNINSTALL() { echo -e "\r\n${GREEN_COLOR}卸载 trilium ...${RES}\r\n" echo -e "${GREEN_COLOR}停止进程${RES}" systemctl disable trilium >/dev/null 2>&1 systemctl stop trilium >/dev/null 2>&1 echo -e "${GREEN_COLOR}清除残留文件${RES}" rm -rf $INSTALL_PATH /etc/systemd/system/trilium.service rm -f /lib/systemd/system/trilium.service systemctl daemon-reload echo -e "\r\n${GREEN_COLOR}trilium 已在系统中移除!数据库则请自行删除!${RES}\r\n" } UPDATE() { cd /opt if [ ! -d "$INSTALL_PATH" ]; then echo -e "\r\n${RED_COLOR}出错了${RES},当前系统未安装 trilium\r\n" exit 1 else echo echo -e "${GREEN_COLOR}停止 trilium 进程${RES}\r\n" systemctl stop trilium echo -e "${GREEN_COLOR}删除旧版本 ...${RES}" rm -rf trilium >/dev/null 2>&1; DOWNLOAD echo -e "${GREEN_COLOR}解压压缩包 ...${RES}" unzip trilium.zip >/dev/null 2>&1; echo -e "${GREEN_COLOR}正在更新 ...${RES}" sudo mv trilium-linux-x64-server $INSTALL_PATH echo -e "\r\n${GREEN_COLOR}启动 trilium 进程${RES}" systemctl start trilium echo -e "\r\n${GREEN_COLOR}trilium 已更新到最新稳定版!${RES}\r\n" # 删除临时文件 rm -f trilium.zip fi } # CURL 进度显示 if curl --help | grep progress-bar >/dev/null 2>&1; then # $CURL_BAR CURL_BAR="--progress-bar" fi # The temp directory must exist if [ ! -d "/tmp" ]; then mkdir -p /tmp fi # Fuck bt.cn (BT will use chattr to lock the php isolation config) chattr -i -R $INSTALL_PATH >/dev/null 2>&1 if [ "$1" = "uninstall" ]; then UNINSTALL elif [ "$1" = "update" ]; then UPDATE elif [ "$1" = "install" ]; then CHECK INSTALL INIT if [ -f "$INSTALL_PATH" ]; then SUCCESS else echo -e "${RED_COLOR} 安装失败${RES}" fi else echo -e "${RED_COLOR} 错误的命令${RES}" fi