分类 小技巧 下的文章

需求

防止我在梦中惊醒,一怒之下整了这个脚本

实现

  1. 实现锁屏静音🔇,解锁恢复
  2. 锁屏前就是静音状态,则解锁保持静音🔇
  3. 接住AudioDeviceCmdlets模块,运行几乎无压力

代码

把下面代码用自带记事本保存,文件名(包括扩展名)改成 SetupMuteOnLock.ps1 并使用管理员权限运行。

# 需要以管理员权限运行
if (-not ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) {
    Write-Host "请以管理员权限运行此脚本!" -ForegroundColor Red
    Start-Sleep -Seconds 3
    exit
}

Write-Host "正在设置锁屏自动静音功能..." -ForegroundColor Green

# 创建脚本目录
$scriptDir = "$env:USERPROFILE\LockScreenMuteScripts"
if (-not (Test-Path -Path $scriptDir)) {
    New-Item -Path $scriptDir -ItemType Directory | Out-Null
}

# 检查AudioDeviceCmdlets模块是否安装
$moduleInstalled = Get-Module -ListAvailable -Name AudioDeviceCmdlets
if (-not $moduleInstalled) {
    Write-Host "安装AudioDeviceCmdlets模块..." -ForegroundColor Yellow
    Install-Module -Name AudioDeviceCmdlets -Force -Scope CurrentUser
    Write-Host "AudioDeviceCmdlets模块安装成功!" -ForegroundColor Green
}

# 创建静音脚本 (使用VBS包装以隐藏PowerShell窗口)
$mutePath = "$scriptDir\Mute.ps1"
@"
# 保存当前音量状态
Import-Module AudioDeviceCmdlets

# 获取当前状态
`$isMuted = Get-AudioDevice -PlaybackMute

# 保存状态到文件
"`$isMuted" | Out-File -FilePath "$env:USERPROFILE\volume_state.txt" -Force

# 设置静音
Set-AudioDevice -PlaybackMute `$true
"@ | Out-File -FilePath $mutePath -Encoding utf8

# 创建取消静音脚本 (使用VBS包装以隐藏PowerShell窗口)
$unmutePath = "$scriptDir\Unmute.ps1"
@"
# 恢复之前的音量状态
Import-Module AudioDeviceCmdlets

# 读取保存的状态
if (Test-Path -Path "$env:USERPROFILE\volume_state.txt") {
    `$savedState = Get-Content -Path "$env:USERPROFILE\volume_state.txt"
    `$wasMuted = [System.Convert]::ToBoolean(`$savedState)
  
    # 如果之前没有静音,则恢复
    if (-not `$wasMuted) {
        Set-AudioDevice -PlaybackMute `$false
    }
}
"@ | Out-File -FilePath $unmutePath -Encoding utf8

# 创建VBS包装脚本(完全隐藏窗口)
$muteVbsPath = "$scriptDir\Mute.vbs"
@"
Set objShell = CreateObject("Wscript.Shell")
command = "powershell.exe -ExecutionPolicy Bypass -WindowStyle Hidden -NonInteractive -File ""$mutePath"""
objShell.Run command, 0, False
"@ | Out-File -FilePath $muteVbsPath -Encoding ASCII

$unmuteVbsPath = "$scriptDir\Unmute.vbs"
@"
Set objShell = CreateObject("Wscript.Shell")
command = "powershell.exe -ExecutionPolicy Bypass -WindowStyle Hidden -NonInteractive -File ""$unmutePath"""
objShell.Run command, 0, False
"@ | Out-File -FilePath $unmuteVbsPath -Encoding ASCII

# 设置任务计划
$lockTaskName = "LockScreenMute"
$unlockTaskName = "UnlockScreenUnmute"

# 删除已有任务(如果存在)
schtasks /Query /TN $lockTaskName 2>$null
if ($LASTEXITCODE -eq 0) {
    schtasks /Delete /TN $lockTaskName /F | Out-Null
}

schtasks /Query /TN $unlockTaskName 2>$null
if ($LASTEXITCODE -eq 0) {
    schtasks /Delete /TN $unlockTaskName /F | Out-Null
}

# 创建自定义XML触发器(会话锁定)
$xmlTask = @"
<?xml version="1.0" encoding="UTF-16"?>
<Task version="1.4" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">
  <RegistrationInfo>
    <Date>2023-01-01T00:00:00.0000000</Date>
    <Author>$env:USERNAME</Author>
    <Description>锁屏时自动静音</Description>
  </RegistrationInfo>
  <Triggers>
    <SessionStateChangeTrigger>
      <Enabled>true</Enabled>
      <StateChange>SessionLock</StateChange>
    </SessionStateChangeTrigger>
  </Triggers>
  <Principals>
    <Principal id="Author">
      <UserId>$env:USERDOMAIN\$env:USERNAME</UserId>
      <LogonType>InteractiveToken</LogonType>
      <RunLevel>HighestAvailable</RunLevel>
    </Principal>
  </Principals>
  <Settings>
    <MultipleInstancesPolicy>IgnoreNew</MultipleInstancesPolicy>
    <DisallowStartIfOnBatteries>false</DisallowStartIfOnBatteries>
    <StopIfGoingOnBatteries>false</StopIfGoingOnBatteries>
    <AllowHardTerminate>true</AllowHardTerminate>
    <StartWhenAvailable>false</StartWhenAvailable>
    <RunOnlyIfNetworkAvailable>false</RunOnlyIfNetworkAvailable>
    <IdleSettings>
      <StopOnIdleEnd>true</StopOnIdleEnd>
      <RestartOnIdle>false</RestartOnIdle>
    </IdleSettings>
    <AllowStartOnDemand>true</AllowStartOnDemand>
    <Enabled>true</Enabled>
    <Hidden>true</Hidden>
    <RunOnlyIfIdle>false</RunOnlyIfIdle>
    <DisallowStartOnRemoteAppSession>false</DisallowStartOnRemoteAppSession>
    <UseUnifiedSchedulingEngine>true</UseUnifiedSchedulingEngine>
    <WakeToRun>false</WakeToRun>
    <ExecutionTimeLimit>PT72H</ExecutionTimeLimit>
  </Settings>
  <Actions Context="Author">
    <Exec>
      <Command>wscript.exe</Command>
      <Arguments>"$muteVbsPath"</Arguments>
    </Exec>
  </Actions>
</Task>
"@

$xmlPath = "$scriptDir\LockScreenMute.xml"
$xmlTask | Out-File -FilePath $xmlPath -Encoding unicode

# 创建自定义XML触发器(会话解锁)
$xmlUnlockTask = @"
<?xml version="1.0" encoding="UTF-16"?>
<Task version="1.4" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">
  <RegistrationInfo>
    <Date>2023-01-01T00:00:00.0000000</Date>
    <Author>$env:USERNAME</Author>
    <Description>解锁时恢复音量</Description>
  </RegistrationInfo>
  <Triggers>
    <SessionStateChangeTrigger>
      <Enabled>true</Enabled>
      <StateChange>SessionUnlock</StateChange>
    </SessionStateChangeTrigger>
  </Triggers>
  <Principals>
    <Principal id="Author">
      <UserId>$env:USERDOMAIN\$env:USERNAME</UserId>
      <LogonType>InteractiveToken</LogonType>
      <RunLevel>HighestAvailable</RunLevel>
    </Principal>
  </Principals>
  <Settings>
    <MultipleInstancesPolicy>IgnoreNew</MultipleInstancesPolicy>
    <DisallowStartIfOnBatteries>false</DisallowStartIfOnBatteries>
    <StopIfGoingOnBatteries>false</StopIfGoingOnBatteries>
    <AllowHardTerminate>true</AllowHardTerminate>
    <StartWhenAvailable>false</StartWhenAvailable>
    <RunOnlyIfNetworkAvailable>false</RunOnlyIfNetworkAvailable>
    <IdleSettings>
      <StopOnIdleEnd>true</StopOnIdleEnd>
      <RestartOnIdle>false</RestartOnIdle>
    </IdleSettings>
    <AllowStartOnDemand>true</AllowStartOnDemand>
    <Enabled>true</Enabled>
    <Hidden>true</Hidden>
    <RunOnlyIfIdle>false</RunOnlyIfIdle>
    <DisallowStartOnRemoteAppSession>false</DisallowStartOnRemoteAppSession>
    <UseUnifiedSchedulingEngine>true</UseUnifiedSchedulingEngine>
    <WakeToRun>false</WakeToRun>
    <ExecutionTimeLimit>PT72H</ExecutionTimeLimit>
  </Settings>
  <Actions Context="Author">
    <Exec>
      <Command>wscript.exe</Command>
      <Arguments>"$unmuteVbsPath"</Arguments>
    </Exec>
  </Actions>
</Task>
"@

$xmlUnlockPath = "$scriptDir\UnlockScreenUnmute.xml"
$xmlUnlockTask | Out-File -FilePath $xmlUnlockPath -Encoding unicode

# 注册任务
Write-Host "注册任务计划..." -ForegroundColor Yellow
& schtasks.exe /Create /TN $lockTaskName /XML $xmlPath /F
& schtasks.exe /Create /TN $unlockTaskName /XML $xmlUnlockPath /F

# 设置PowerShell执行策略
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser -Force | Out-Null

# 手动测试脚本
Write-Host "`n正在测试静音功能..." -ForegroundColor Yellow
& wscript.exe "$muteVbsPath"
Write-Host "系统已静音,按任意键继续测试..." -ForegroundColor Cyan
$null = $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")

Write-Host "正在测试取消静音功能..." -ForegroundColor Yellow
& wscript.exe "$unmuteVbsPath"
Write-Host "已恢复原音量状态" -ForegroundColor Cyan

Write-Host "`n安装完成!" -ForegroundColor Green
Write-Host "现在当你锁屏时,系统将自动静音,解锁时将恢复原来的音量状态。" -ForegroundColor Cyan
Write-Host "脚本文件位于:$scriptDir" -ForegroundColor Cyan
Write-Host "`n如需卸载,请在任务计划程序中删除名为 '$lockTaskName' 和 '$unlockTaskName' 的任务。" -ForegroundColor Yellow

Write-Host "`n按任意键退出..." -ForegroundColor Gray
$null = $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")

转载:https://github.com/spiritLHLS/one-click-installation-script

前言

所有脚本如需在国内服务器使用,请在链接前加上 https://cdn.spiritlhl.net/确保命令可以下载本仓库的shell脚本执行

目录

一键修复脚本

运行所有一键修复脚本前注意看说明,以及保证服务器无重要数据,运行后造成的一切后果作者不负任何责任,自行评判风险!

一键尝试修复apt源

  • 支持系统:Ubuntu 12+,Debian 6+
  • 修复apt下载包进程意外退出导致的源锁死
  • 修复apt源broken损坏
  • 修复apt源多进程占用锁死
  • 修复apt源公钥缺失
  • 修复替换系统可用的apt源列表,国内用阿里源,国外用官方源
  • 修复本机的Ubuntu系统是EOL非长期维护的版本(奇数或陈旧的偶数版本),将替换为Ubuntu官方的old-releases仓库以支持apt的使用
  • 修复只保证 apt update不会报错,其他命令报错未修复
  • 如若修复后install还有问题,重启服务器解决问题
curl -L https://raw.githubusercontent.com/spiritLHLS/one-click-installation-script/main/repair_scripts/package.sh -o package.sh && chmod +x package.sh && bash package.sh

一键尝试修复系统时间

  • 支持系统:Ubuntu 18+,Debian 8+,centos 7+,Fedora,Almalinux 8.5+
  • 由于系统时间不准确都是未进行时区时间同步造成的,使用chronyd进行时区时间同步后应当解决了问题
curl -L https://raw.githubusercontent.com/spiritLHLS/one-click-installation-script/main/repair_scripts/modify_time.sh -o modify_time.sh && chmod +x modify_time.sh && bash modify_time.sh

一键尝试修复sudo警告

  • 一键尝试修复 sudo: unable to resolve host xxx: Name or service not known警告(爆错)

不要在生产环境上使用该脚本,否则容易造成网络hosts配置错误,配置的host名字不在外网IP上反而在内网IP(127.0.0.1)上

curl -L https://raw.githubusercontent.com/spiritLHLS/one-click-installation-script/main/repair_scripts/check_sudo.sh -o check_sudo.sh && chmod +x check_sudo.sh && bash check_sudo.sh

一键修改系统自带的journal日志记录大小释放系统盘空间

  • 支持系统:Ubuntu 18+,Debian 8+,centos 7+,Fedora,Almalinux 8.5+
  • 1.自定义修改大小,单位为MB,一般500或者1000即可,有的系统日志默认给了5000甚至更多,不是做站啥的没必要

    • 请注意,修改journal目录大小会影响系统日志的记录,因此,在修改journal目录大小之前如果需要之前的日志,建议先备份系统日志到本地
  • 2.自定义修改设置系统日志保留日期时长,超过日期时长的日志将被清除
  • 3.默认修改日志只记录warning等级(无法自定义)
  • 4.以后日志的产生将受到日志文件大小,日志保留时间,日志保留等级的限制
curl -L https://raw.githubusercontent.com/spiritLHLS/one-click-installation-script/main/repair_scripts/resize_journal.sh -o resize_journal.sh && chmod +x resize_journal.sh && bash resize_journal.sh

一键尝试修复网络

该脚本轻易勿要使用,请确保运行时服务器无重要文件或程序,出现运行bug后续可能需要重装系统

一定要在screen中执行该脚本,否则可能导致修改过程中ssh断链接而修改失败卡住最终SSH无法连接!不在screen中执行后果自负!

  • 支持系统:Ubuntu 18+,Debian 8+,centos 7+,Fedora,Almalinux 8.5+
  • 尝试修复nameserver为google源或cloudflare源
  • 尝试修复为IP类型对应的网络优先级(默认IPV4类型,纯V6类型再替换为IPV6类型)
curl -L https://cdn.spiritlhl.workers.dev/https://raw.githubusercontent.com/spiritLHLS/one-click-installation-script/main/repair_scripts/network.sh -o network.sh && chmod +x network.sh && bash network.sh

如果是纯V6的也可以不使用上面脚本的nat64,使用warp添加V4网络

比如:https://gitlab.com/fscarmen/warp

wget -N https://gitlab.com/fscarmen/warp/-/raw/main/menu.sh && bash menu.sh [option] [lisence/url/token]

非纯V6的,带V4切换优先级到IPV4可用以下命令

sudo sed -i 's/.*precedence ::ffff:0:0\/96.*/precedence ::ffff:0:0\/96  100/g' /etc/gai.conf && sudo systemctl restart networking

一键解除进程数限制

curl -L https://raw.githubusercontent.com/spiritLHLS/one-click-installation-script/main/repair_scripts/unlimit.sh -o unlimit.sh && chmod +x unlimit.sh && bash unlimit.sh

一键环境安装脚本

只推荐在新服务器上安装,环境不纯净不保证不出bug

运行所有一键环境安装脚本前注意看说明,以及保证服务器无重要数据,运行后造成的一切后果作者不负任何责任,自行评判风险!

一键安装golang环境

curl -L https://raw.githubusercontent.com/spiritLHLS/one-click-installation-script/main/install_scripts/golang.sh -o golang.sh && chmod +x golang.sh && bash golang.sh

