Skip to content

Commit

Permalink
reactor: 重构linux安装脚本和linux策略
Browse files Browse the repository at this point in the history
  • Loading branch information
JusterZhu committed Sep 2, 2024
1 parent d504726 commit b91cdf8
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
15 changes: 9 additions & 6 deletions src/c#/GeneralUpdate.Bowl/Applications/Linux/install.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
#!/bin/bash

# 获取脚本的实际名称
SCRIPT_NAME=$(basename "\$0")

# 检查是否提供了参数
if [ "$#" -ne 1 ]; then
echo "Usage: install_package.sh <package-file>"
echo "Usage: $SCRIPT_NAME <package-file>"
exit 1
fi

Expand All @@ -11,19 +14,19 @@ PACKAGE_FILE=\$1
# 检查文件类型并安装
if [[ "$PACKAGE_FILE" == *.rpm ]]; then
if command -v rpm &> /dev/null; then
sudo rpm -ivh "$PACKAGE_FILE"
sudo rpm -ivh "$PACKAGE_FILE" || { echo "Failed to install $PACKAGE_FILE using rpm"; exit 1; }
elif command -v dnf &> /dev/null; then
sudo dnf install -y "$PACKAGE_FILE"
sudo dnf install -y "$PACKAGE_FILE" || { echo "Failed to install $PACKAGE_FILE using dnf"; exit 1; }
elif command -v yum &> /dev/null; then
sudo yum install -y "$PACKAGE_FILE"
sudo yum install -y "$PACKAGE_FILE" || { echo "Failed to install $PACKAGE_FILE using yum"; exit 1; }
else
echo "RPM package manager not found."
exit 1
fi
elif [[ "$PACKAGE_FILE" == *.deb ]]; then
if command -v dpkg &> /dev/null; then
sudo dpkg -i "$PACKAGE_FILE"
sudo apt-get install -f -y # 修复依赖问题
sudo dpkg -i "$PACKAGE_FILE" || { echo "Failed to install $PACKAGE_FILE using dpkg"; exit 1; }
sudo apt-get install -f -y || { echo "Failed to fix dependencies"; exit 1; }
else
echo "DEB package manager not found."
exit 1
Expand Down
6 changes: 4 additions & 2 deletions src/c#/GeneralUpdate.Bowl/Strategys/LinuxStrategy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,13 @@ public override void Launch()

private void Install()
{
//TODO: 安装路径需要调整
string scriptPath = "./install.sh";
string packageFile = GetPacketName();

ProcessStartInfo processStartInfo = new ProcessStartInfo()
{
FileName = "/bin/bash",
Arguments = $"install.sh {GetPacketName()}",
Arguments = $"{scriptPath} {packageFile}",
RedirectStandardOutput = true,
RedirectStandardError = true,
UseShellExecute = false,
Expand Down
3 changes: 1 addition & 2 deletions src/c#/GeneralUpdate.Bowl/Strategys/WindowStrategy.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.IO;
using System.Runtime.InteropServices;
using System.Runtime.InteropServices;

namespace GeneralUpdate.Bowl.Strategys;

Expand Down

0 comments on commit b91cdf8

Please sign in to comment.