fix: merge

This commit is contained in:
2024-11-22 11:20:48 +00:00
26 changed files with 1996 additions and 158 deletions
+34
View File
@@ -0,0 +1,34 @@
#!/bin/bash
# 检查参数数量
if [ "$#" -lt 1 ]; then
echo "Usage: $0 <command> [command_args...]"
exit 1
fi
# 获取 webhook URL
WEBHOOK_URL="https://open.feishu.cn/open-apis/bot/v2/hook/808eafd8-a79f-4af0-b730-8442cf15933b"
# 执行命令并捕获输出
OUTPUT=$("$@" 2>&1)
EXIT_CODE=$?
# 如果命令失败,发送 webhook 通知
if [ $EXIT_CODE -ne 0 ]; then
# 准备 JSON 数据
JSON_DATA=$(cat <<EOF
{
"msg_type": "text",
"content": {
"text": "Cron job fail\n\nCommand: $*\nError: $(echo "$OUTPUT" | sed 's/"/\\"/g')"
}
}
EOF
)
# 发送 webhook
curl -s -X POST -H "Content-Type: application/json" -d "$JSON_DATA" "$WEBHOOK_URL"
fi
# 退出,使用原命令的退出码
exit $EXIT_CODE
+25
View File
@@ -0,0 +1,25 @@
#/bin/bash
set -e
# delete old package
for pkg in docker.io docker-doc docker-compose podman-docker containerd runc; do sudo apt-get remove $pkg; done
# Add Docker's official GPG key:
sudo apt-get update
sudo apt-get install ca-certificates curl
sudo install -m 0755 -d /etc/apt/keyrings
sudo curl -fsSL https://download.docker.com/linux/debian/gpg -o /etc/apt/keyrings/docker.asc
sudo chmod a+r /etc/apt/keyrings/docker.asc
# Add the repository to Apt sources:
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/debian \
$(. /etc/os-release && echo "$VERSION_CODENAME") stable" |
sudo tee /etc/apt/sources.list.d/docker.list >/dev/null
sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
# add to docker group
sudo usermod -aG docker $USER
+3
View File
@@ -6,6 +6,9 @@ if [ -f "$HOME/.config/fish/config.fish" ]; then
fi
ln -s $HOME/.dotfile/fish/config.fish $HOME/.config/fish/config.fish
fish -c "curl -sL https://raw.githubusercontent.com/jorgebucaran/fisher/main/functions/fisher.fish | source && fisher install jorgebucaran/fisher"
fish -c "fisher install jethrokuan/z"
echo 'Set fish as default shell'
fishpath=$(which fish)
echo $fishpath | sudo tee -a /etc/shells
+104
View File
@@ -0,0 +1,104 @@
#!/usr/bin/env python3
import os
import sys
import platform
import subprocess
from typing import Dict, List, Optional
import urllib.request
import zipfile
import shutil
def get_font_dir() -> str:
"""根据操作系统确定字体安装目录"""
system = platform.system()
if system == "Darwin": # macOS
return os.path.expanduser("~/Library/Fonts")
elif system == "Linux":
return os.path.expanduser("~/.local/share/fonts")
else:
raise OSError(f"不支持的操作系统: {system}")
def check_command(command: str) -> bool:
"""检查命令是否存在"""
return shutil.which(command) is not None
def download_file(url: str, dest_path: str) -> None:
"""下载文件到指定路径"""
try:
urllib.request.urlretrieve(url, dest_path)
except Exception as e:
print(f"下载失败: {e}")
sys.exit(1)
def get_top_level_dirs(zip_file: zipfile.ZipFile) -> List[str]:
"""获取 ZIP 文件中的顶级目录"""
return list(set(item.split('/')[0] for item in zip_file.namelist() if '/' in item))
def has_single_top_dir(zip_file: zipfile.ZipFile) -> bool:
"""检查 ZIP 文件是否只有一个顶级目录"""
top_dirs = get_top_level_dirs(zip_file)
return len(top_dirs) == 1 and all(name.startswith(top_dirs[0] + '/') for name in zip_file.namelist())
def unzip_file(zip_path: str, font_name: str) -> None:
"""解压文件到指定路径,根据 ZIP 文件结构决定是否创建顶级目录"""
with zipfile.ZipFile(zip_path, 'r') as zip_ref:
if has_single_top_dir(zip_ref):
# ZIP 文件有单一顶级目录,直接解压
zip_ref.extractall("/tmp")
print(f"已解压 {font_name} 到现有顶级目录")
else:
# 没有单一顶级目录,创建一个以字体名命名的目录
font_dir = os.path.join("/tmp", font_name)
os.makedirs(font_dir, exist_ok=True)
for file in zip_ref.namelist():
if not file.startswith('__MACOSX'): # 排除 macOS 系统文件
zip_ref.extract(file, font_dir)
print(f"已解压 {font_name} 并创建新的顶级目录")
def install_font(font_name: str, font_dir: str) -> None:
"""安装字体到指定目录"""
# find ttf files to copy to the font_dir
ttf_files = [file for file in os.listdir(f"/tmp/{font_name}") if file.endswith(".ttf")]
for ttf_file in ttf_files:
shutil.copy(f"/tmp/{font_name}/{ttf_file}", font_dir)
print(f"已安装 {font_name} 到 {font_dir}")
def refresh_font_cache() -> None:
"""在 Linux 系统上刷新字体缓存"""
if platform.system() == "Linux" and check_command("fc-cache"):
subprocess.run(["fc-cache", "-f"])
print("字体缓存已刷新。")
else:
print("警告:无法刷新字体缓存。您可能需要手动刷新。")
def main() -> None:
fonts: Dict[str, str] = {
"SarasaNerd":"https://github.com/jonz94/Sarasa-Gothic-Nerd-Fonts/releases/download/v1.0.23-0/sarasa-fixed-sc-nerd-font.zip",
"FiraCode": "https://github.com/tonsky/FiraCode/releases/download/6.2/Fira_Code_v6.2.zip"
}
try:
font_dir = get_font_dir()
except OSError as e:
print(str(e))
sys.exit(1)
os.makedirs(font_dir, exist_ok=True)
for font in fonts:
print(f"正在下载和安装 {font}...")
zip_path = f"/tmp/{font}.zip"
download_file(fonts[font], zip_path)
unzip_file(zip_path, font)
install_font(font, font_dir)
os.remove(zip_path)
refresh_font_cache()
print("安装完成。请重启您的终端或应用程序以使用新字体。")
if __name__ == "__main__":
main()
+25
View File
@@ -0,0 +1,25 @@
#!/bin/bash
set -e
# install neovim
os_arch=$(uname -s)-$(uname -m)
case $os_arch in
"Darwin-x86_64")
cd /usr/local
wget https://golang.google.cn/dl/go1.23.2.linux-amd64.tar.gz
tar zxvf go1.23.2.linux-amd64.tar.gz
;;
"Linux-x86_64"|"Linux-arm64")
cd /tmp
rm -rf nvim-linux64.tar.gz
wget https://go.dev/dl/go1.23.2.linux-amd64.tar.gz
tar zxvf go1.23.2.linux-amd64.tar.gz
mv go /usr/local/
sudo ln -s /usr/local/go/bin/go/usr/local/bin/go
;;
esac
-16
View File
@@ -1,16 +0,0 @@
#!bin/sh
#git clone https://github.com/hilaily/.dotfile.git ~/.dotfile
# 判断 zsh 是否安装
#sudo yum update && sudo yum -y install zsh
# 判断 oh-my-zsh 是否安装
if [ ! -d "$HOME/.oh-my-zsh" ];then
export ZSH=$HOME/.oh-my-zsh
sh -c "$(wget https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh -O -)"
fi
ln -sf ~/.dotfile/.zshrc ~/
ln -sf ~/.dotfile/laily.zsh-theme ~/.oh-my-zsh/themes/
ln -sf ~/.dotfile/.tmux.conf ~/
ln -sf ~/.dotfile/git/.gitconfig ~/.gitconfig
+38
View File
@@ -0,0 +1,38 @@
#!/bin/bash
# 定义变量
NVIM_CONFIG_DIR="$HOME/.config/nvim"
YOUR_CUSTOM_CONFIG_DIR="$HOME/.dotfile/nvim" # 请替换为您的自定义配置目录路径
# 检查软链接是否已经存在并指向正确的目录
if [ -L "$NVIM_CONFIG_DIR" ] && [ "$(readlink -f "$NVIM_CONFIG_DIR")" = "$(readlink -f "$YOUR_CUSTOM_CONFIG_DIR")" ]; then
echo "软链接已经存在并指向正确的目录。无需进行任何操作。"
exit 0
fi
# 检查是否存在现有的 Neovim 配置
if [ -e "$NVIM_CONFIG_DIR" ]; then
echo "检测到现有的 Neovim 配置。"
# 如果是目录或常规文件,创建备份
if [ -d "$NVIM_CONFIG_DIR" ] || [ -f "$NVIM_CONFIG_DIR" ]; then
BACKUP_DIR="$NVIM_CONFIG_DIR.backup.$(date +%Y%m%d%H%M%S)"
mv "$NVIM_CONFIG_DIR" "$BACKUP_DIR"
echo "已将现有配置备份到 $BACKUP_DIR"
else
# 如果是其他类型的文件(如损坏的软链接),直接删除
rm "$NVIM_CONFIG_DIR"
echo "已删除现有的无效配置。"
fi
fi
# 创建软链接
ln -s "$YOUR_CUSTOM_CONFIG_DIR" "$NVIM_CONFIG_DIR"
# 检查软链接是否创建成功
if [ -L "$NVIM_CONFIG_DIR" ] && [ "$(readlink -f "$NVIM_CONFIG_DIR")" = "$(readlink -f "$YOUR_CUSTOM_CONFIG_DIR")" ]; then
echo "软链接创建成功。Neovim 现在将使用您的自定义配置。"
else
echo "创建软链接时出错。请检查路径和权限。"
fi
+36 -3
View File
@@ -1,4 +1,37 @@
#!/bin/bash
set -e
# install neovim
cd /usr/local
wget https://github.com/neovim/neovim/releases/download/stable/nvim-macos.tar.gz
tar zxvf nvim-macos.tar.gz
os_arch=$(uname -s)-$(uname -m)
ver=v0.10.2
case $os_arch in
"Darwin-x86_64")
cd /tmp
rm -rf nvim-macos-x86_64.tar.gz
wget https://github.com/neovim/neovim/releases/download/$ver/nvim-macos-x86_64.tar.gz
tar zxf nvim-macos-x86_64.tar.gz
sudo mv -f /usr/local/nvim /usr/local/nvim-bak
sudo mv nvim-macos-x86_64 /usr/local/nvim
sudo ln -sf /usr/local/nvim/bin/nvim /usr/local/bin/vim
sudo ln -sf /usr/local/nvim/bin/nvim /usr/local/bin/nvim
echo ""
vim -v
;;
"Linux-x86_64" | "Linux-arm64")
cd /tmp
rm -rf nvim-linux64.tar.gz
wget https://github.com/neovim/neovim/releases/download/$ver/nvim-linux64.tar.gz
tar zxf nvim-linux64.tar.gz
[ -e /usr/local/nvim ] && sudo mv -f /usr/local/nvim /usr/local/nvim-bak
sudo mv nvim-linux64 /usr/local/nvim
sudo ln -sf /usr/local/nvim/bin/nvim /usr/local/bin/vim
sudo ln -sf /usr/local/nvim/bin/nvim /usr/local/bin/nvim
echo ""
vim -v
;;
esac
# if has error "no c compile found"
# sudo apt install build-essential
+40
View File
@@ -0,0 +1,40 @@
#!/bin/bash
set -e
# 设置颜色
GREEN='\033[0;32m'
RED='\033[0;31m'
NC='\033[0m' # No Color
# 检查是否已安装 pyenv
if ! command -v pyenv &> /dev/null
then
echo -e "${RED}pyenv 未安装. 正在安装 pyenv...${NC}"
# 安装 pyenv
curl https://pyenv.run | bash
source ~/.config/fish/config.fish
else
echo -e "${GREEN}pyenv 已安装${NC}"
fi
# 询问用户想安装的 Python 版本
python_version=3.11.10
# 安装指定版本的 Python
echo -e "${GREEN}正在安装 Python $python_version...${NC}"
pyenv install $python_version
# 设置全局 Python 版本
pyenv global $python_version
# 验证安装
installed_version=$(python --version)
echo -e "${GREEN}Python 安装完成. 当前版本: $installed_version${NC}"
# 安装一些常用的 Python 包
echo -e "${GREEN}正在安装一些常用的 Python 包...${NC}"
pip install --upgrade pip
pip install ipython jupyter notebook pandas numpy matplotlib scikit-learn
echo -e "${GREEN}Python 环境设置完成!${NC}"
-2
View File
@@ -1,2 +0,0 @@
#/bin/fish
source $HOME/.config/fish/config.fish