一键安装jupyter环境

  • 本脚本尝试使用Miniconda3安装虚拟环境jupyter-env再进行jupyter和jupyterlab的安装,如若安装机器不纯净勿要轻易使用本脚本!
  • 本脚本为实验性脚本可能会有各种bug,勿要轻易尝试!
  • 验证已支持的系统:

    • Ubuntu 系 - 推荐,脚本自动挂起到后台
    • Debian 系 - 部分可能需要手动挂起到后台,详看脚本运行安装完毕的后续提示
  • 可能支持的系统(未验证):centos 7+,Fedora,Almalinux 8.5+
  • 执行脚本,之前有用本脚本安装过则直接打印设置的登陆信息,没安装过则进行安装再打印信息,如果已安装但未启动则自动启动后再打印信息
  • 如果是初次安装无脑输入y回车即可,按照提示进行操作即可,安装完毕将在后台常驻运行,自动添加常用的安装包通道源
  • 安装完毕后,如果需要在lab中安装第三方库需要在lab中使用terminal并使用conda进行下载而不是pip3下载,这是需要注意的一点
  • 安装过程中有判断是否为中国IP,可选择是否使用中国镜像

原始用途是方便快捷的在按小时计费的超大型服务器上部署python环境进行科学计算,充分利用时间别浪费在构建环境上。

curl -L https://raw.githubusercontent.com/spiritLHLS/one-click-installation-script/main/install_scripts/jupyter.sh -o jupyter.sh && chmod +x jupyter.sh && bash jupyter.sh

一键安装R语言环境

  • 安装前需使用Miniconda3安装虚拟环境jupyter-env,然后进行jupyter和jupyterlab的安装,再然后才能安装本内核
  • 简单的说,需要执行本仓库对应的jupyter安装脚本再运行本脚本安装R语言环境,会自动安装R环境内核和图形设备支持库
  • x11可能需要手动启动一下,执行 sudo /usr/bin/Xorg
  • 可能支持的系统(未验证):centos 7+,Fedora,Almalinux 8.5+
curl -L https://raw.githubusercontent.com/spiritLHLS/one-click-installation-script/main/install_scripts/R.sh -o R.sh && chmod +x R.sh && bash R.sh

一键安装rust环境

  • 支持系统:Ubuntu 18+,Debian 8+,centos 7+,Fedora,Almalinux 8.5+
  • 加载官方脚本安装,前置条件适配系统以及后置条件判断安装的版本
curl -L https://raw.githubusercontent.com/spiritLHLS/one-click-installation-script/main/install_scripts/rust.sh -o rust.sh && chmod +x rust.sh && bash rust.sh

一键安装C环境

  • 一键安装C++环境
  • 支持系统:使用apt或者yum作为包管理器的系统
  • 如果未安装则安装,如果有安装则提示升级
curl -L https://raw.githubusercontent.com/spiritLHLS/one-click-installation-script/main/install_scripts/cplusplus.sh -o cplusplus.sh && chmod +x cplusplus.sh && bash cplusplus.sh

一键安装vnstat环境

  • 支持系统:Ubuntu 18+,Debian 8+,centos 7+,Fedora,Almalinux 8.5+
  • 加载官方文件编译安装,前置条件适配系统以及后置条件判断安装的版本
curl -L https://raw.githubusercontent.com/spiritLHLS/one-click-installation-script/main/install_scripts/vnstat.sh -o vnstat.sh && chmod +x vnstat.sh && bash vnstat.sh

一键升级低版本debian为debian11

  • 支持系统:debian 6+
  • 升级后需要重启系统加载内核,升级过程中需要选择的都无脑按回车即可
  • 升级是一个版本迭代一个版本,所以如果版本低,每执行一次升级一个版本,直至升级到debian11
curl -L https://raw.githubusercontent.com/spiritLHLS/one-click-installation-script/main/install_scripts/todebian11.sh -o todebian11.sh && chmod +x todebian11.sh && bash todebian11.sh

一键升级低版本ubuntu为ubuntu22

  • 支持系统:Ubuntu 16+
  • 升级后需要重启系统加载内核,升级过程中需要选择的都无脑按回车即可
  • 升级是一个版本迭代一个版本,所以如果版本低,每执行一次升级一个版本,直至升级到ubuntu22
curl -L https://raw.githubusercontent.com/spiritLHLS/one-click-installation-script/main/install_scripts/toubuntu22.sh -o toubuntu22.sh && chmod +x toubuntu22.sh && bash toubuntu22.sh

一键安装zipline平台

  • 应该支持的系统:Ubuntu 18+,Debian 8+,centos 7+,Fedora,Almalinux 8.5+
  • 暂时只在Ubuntu上验证无问题
  • 如若要设置反向代理绑定域名,安装前请保证原服务器未安装过nginx,如若已安装过nginx,请自行配置反向代理本机的3000端口
  • 默认一路回车是不启用反代不安装nginx的,自行选择,如需通过本脚本配置反代系统一定要未安装过nginx并在填写y或Y开启安装
  • zipline 平台功能: ShareX,自定义短链接,文件上传分享,多用户校验,高亮显示,阅后即焚,设置简单 (含pastebin)
  • 自动安装docker,docker-compose,如若已安装zipline在/root目录下,则自动更新
  • 反向代理如若已设置成功,还需要在面板设置中填写域名,绑定启用
