|
| 1 | +/* |
| 2 | +* |
| 3 | +# SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. |
| 4 | +# SPDX-License-Identifier: Apache-2.0 |
| 5 | +# |
| 6 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | +# you may not use this file except in compliance with the License. |
| 8 | +# You may obtain a copy of the License at |
| 9 | +# |
| 10 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | +# |
| 12 | +# Unless required by applicable law or agreed to in writing, software |
| 13 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | +# See the License for the specific language governing permissions and |
| 16 | +# limitations under the License. |
| 17 | +* |
| 18 | +*/ |
| 19 | +package installer |
| 20 | + |
| 21 | +import ( |
| 22 | + "fmt" |
| 23 | + "os" |
| 24 | + "path/filepath" |
| 25 | +) |
| 26 | + |
| 27 | +func resolvePackageType(hostRoot string, packageType string) (rPackageTypes string, rerr error) { |
| 28 | + if packageType != "" && packageType != "auto" { |
| 29 | + return packageType, nil |
| 30 | + } |
| 31 | + |
| 32 | + if info, err := os.Stat(filepath.Join(hostRoot, "/usr/bin/rpm")); err != nil && !info.IsDir() { |
| 33 | + return "rpm", nil |
| 34 | + } |
| 35 | + if info, err := os.Stat(filepath.Join(hostRoot, "/usr/bin/dpkg")); err != nil && !info.IsDir() { |
| 36 | + return "deb", nil |
| 37 | + } |
| 38 | + |
| 39 | + return "deb", nil |
| 40 | +} |
| 41 | + |
| 42 | +func defaultSourceRoot(hostRoot string, packageType string) (string, error) { |
| 43 | + resolvedPackageType, err := resolvePackageType(hostRoot, packageType) |
| 44 | + if err != nil { |
| 45 | + return "", err |
| 46 | + } |
| 47 | + switch resolvedPackageType { |
| 48 | + case "deb": |
| 49 | + return "/artifacts/deb", nil |
| 50 | + case "rpm": |
| 51 | + return "/artifacts/rpm", nil |
| 52 | + default: |
| 53 | + return "", fmt.Errorf("invalid package type: %v", resolvedPackageType) |
| 54 | + } |
| 55 | +} |
0 commit comments