Skip to content

doge-liang/devtools

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 

Repository files navigation

devtools

个人开发与运维辅助脚本集合,主要覆盖 Linux 主机用户管理、Git/GitHub SSH 配置,以及 Windows 开发环境初始化。

这些脚本会修改系统用户、全局 Git 配置、SSH key、JDK/Conda 安装目录等本机状态。执行前请先阅读脚本内容,在测试机或可回滚环境里验证。

目录结构

路径 用途
host-manage/user/ Linux 用户创建、sudo 权限配置脚本
host-manage/git/ Linux/macOS Git 用户信息和 GitHub SSH key 配置脚本
windows-shell/powershell/ Windows PowerShell 开发环境初始化脚本

Linux 主机用户管理

创建用户

sudo bash host-manage/user/create_user.sh -u <用户名> -p <临时密码> [-g <用户组>]

说明:

  • 需要 root 权限。
  • 如果指定用户组且用户组不存在,脚本会先创建用户组。
  • 密码通过命令行传入,可能进入 shell history。建议只传临时密码,登录后立即修改。

添加 sudo 权限

sudo bash host-manage/user/make_sudoer.sh -u <用户名>

说明:

  • 需要 root 权限。
  • 脚本会把用户追加到 sudo 组。

统一入口

sudo bash host-manage/user/user_manage.sh -a create -u <用户名> -p <临时密码> [-g <用户组>]
sudo bash host-manage/user/user_manage.sh -a make_sudoer -u <用户名> -p <任意占位值>

user_manage.sh 当前要求 -p 参数,即使 make_sudoer 动作不实际使用密码,也需要传入占位值。后续可以把这个入口脚本改成按 action 校验参数。

Git 与 GitHub SSH

配置 Git 用户信息

bash host-manage/git/github_config.sh

脚本会交互式读取 GitHub 用户名和邮箱,并写入:

git config --global user.name
git config --global user.email

配置 GitHub SSH key

bash host-manage/git/install_github_ssh.sh

脚本会:

  • 接收 GitHub 仓库地址和 key 名称。
  • 把 HTTPS 仓库地址转换为 SSH 格式。
  • 生成或复用 ~/.ssh/<key_name>
  • 输出公钥并尝试复制到剪贴板。
  • 打开 GitHub SSH key 设置页。
  • 写入 ~/.ssh/config
  • 测试 SSH 连接。

执行前建议备份:

cp ~/.ssh/config ~/.ssh/config.bak.$(date +%Y%m%d%H%M%S)

Windows PowerShell 脚本

安装 Miniconda

powershell -ExecutionPolicy Bypass -File windows-shell/powershell/install_conda.ps1

脚本会下载 Miniconda Windows 安装包,安装到用户目录,并执行 conda init powershell

配置 GitHub SSH key

powershell -ExecutionPolicy Bypass -File windows-shell/powershell/install_github_ssh.ps1 -email <GitHub邮箱>

可选参数:

-keyName id_ed25519
-noPrompt

脚本会生成 SSH key、启动 ssh-agent、把公钥复制到剪贴板,并提示在 GitHub 添加 SSH key。

安装 JDK

powershell -ExecutionPolicy Bypass -File windows-shell/powershell/install_jdk.ps1 -Version 17.0.8 -Vendor "Eclipse Temurin" -SetDefault

常用参数:

-ShowVersions
-ListInstalled
-InstallPath "D:\Java"
-Vendor "Amazon Corretto"

脚本支持 Eclipse Temurin 和 Amazon Corretto 的若干固定版本。后续维护时应定期更新版本和下载地址。

配置 Git 代理

powershell -ExecutionPolicy Bypass -File windows-shell/powershell/setup_git_config.ps1 -httpProxy http://127.0.0.1:7890 -httpsProxy http://127.0.0.1:7890

注意:该脚本会写入全局 Git proxy,并设置固定的全局 Git 用户名和邮箱。执行前请确认这些值符合当前机器用途。

查看或移除代理:

git config --global --get http.proxy
git config --global --get https.proxy
git config --global --unset http.proxy
git config --global --unset https.proxy

安全注意事项

  • 涉及 root、sudo、ssh-agent、~/.ssh/config、全局 Git 配置的脚本,执行前先读脚本。
  • 不要在共享机器上直接运行会写入全局配置的脚本。
  • 不要把长期密码放进命令行参数;命令行参数可能被 history 或进程列表记录。
  • Windows 安装脚本会从公网下载安装包,执行前确认下载来源和版本。
  • 对生产机器,先在临时账号或测试机验证脚本行为。

后续维护建议

  1. 给 Bash 脚本加 set -euo pipefail 和更严格的参数校验。
  2. 把硬编码的 Git 用户信息改成参数或交互输入。
  3. 给会修改系统状态的脚本增加 --dry-run
  4. 增加 CI:Bash 用 shellcheck,PowerShell 用 PSScriptAnalyzer
  5. 为每个脚本补最小 smoke test 或示例执行记录。

About

Some bash script to help me for developing and operating

Topics

Resources

License

Stars

0 stars

Watchers

1 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors