From 5358a9edcdd9229a234d07d185aa588d1f1886b2 Mon Sep 17 00:00:00 2001 From: zart Date: Wed, 26 Jun 2024 10:57:12 +0800 Subject: [PATCH] msg MQTT message --- download_and_execute.sh | 84 +++++++++++++++++++++++++++++++++++++++++ smp_init.sh | 43 +++++++++++++++++++++ 2 files changed, 127 insertions(+) create mode 100644 download_and_execute.sh create mode 100644 smp_init.sh diff --git a/download_and_execute.sh b/download_and_execute.sh new file mode 100644 index 0000000..cbd0a00 --- /dev/null +++ b/download_and_execute.sh @@ -0,0 +1,84 @@ +#!/bin/bash + +# 设置仓库URL和本地目录 +repo_url="https://bdgit.educoder.net/pv2ajsu8k/smp_pc_20240625.git" +local_dir="smp_pc" + +# 检查是否安装了git +if ! command -v git &> /dev/null; then + echo "未找到git,尝试安装git..." + if command -v apt-get &> /dev/null; then + sudo apt-get update + sudo apt-get install -y git + elif command -v yum &> /dev/null; then + sudo yum install -y git + else + echo "无法自动安装git,请手动安装git后重试。" + exit 1 + fi +fi + +# 克隆仓库 +if git clone $repo_url $local_dir; then + echo "仓库克隆成功" +else + echo "仓库克隆失败" + exit 1 +fi + +# 进入仓库目录 +cd $local_dir || { echo "无法进入目录 $local_dir"; exit 1; } + +# 检查smp_init.sh是否存在 +if [ -f "smp_init.sh" ]; then + # 如果没有执行权限,尝试添加执行权限 + if [ ! -x "smp_init.sh" ]; then + echo "smp_init.sh 没有执行权限,尝试添加执行权限..." + chmod +x "smp_init.sh" || { echo "无法添加执行权限"; exit 1; } + fi + + # 执行smp_init.sh + ./smp_init.sh + echo "smp_init.sh 执行完成" +else + echo "smp_init.sh 不存在" + exit 1 +fi + +check_software() { + local software_name=$1 + if command -v $software_name &> /dev/null + then + echo "$software_name 已安装" + else + echo "$software_name 未安装" + fi +} + +check_library() { + local library_path=$1 + if [ -f "$library_path" ]; then + echo "库文件 $library_path 存在" + else + echo "库文件 $library_path 不存在" + fi +} + +check_python_library() { + local library_name=$1 + python -c "import $library_name" &> /dev/null + if [ $? -eq 0 ]; then + echo "Python库 $library_name 存在" + else + echo "Python库 $library_name 不存在" + fi +} + +# 检查某个软件 +check_software "git" + +# 检查某个库文件 +#check_library "/usr/lib/libc.so.6" + +# 检查某个Python库 +check_python_library "numpy" diff --git a/smp_init.sh b/smp_init.sh new file mode 100644 index 0000000..49a3139 --- /dev/null +++ b/smp_init.sh @@ -0,0 +1,43 @@ +#!/bin/bash + + + + +#!/bin/bash + +# 创建一个目录用于存放虚拟环境 +env_dir="myenv" + +# 检查是否已经存在虚拟环境目录 +if [ -d "$env_dir" ]; then + echo "虚拟环境目录 $env_dir 已存在,跳过创建步骤。" +else + # 创建虚拟环境 + python3 -m venv $env_dir + echo "虚拟环境已创建在 $env_dir" +fi + +# 激活虚拟环境 +source $env_dir/bin/activate + +# 检查是否成功激活虚拟环境 +if [ "$VIRTUAL_ENV" != "" ]; then + echo "虚拟环境已激活" +else + echo "虚拟环境激活失败" + exit 1 +fi + +# 安装 paho-mqtt 库 +pip install paho-mqtt + +# 验证安装 +if python -c "import paho.mqtt.client" &> /dev/null; then + echo "paho-mqtt 安装成功" +else + echo "paho-mqtt 安装失败" +fi + +# 提示如何退出虚拟环境 +echo "要退出虚拟环境,请运行 'deactivate'" +