curl -L https://raw.githubusercontent.com/spiritLHLS/one-click-installation-script/main/install_scripts/zipline.sh -o zipline.sh && chmod +x zipline.sh && bash zipline.sh

如果需要删除0字节文件,打开 /root/zipline文件夹,执行

docker-compose exec zipline yarn scripts:clear-zero-byte

按照提示操作

一键安装filebrowser平台

  • 端口设置为3030了,其他登陆信息详见提示
  • filebrowser平台支持下载上传文件到服务器,批量下载多个文件(自定义压缩格式),构建文件分享链接,设置分享时长
  • 如果本地有启用IPV6优先级可能绑定到V6去了,使用 lsof -i:3030查看绑定情况,切换优先级后再安装就正常了
curl -L https://raw.githubusercontent.com/spiritLHLS/one-click-installation-script/main/install_scripts/filebrowser.sh -o filebrowser.sh && chmod +x filebrowser.sh && bash filebrowser.sh

一键删除平台监控

  • 一键移除大多数云服务器监控
  • 涵盖阿里云、腾讯云、华为云、UCLOUD、甲骨文云、京东云
curl -L https://raw.githubusercontent.com/spiritLHLS/one-click-installation-script/main/install_scripts/dlm.sh -o dlm.sh && chmod +x dlm.sh && bash dlm.sh

部分手动命令

一键开启root登陆并替换密码

