Skip to content

Commit

Permalink
修复配置脚本到处创建init.log的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
copi143 committed Jan 20, 2025
1 parent 2f0388d commit f0db16c
Showing 1 changed file with 66 additions and 33 deletions.
99 changes: 66 additions & 33 deletions init.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,29 @@
#!/usr/bin/bash

info() {
INIT_LOG_PATH=$(pwd)/init.log

step() {
echo "" >>$INIT_LOG_PATH
echo -e "\033[32m[Info]\033[0m $1"
echo -e "## $1" >>$INIT_LOG_PATH
}

substep() {
echo "" >>$INIT_LOG_PATH
echo -e "\033[32m[Info]\033[0m $1"
echo -e "\033[32m[Info]\033[0m $1" >>init.log
echo -e "### $1" >>$INIT_LOG_PATH
}

info() {
echo "" >>$INIT_LOG_PATH
echo -e "- \033[32m[Info]\033[0m $1"
echo -e "- [Info] $1" >>$INIT_LOG_PATH
}

fail() {
echo "" >>$INIT_LOG_PATH
echo -e "\033[31m[Fail]\033[0m $1"
echo -e "\033[31m[Fail]\033[0m $1" >>init.log
echo -e "- [Fail] $1" >>$INIT_LOG_PATH
}

check_command() {
Expand All @@ -21,12 +37,28 @@ check_command() {
fi
}

run() {
if [ "$GITHUB_ACTIONS" = "true" ]; then
$*
else
echo "" >>$INIT_LOG_PATH
echo "\`\`\`sh" >>$INIT_LOG_PATH
echo "$ $*" >>$INIT_LOG_PATH
$* &>>$INIT_LOG_PATH
echo "-> $?" >>$INIT_LOG_PATH
echo "\`\`\`" >>$INIT_LOG_PATH
fi
}

check() {
if [ "$GITHUB_ACTIONS" = "true" ]; then
$*
else
echo "$ $*" >>init.log
$* &>>init.log
echo "" >>$INIT_LOG_PATH
echo "\`\`\`sh" >>$INIT_LOG_PATH
echo "$ $*" >>$INIT_LOG_PATH
$* &>>$INIT_LOG_PATH
echo "\`\`\`" >>$INIT_LOG_PATH
fi
retcode=$?
if [ $retcode -ne 0 ]; then
Expand Down Expand Up @@ -58,7 +90,12 @@ deinit() {
rm -r ./apps/lib
}

info 简单检查项目完整性
rm $INIT_LOG_PATH &>/dev/null
touch $INIT_LOG_PATH

echo "# Plant-OS 自动配置日志" >>$INIT_LOG_PATH

step 简单检查项目完整性

check_directory './apps'
check_directory './cmake'
Expand Down Expand Up @@ -91,26 +128,22 @@ if [ -d './bin' ] || [ -d './build' ] || [ -d './lib' ]; then
esac
fi

rm ./init.log &>/dev/null

info '开始配置 Plant-OS 项目'

touch init.log
step '开始配置 Plant-OS 项目'

info 创建目录
mkdir -p ./bin
mkdir -p ./bin/resource
mkdir -p ./build
mkdir -p ./lib
mkdir -p ./apps/lib
step 创建目录
run mkdir -p ./bin
run mkdir -p ./bin/resource
run mkdir -p ./build
run mkdir -p ./lib
run mkdir -p ./apps/lib

cd bin
info 创建符号链接
ln -s ../src/boot/run.sh run.sh &>>init.log
ln -s ../src/boot/run-efi.sh run-efi.sh &>>init.log
ln -s ../src/boot/bochs.sh bochs.sh &>>init.log
ln -s ../src/boot/netlog.py netlog.py &>>init.log
ln -s ../src/boot/templates templates &>>init.log
step 创建符号链接
run ln -s ../src/boot/run.sh run.sh &>>$INIT_LOG_PATH
run ln -s ../src/boot/run-efi.sh run-efi.sh &>>$INIT_LOG_PATH
run ln -s ../src/boot/bochs.sh bochs.sh &>>$INIT_LOG_PATH
run ln -s ../src/boot/netlog.py netlog.py &>>$INIT_LOG_PATH
run ln -s ../src/boot/templates templates &>>$INIT_LOG_PATH
cd ..

if [ "$ALREADY_HAS_RESOURCE_FILES" = "false" ]; then
Expand All @@ -122,17 +155,17 @@ if [ "$ALREADY_HAS_RESOURCE_FILES" = "false" ]; then
# plos-rsc.github.io

cd ./bin/resource
info 下载资源文件
step 下载资源文件
check_command curl '需要使用 curl 来下载资源文件' 'apt install curl'
check_command unzip '需要使用 unzip 来解压资源文件' 'apt install unzip'
info 下载并解压系统必须资源文件...
substep 下载并解压系统必须资源文件...
check curl -O "https://${SRC_MIRROR_SITE}/resource-files.zip"
check unzip resource-files.zip
check rm resource-files.zip
if [ "$GITHUB_ACTIONS" = "true" ]; then
info 'GitHub Actions 中跳过下载并解压其它资源文件'
else
info 下载并解压其它资源文件...
substep 下载并解压其它资源文件...
check curl -O "https://${SRC_MIRROR_SITE}/ext-resources.zip"
check unzip ext-resources.zip
check rm ext-resources.zip
Expand All @@ -142,18 +175,18 @@ if [ "$ALREADY_HAS_RESOURCE_FILES" = "false" ]; then
cd ../..

cd ./apps/lib
info 下载并解压应用程序资源文件...
substep 下载并解压应用程序资源文件...
check curl -O "https://${SRC_MIRROR_SITE}/lib.zip"
check unzip lib.zip
check rm lib.zip
cd ../..
fi

info '成功配置 Plant-OS 项目'
step '成功配置 Plant-OS 项目'
# ------------------------- 配置 CMake -------------------------

cd build
info '初始化 CMake 并进行编译测试'
step '初始化 CMake 并进行编译测试'
check_command gcc '需要使用 gcc 来编译项目' 'apt install gcc g++'
check_command nasm '需要使用 nasm 来编译项目' 'apt install nasm'
check_command mformat '需要使用 mformat 来格式化软盘' 'apt install mtools'
Expand All @@ -166,12 +199,12 @@ check make make
cd ..

if [ "$GITHUB_ACTIONS" = "true" ]; then
info 'GitHub Actions 中跳过运行'
step 'GitHub Actions 中跳过运行'
else
cd bin
info '运行 Plant-OS'
step '运行 Plant-OS'
check_command qemu-system-i386 '需要使用 qemu-system-i386 来运行 Plant-OS' 'apt install qemu-system-i386'
check ./run.sh
./run.sh
cd ..
fi

Expand All @@ -182,4 +215,4 @@ if [ "$GITHUB_ACTIONS" = "true" ]; then
cp ./src/boot/requirements.txt bin/
fi

info 配置脚本结束
step 配置脚本结束

0 comments on commit f0db16c

Please sign in to comment.