@@ -7,18 +7,35 @@ import (
77 "net/http"
88 "os"
99 "os/exec"
10+ "os/user"
1011
1112 "github.com/Hayao0819/go-distro"
1213 "github.com/Hayao0819/go-distro/linux"
1314
14- "github.com/FascodeNet/alterlinux/src/internal/archiso "
15+ "github.com/FascodeNet/alterlinux/src/internal/cmd/injectable "
1516 "github.com/FascodeNet/alterlinux/src/internal/errors"
1617 "github.com/Jguer/go-alpm/v2"
1718 "github.com/go-git/go-git/v6"
1819 "github.com/go-git/go-git/v6/plumbing"
1920 "github.com/spf13/cobra"
2021)
2122
23+ /*
24+ このコードは概ねこれです。
25+
26+ #!/usr/bin/env bash
27+ set -eEuo pipefail
28+ if which pacman 2> /dev/null 1>&2 && pacman -Qq archiso; then
29+ curl -sL "https://raw.githubusercontent.com/FascodeNet/alterlinux/refs/heads/dev/archiso/mkarchiso" > "/usr/local/bin/mkarchiso"
30+ else
31+ tmpdir=$(mktemp -d)
32+ trap 'rm -rf "$tmpdir"' 1 2 3 15
33+ git clone https://github.com/FascodeNet/alterlinux "$tmpdir"
34+ cd "$tmpdir" || exit 1
35+ make install
36+ fi
37+ */
38+
2239func isPkgInstalled (name ... string ) (bool , error ) {
2340
2441 if ! isArchLinux () {
@@ -72,7 +89,7 @@ func checkoutBranch(repo *git.Repository, branch string) error {
7289 }
7390
7491 err = w .Checkout (& git.CheckoutOptions {
75- Branch : plumbing .ReferenceName (branch ),
92+ Branch : plumbing .NewBranchReferenceName (branch ),
7693 })
7794 if err != nil {
7895 return err
@@ -108,9 +125,9 @@ func installArchisoCmd() *cobra.Command {
108125 Use : "install-archiso" ,
109126 Short : "Install injectable Archiso" ,
110127 PreRunE : func (cmd * cobra.Command , args []string ) error {
111- installed , err := archiso . IsInjectable ()
128+ installed , err := injectable . TestInjectable ()
112129 if err != nil {
113- return err
130+ installed = false
114131 }
115132 if installed {
116133 return errors .New ("archiso-injectable is already installed" )
@@ -157,19 +174,26 @@ func installArchisoCmd() *cobra.Command {
157174 }
158175 return nil
159176 } else {
177+ if u , err := user .Current (); err == nil && u .Uid != "0" {
178+ return errors .New ("archiso package is not installed, please run this command as root to install from source" )
179+ }
180+
160181 slog .Info ("archiso package is not installed, cloning full repository and installing from source" )
161182 repoURL := fmt .Sprintf ("https://github.com/%s/%s.git" , githubOwner , githubRepo )
183+ slog .Info ("Cloning repository" , "url" , repoURL , "ref" , githubRef )
162184 repo , tempDir , err := gitCloneIntoTempDir (repoURL )
163185 if err != nil {
164186 return err
165187 }
166188 defer os .RemoveAll (tempDir )
167189
190+ slog .Info ("Checking out branch" , "branch" , githubRef )
168191 if err := checkoutBranch (repo , githubRef ); err != nil {
169192 return err
170193 }
171194
172- makeCmd := exec .Command ("make" , "install" )
195+ slog .Info ("Running make install" , "dir" , tempDir )
196+ makeCmd := exec .Command ("make" , "install-scripts" )
173197 makeCmd .Dir = tempDir
174198 makeCmd .Stdout = os .Stdout
175199 makeCmd .Stderr = os .Stderr
@@ -184,8 +208,8 @@ func installArchisoCmd() *cobra.Command {
184208
185209 cmd .Flags ().StringP ("script-dest" , "" , "/usr/local/bin/mkarchiso" , "Local destination path for the mkarchiso script" )
186210 cmd .Flags ().StringP ("github-owner" , "" , "FascodeNet" , "GitHub owner of the archiso-injectable repository" )
187- cmd .Flags ().StringP ("github-repo" , "" , "archiso-injectable " , "GitHub repository name of the archiso-injectable repository" )
188- cmd .Flags ().StringP ("github-ref" , "" , "main " , "GitHub reference (branch, tag, commit) of the archiso-injectable repository" )
211+ cmd .Flags ().StringP ("github-repo" , "" , "alterlinux " , "GitHub repository name of the archiso-injectable repository" )
212+ cmd .Flags ().StringP ("github-ref" , "" , "dev " , "GitHub reference (branch, tag, commit) of the archiso-injectable repository" )
189213
190214 return & cmd
191215
0 commit comments