bash <(curl -sSL https://raw.githubusercontent.com/fscarmen/tools/main/root.sh) [PASSWORD]

一键屏蔽邮件端口避免被恶意程序使用

iptables -A INPUT -p tcp --dport 25 -j DROP
iptables -A OUTPUT -p tcp --dport 25 -j DROP
/sbin/iptables-save

设置语言包

sudo apt update
sudo apt install -y locales
sudo locale-gen en_US.UTF-8
echo 'LANG=en_US.UTF-8' | sudo tee /etc/default/locale
echo 'LC_ALL=en_US.UTF-8' | sudo tee -a /etc/default/locale
sudo sed -i '/^#.* en_US.UTF-8 /s/^#//' /etc/locale.gen
sudo locale-gen
export LANG=en_US.UTF-8
export LC_ALL=en_US.UTF-8
locale

重新连接SSH或重启服务器以使得设置生效

ubuntu更新源被锁

sudo rm -rf /var/cache/apt/archives/lock
sudo pkill apt
sudo rm /var/lib/dpkg/lock-frontend
sudo rm /var/lib/apt/lists/lock
sudo rm /var/cache/apt/archives/lock
sudo rm /var/lib/dpkg/lock
sudo dpkg --configure -a

然后重启系统

debian缺失公钥

apt-get install debian-keyring debian-archive-keyring -y

ubuntu或debian缺失公钥

后续这块有计划整理为一个一键脚本

sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 公钥

centos换源

sudo cp /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
sudo sed -i 's/^mirrorlist=http/mirrorlist=https/' /etc/yum.repos.d/CentOS-Base.repo

安装gitea

安装时使用这里的方法:

https://gitlab.com/packaging/gitea

但不要设置无人值守自动升级版本,容易升级到一个有BUG的新版本

更改默认配置需要更改文件 /etc/gitea/app.ini

比如设置文件上传无限制

[repository.upload]
ENABLED = true
ALLOWED_TYPES =
FILE_MAX_SIZE = 1024
MAX_FILES = 100

写在 [security]上面,每个模块 []的内容之间间隔一个空行

卸载aapanel

apt install sysv-rc-conf -y && service bt stop && sysv-rc-conf bt off && rm -f /etc/init.d/bt && rm -rf /www/server/panel

查询是什么东西占用硬盘大于100M

find / -type f -size +100M -exec ls -lh {} \;

卸载dns缓存机制避免配置覆写

systemctl stop systemd-resolved
systemctl disable systemd-resolved

安装docker和docker-compose

安装24版本的docker

curl -sSL https://get.docker.com/ | sh

或安装最新版本的docker(都选官方源即可)

bash <(curl -sSL https://linuxmirrors.cn/docker.sh)

安装docker-compose最新版本

curl -L "https://github.com/docker/compose/releases/latest/download/docker-compose-linux-$(uname -m)" -o /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
docker-compose --version

卸载所有docker镜像和容器

docker rm -f $(docker ps -aq); docker rmi $(docker images -aq)

删除累积的docker日志

cd /var/lib/docker/containers/ && for container_id in */; do container_path="/var/lib/docker/containers/${container_id}"; log_file="${container_id%/}-json.log"; rm -rf "${container_path}${log_file}" && echo "已删除 ${container_path}${log_file}"; done

通过docker安装code-server

安装

mkdir -p ~/.config
docker run --restart=always --name code-server -p 0.0.0.0:8886:8080 \
  -v "$HOME/.config:/home/coder/.config" \
  -v "$PWD:/home/coder/project" \
  -u "$(id -u):$(id -g)" \
  -e "DOCKER_USER=$USER" \
  codercom/code-server:latest

新窗口

docker exec code-server cat /root/.config/code-server/config.yaml

curl -fsSL https://code-server.dev/install.sh | sh -s -- --dry-run
sudo systemctl enable --now code-server@root
sed -i '1s/127.0.0.1:8080/0.0.0.0:8536/' ~/.config/code-server/config.yaml
sudo systemctl restart code-server@root
cat .config/code-server/config.yaml

卸载需要

sudo systemctl stop code-server@root
sudo systemctl disable code-server@root
rm -rf ~/.cache/coder
sudo apt remove coder -y

友链

一键测试服务器的融合怪脚本

https://github.com/spiritLHLS/ecs

一键批量开NAT服务器的LXD脚本

https://github.com/spiritLHLS/lxd

一键安装PVE和使用PVE批量开设虚拟机的脚本

https://github.com/spiritLHLS/pve

朋友fscarmen的常用一键工具仓库

https://github.com/fscarmen/tools

[scode type="red" size=""]⚠ 数据安全须知
!!!数据无价!!!
在做转换前需要先备份再操作,操作过程中出现异常,作者不负任何责任![/scode]

1·选择您的数据库:

USE your_database_name;

2.获取所有表的名称并生成ALTER TABLE语句。您可以通过执行以下命令来完成这个步骤:

SELECT CONCAT('ALTER TABLE `', table_name, '` CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;') AS _sql
FROM information_schema.TABLES 
WHERE table_schema = "your_database_name" 
AND table_type = "BASE TABLE";

这个查询会为您的数据库中的每个表生成一个 ALTER TABLE语句。注意将 your_database_name替换成您实际的数据库名称。

将上述查询的结果复制到一个SQL脚本文件中或者直接在MySQL命令行中运行它们。

3.验证您的服务是否正常,返回结果是否在预期内。

安装

Github安装链接

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash

Gitee安装链接(含设定淘宝镜像源,适用中国大陆)

curl -o- https://gitee.com/RubyMetric/nvm-cn/raw/main/install.sh | bash

更新nvm

安装时可能使用旧版的nvm程序,可在安装后执行一次更新命令。

nvm update
上述命令执行时,请确保有权限。

例外操作

可能会遭遇受限权限写入或者需要重载环境等情况,通常执行以下命令可恢复正常。

# 更新权限
chmod +x ~/.nvm/nvm.sh
# 重新加载环境变量
source ~/.bashrc

nvm指令

  1. 查看当前机器安装版本

    nvm ls
  2. 查看可以云端版本

    nvm ls-remote
  3. 安装指定版本Node.js

    nvm install [<version>]
  4. 卸载指定Node.js版本

    nvm uninstall [<version>]
  5. 使用指定Node.js版本

    nvm use [<version>]
  6. 当前使用Node.js版本

    nvm current
  7. 在对应项目中切换不同Node.js版本

在项目中创建项目所需要的版本声明

touch .nvmrc
echo "v18.19.0" >> .nvmrc

在指定目录下使用nvm use即可切换到对应版本

也可以使用其他方式在使用npm时自动辨识项目的版本文件进行切换操作。

NVM命令输出选项

原文

Node Version Manager (v0.39.5)

Note: <version> refers to any version-like string nvm understands. This includes:
  - full or partial version numbers, starting with an optional "v" (0.10, v0.1.2, v1)
  - default (built-in) aliases: node, stable, unstable, iojs, system
  - custom aliases you define with `nvm alias foo`

 Any options that produce colorized output should respect the `--no-colors` option.

Usage:
  nvm --help                                  Show this message
    --no-colors                               Suppress colored output
  nvm --version                               Print out the installed version of nvm
  nvm install [<version>]                     Download and install a <version>. Uses .nvmrc if available and version is omitted.
   The following optional arguments, if provided, must appear directly after `nvm install`:
    -s                                        Skip binary download, install from source only.
    -b                                        Skip source download, install from binary only.
    --reinstall-packages-from=<version>       When installing, reinstall packages installed in <node|iojs|node version number>
    --lts                                     When installing, only select from LTS (long-term support) versions
    --lts=<LTS name>                          When installing, only select from versions for a specific LTS line
    --skip-default-packages                   When installing, skip the default-packages file if it exists
    --latest-npm                              After installing, attempt to upgrade to the latest working npm on the given node version
    --no-progress                             Disable the progress bar on any downloads
    --alias=<name>                            After installing, set the alias specified to the version specified. (same as: nvm alias <name> <version>)
    --default                                 After installing, set default alias to the version specified. (same as: nvm alias default <version>)
  nvm uninstall <version>                     Uninstall a version
  nvm uninstall --lts                         Uninstall using automatic LTS (long-term support) alias `lts/*`, if available.
  nvm uninstall --lts=<LTS name>              Uninstall using automatic alias for provided LTS line, if available.
  nvm use [<version>]                         Modify PATH to use <version>. Uses .nvmrc if available and version is omitted.
   The following optional arguments, if provided, must appear directly after `nvm use`:
    --silent                                  Silences stdout/stderr output
    --lts                                     Uses automatic LTS (long-term support) alias `lts/*`, if available.
    --lts=<LTS name>                          Uses automatic alias for provided LTS line, if available.
  nvm exec [<version>] [<command>]            Run <command> on <version>. Uses .nvmrc if available and version is omitted.
   The following optional arguments, if provided, must appear directly after `nvm exec`:
    --silent                                  Silences stdout/stderr output
    --lts                                     Uses automatic LTS (long-term support) alias `lts/*`, if available.
    --lts=<LTS name>                          Uses automatic alias for provided LTS line, if available.
  nvm run [<version>] [<args>]                Run `node` on <version> with <args> as arguments. Uses .nvmrc if available and version is omitted.
   The following optional arguments, if provided, must appear directly after `nvm run`:
    --silent                                  Silences stdout/stderr output
    --lts                                     Uses automatic LTS (long-term support) alias `lts/*`, if available.
    --lts=<LTS name>                          Uses automatic alias for provided LTS line, if available.
  nvm current                                 Display currently activated version of Node
  nvm ls [<version>]                          List installed versions, matching a given <version> if provided
    --no-colors                               Suppress colored output
    --no-alias                                Suppress `nvm alias` output
  nvm ls-remote [<version>]                   List remote versions available for install, matching a given <version> if provided
    --lts                                     When listing, only show LTS (long-term support) versions
    --lts=<LTS name>                          When listing, only show versions for a specific LTS line
    --no-colors                               Suppress colored output
  nvm version <version>                       Resolve the given description to a single local version
  nvm version-remote <version>                Resolve the given description to a single remote version
    --lts                                     When listing, only select from LTS (long-term support) versions
    --lts=<LTS name>                          When listing, only select from versions for a specific LTS line
  nvm deactivate                              Undo effects of `nvm` on current shell
    --silent                                  Silences stdout/stderr output
  nvm alias [<pattern>]                       Show all aliases beginning with <pattern>
    --no-colors                               Suppress colored output
  nvm alias <name> <version>                  Set an alias named <name> pointing to <version>
  nvm unalias <name>                          Deletes the alias named <name>
  nvm install-latest-npm                      Attempt to upgrade to the latest working `npm` on the current node version
  nvm reinstall-packages <version>            Reinstall global `npm` packages contained in <version> to current version
  nvm unload                                  Unload `nvm` from shell
  nvm which [current | <version>]             Display path to installed node version. Uses .nvmrc if available and version is omitted.
    --silent                                  Silences stdout/stderr output when a version is omitted
  nvm cache dir                               Display path to the cache directory for nvm
  nvm cache clear                             Empty cache directory for nvm
  nvm set-colors [<color codes>]              Set five text colors using format "yMeBg". Available when supported.
                                               Initial colors are:
                                                  bygre
                                               Color codes:
                                                r/R = red / bold red
                                                g/G = green / bold green
                                                b/B = blue / bold blue
                                                c/C = cyan / bold cyan
                                                m/M = magenta / bold magenta
                                                y/Y = yellow / bold yellow
                                                k/K = black / bold black
                                                e/W = light grey / white
Example:
  nvm install 8.0.0                     Install a specific version number
  nvm use 8.0                           Use the latest available 8.0.x release
  nvm run 6.10.3 app.js                 Run app.js using node 6.10.3
  nvm exec 4.8.3 node app.js            Run `node app.js` with the PATH pointing to node 4.8.3
  nvm alias default 8.1.0               Set default node version on a shell
  nvm alias default node                Always default to the latest available node version on a shell

  nvm install node                      Install the latest available version
  nvm use node                          Use the latest version
  nvm install --lts                     Install the latest LTS version
  nvm use --lts                         Use the latest LTS version

  nvm set-colors cgYmW                  Set text colors to cyan, green, bold yellow, magenta, and white

Note:
  to remove, delete, or uninstall nvm - just remove the `$NVM_DIR` folder (usually `~/.nvm`)

译文

个人翻译仅供参考,请以自己实际理解为准。

Node 版本管理器 (v0.39.5)

注意:<version> 指的是 nvm 能理解的任何类似版本的字符串。这包括:
  - 完整或部分版本号,以可选的 "v" 开头(0.10, v0.1.2, v1)
  - 内置的默认别名:node, stable, unstable, iojs, system
  - 你通过 `nvm alias foo` 定义的自定义别名

任何产生彩色输出的选项都应该尊重 `--no-colors` 选项。

用法:
  nvm --help                                  显示此消息
    --no-colors                               抑制彩色输出
  nvm --version                               打印已安装的 nvm 版本
  nvm install [<version>]                     下载并安装一个 <version>。如果省略版本号,则使用 .nvmrc(如果可用)。
   如果提供了以下可选参数,则必须直接出现在 `nvm install` 后:
    -s                                        跳过二进制下载,只从源码安装。
    -b                                        跳过源码下载,只从二进制安装。
    --reinstall-packages-from=<version>       安装时,重新安装在 <node|iojs|node 版本号> 中安装的包
    --lts                                     安装时,只选择长期支持(LTS)版本
    --lts=<LTS 名称>                          安装时,只选择特定 LTS 系列的版本
    --skip-default-packages                   安装时,如果存在默认包文件,则跳过
    --latest-npm                              安装后,尝试升级到给定 node 版本上最新可用的 npm
    --no-progress                             禁用任何下载的进度条
    --alias=<名称>                            安装后,将指定的别名设置为指定的版本。 (与 `nvm alias <名称> <版本>` 相同)
    --default                                 安装后,将默认别名设置为指定的版本。 (与 `nvm alias default <版本>` 相同)
  nvm uninstall <version>                     卸载一个版本
  nvm uninstall --lts                         使用 `lts/*` 的自动 LTS(长期支持)别名进行卸载(如果可用)。
  nvm uninstall --lts=<LTS 名称>              使用提供的 LTS 系列的自动别名进行卸载(如果可用)。
  nvm use [<version>]                         修改 PATH 以使用 <version>。如果省略版本号,则使用 .nvmrc(如果可用)。
   如果提供了以下可选参数,则必须直接出现在 `nvm use` 后:
    --silent                                  静默 stdout/stderr 输出
    --lts                                     使用 `lts/*` 的自动 LTS(长期支持)别名(如果可用)。
    --lts=<LTS 名称>                          使用提供的 LTS 系列的自动别名(如果可用)。
  nvm exec [<version>] [<command>]            在 <version> 上运行 <command>。如果省略版本号,则使用 .nvmrc(如果可用)。
   如果提供了以下可选参数,则必须直接出现在 `nvm exec` 后:
    --silent                                  静默 stdout/stderr 输出
    --lts                                     使用 `lts/*` 的自动 LTS(长期支持)别名(如果可用)。
    --lts=<LTS 名称>                          使用提供的 LTS 系列的自动别名(如果可用)。
  nvm run [<version>] [<args>]                在 <version> 上用 <args> 作为参数运行 `node`。如果省略版本号,则使用 .nvmrc(如果可用)。
   如果提供了以下可选参数,则必须直接出现在 `nvm run` 后:
    --silent                                  静默 stdout/stderr 输出
    --lts                                     使用 `lts/*` 的自动 LTS(长期支持)别名(如果可用)。
    --lts=<LTS 名称>                          使用提供的 LTS系列的自动别名(如果可用)。
  nvm current                                 显示当前激活的 Node 版本
  nvm ls [<version>]                          列出安装的版本,如果提供了 <version> 则匹配给定版本
    --no-colors                               抑制彩色输出
    --no-alias                                抑制 `nvm alias` 输出
  nvm ls-remote [<version>]                   列出可供安装的远程版本,如果提供了 <version> 则匹配给定版本
    --lts                                     列出时,只显示长期支持(LTS)版本
    --lts=<LTS 名称>                          列出时,只显示特定 LTS 系列的版本
    --no-colors                               抑制彩色输出
  nvm version <version>                       将给定描述解析为单个本地版本
  nvm version-remote <version>                将给定描述解析为单个远程版本
    --lts                                     列出时,只从长期支持(LTS)版本中选择
    --lts=<LTS 名称>                          列出时,只从特定 LTS 系列的版本中选择
  nvm deactivate                              撤销 `nvm` 对当前 shell 的影响
    --silent                                  在版本省略时静默 stdout/stderr 输出
  nvm alias [<pattern>]                       显示以 <pattern> 开头的所有别名
    --no-colors                               抑制彩色输出
  nvm alias <name> <version>                  设置一个名为 <name> 的别名,指向 <version>
  nvm unalias <name>                          删除名为 <name> 的别名
  nvm install-latest-npm                      尝试在当前 node 版本上升级到最新可用的 `npm`
  nvm reinstall-packages <version>            将 <version> 中包含的全局 `npm` 包重新安装到当前版本
  nvm unload                                  卸载 shell 中的 `nvm`
  nvm which [current | <version>]             显示安装的 node 版本的路径。如果省略版本号,则使用 .nvmrc(如果可用)。
    --silent                                  当版本省略时静默 stdout/stderr 输出
  nvm cache dir                               显示 nvm 缓存目录的路径
  nvm cache clear                             清空 nvm 的缓存目录
  nvm set-colors [<颜色代码>]                  使用格式 "yMeBg" 设置五种文本颜色。当支持时可用。
                                               初始颜色为:
                                                  bygre
                                               颜色代码:
                                                r/R = 红色 / 加粗红色
                                                g/G = 绿色 / 加粗绿色
                                                b/B = 蓝色 / 加粗蓝色
                                                c/C = 青色 / 加粗青色
                                                m/M = 品红色 / 加粗品红色
                                                y/Y = 黄色 / 加粗黄色
                                                k/K = 黑色 / 加粗黑色
                                                e/W = 浅灰色 / 白色
示例:
  nvm install 8.0.0                     安装特定版本号
  nvm use 8.0                           使用最新可用的 8.0.x 版本
  nvm run 6.10.3 app.js                 使用 node 6.10.3 运行 app.js
  nvm exec 4.8.3 node app.js            用指向 node 4.8.3 的 PATH 运行 `node app.js`
  nvm alias default 8.1.0               在 shell 上设置默认 node 版本
  nvm alias default node                始终默认在 shell 上使用最新可用的 node 版本

  nvm install node                      安装最新可用版本
  nvm use node                          使用最新版本
  nvm install --lts                     安装最新的 LTS 版本
  nvm use --lts                         使用最新的 LTS 版本

  nvm set-colors cgYmW                  将文本颜色设置为青色、绿色、加粗黄色、洋红色和白色

注意:
  要移除、删除或卸载 nvm - 只需删除 `$NVM_DIR` 文件夹(通常在 `~/.nvm`)