Skip to content

Commit 1e4ad71

Browse files
committed
Optimize the program & add support to i386 architecture
1 parent af48e05 commit 1e4ad71

8 files changed

Lines changed: 96 additions & 40 deletions

File tree

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
*.test
22
test.*
33
*.exe
4-
test*
54
config.yml
65
ArchLinuxInstaller
76
pacman.conf
87
.viminfo
98
builds
9+
.zcompdump

README.md

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,55 @@
11
# ArchLinux Installer (writed in go)
22

3+
## Usage
4+
5+
First execute the binary with the `newconfig` arg, like this to create a empty config file
6+
```./[binary] [arg]
7+
```
8+
After the configuration of the file execute `install` arg to init the installation
9+
10+
### Configuration
11+
12+
The YAML file is a data structure used to configure the installation parameters of the provided Python script. Below are the available configuration options:
13+
14+
`custom_pacman_config`: A boolean value indicating whether to use a custom pacman configuration. The default value is "false".
15+
`keyboard`: Configures the keyboard layout for the installation. The default value is an empty string.
16+
17+
#### Wifi
18+
19+
- `wifi`: An object specifying the wireless network configuration. It consists of the following four properties:
20+
1. `state`: A boolean value indicating whether to enable the wireless connection. The default value is "false".
21+
2. `name`: The name of the wireless network to connect to. The default value is an empty string.
22+
3. `adapter`: The wireless network adapter to use for the connection. The default value is an empty string.
23+
4. `password`: The password for the wireless network. The default value is an empty string.
24+
25+
#### Partitions
26+
27+
`partitions`: An object specifying the partitions to be used for the installation. It consists of the following properties:
28+
29+
1. `boot`: An object specifying the boot partition. It consists of the following properties:
30+
31+
* `partition`: The partition device. The default value is "".
32+
* `format`: A boolean value indicating whether to format the partition. The default value is "".
33+
* `filesystem`: The file system to be used for the partition. The default value is "".
34+
35+
2. `root`: An object specifying the root partition. It has the same properties as the boot partition.
36+
3. `home`: An object specifying the home folder partition. It has the same properties as the boot partition.
37+
4. `swap`: An object specifying the swap partition. It has the same properties as the boot partition, except it does not have the "filesystem" property.
38+
39+
#### Extra Configs
40+
41+
`grub_install_disk`: The storage device where the GRUB bootloader will be installed. The default value is "".
42+
43+
`pacstrap_skip`: A boolean value indicating whether to skip the installation of Arch Linux basic packages. The default value is "false".
44+
45+
`additional_packages`: A string specifying the additional packages to install. The default value is an empty string.
46+
47+
`uefi`: A boolean value indicating whether the system uses UEFI instead of BIOS. The default value is "false".
48+
49+
`arch-chroot`: A boolean value indicating whether to run the script in the Arch Linux chroot environment. The default value is "false".
50+
51+
`post_install_commands`: A string specifying the commands to be executed after the package installation. The default value is an empty string.
52+
53+
`post_install_chroot_commands`: A string specifying the commands to be executed after the package installation in the Arch Linux chroot environment. The default value is an empty string.
54+
55+
`reboot`: Allows specifying whether to restart the system after installation. If this field is omitted, the default configuration will be used.

build.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,5 @@ export GOARCH=arm64
44
go build -o builds/arm64/ArchInstaller-arm64 .
55
export GOARCH=amd64
66
go build -o builds/amd64/ArchInstaller-amd64 .
7+
export GOARCH=386
8+
go build -o builds/i386/ArchInstaller-i386 .

data/data.go

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,18 @@ import (
44
"fmt"
55
"os"
66

7+
"github.com/Tom5521/MyGolangTools/file"
78
"github.com/gookit/color"
89
"gopkg.in/yaml.v3"
910
)
1011

1112
var (
12-
Yellow = color.FgYellow.Render
13-
Red = color.FgRed.Render
14-
filename = "config.yml"
13+
Yellow = color.FgYellow.Render
14+
Red = color.FgRed.Render
15+
Pfilename = filename
16+
filename = "config.yml"
1517
)
1618

17-
func CheckDir(dir string) bool {
18-
if _, err := os.Stat(dir); os.IsNotExist(err) {
19-
return false
20-
} else {
21-
return true
22-
}
23-
}
24-
2519
type yamlfile struct {
2620
CustomPacmanConfig bool `yaml:"custom_pacman_config"`
2721
Keyboard string `yaml:"keyboard"`
@@ -64,15 +58,15 @@ type yamlfile struct {
6458

6559
func GetYamldata() yamlfile {
6660
yamldata := yamlfile{}
67-
if !CheckDir(filename) {
61+
if check, _ := file.CheckFile(filename); !check {
6862
fmt.Printf(Red(filename+" not found...") + Yellow("Creating a new one...\n"))
6963
NewYamlFile()
70-
if CheckDir(filename) {
64+
if newcheck, _ := file.CheckFile(filename); newcheck {
7165
color.Green.Println("config file created!!!")
7266
}
7367
os.Exit(0)
7468
}
75-
file, err := os.ReadFile(filename)
69+
file, err := file.ReadFileCont(filename)
7670
if err != nil {
7771
color.Red.Println("Error reading " + filename)
7872
}
@@ -85,18 +79,12 @@ func GetYamldata() yamlfile {
8579

8680
func NewYamlFile() {
8781
yamlstruct := yamlfile{}
88-
file, err := os.Create(filename)
89-
if err != nil {
90-
color.Red.Println("Error creating " + filename)
91-
return
92-
}
93-
defer file.Close()
9482
data, err := yaml.Marshal(yamlstruct)
9583
if err != nil {
9684
color.Red.Println("Error Marshalling config file")
9785
return
9886
}
99-
_, err = file.WriteString(string(data))
87+
err = file.ReWriteFile(filename, string(data))
10088
if err != nil {
10189
color.Red.Println("Error writing the data in the new yml file")
10290
return

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module github.com/Tom5521/ArchLinuxInstaller
33
go 1.21.0
44

55
require (
6-
github.com/Tom5521/MyGolangTools v0.0.0-20230806053540-1d169699a019 // indirect
6+
github.com/Tom5521/MyGolangTools v0.0.0-20230816231450-36b02638e41c // indirect
77
github.com/gookit/color v1.5.4 // indirect
88
github.com/xo/terminfo v0.0.0-20210125001918-ca9a967f8778 // indirect
99
golang.org/x/sys v0.10.0 // indirect

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
github.com/Tom5521/MyGolangTools v0.0.0-20230806053540-1d169699a019 h1:SNXIavRN8EMNEZb8LVOFEZl1pgvPALH5UIHrlOBM8Qw=
22
github.com/Tom5521/MyGolangTools v0.0.0-20230806053540-1d169699a019/go.mod h1:QovXEupbIBTOVIJ97GiRFabS4UJQm+Me4n3D2rkf6vg=
3+
github.com/Tom5521/MyGolangTools v0.0.0-20230816231450-36b02638e41c h1:chvCOXnVMqlAmhYmr3/+W/rjIrP+rjS2YS05b7pXM30=
4+
github.com/Tom5521/MyGolangTools v0.0.0-20230816231450-36b02638e41c/go.mod h1:QovXEupbIBTOVIJ97GiRFabS4UJQm+Me4n3D2rkf6vg=
35
github.com/gookit/color v1.5.4 h1:FZmqs7XOyGgCAxmWyPslpiok1k05wmY3SJTytgvYFs0=
46
github.com/gookit/color v1.5.4/go.mod h1:pZJOeOS8DM43rXbp4AZo1n9zCU2qjpcRko0b6/QJi9w=
57
github.com/xo/terminfo v0.0.0-20210125001918-ca9a967f8778 h1:QldyIu/L63oPpyvQmHgvgickp1Yw510KJOqX7H24mg8=

main.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,14 @@ package main
33
import (
44
"os"
55

6+
"github.com/Tom5521/ArchLinuxInstaller/data"
67
"github.com/Tom5521/ArchLinuxInstaller/src"
8+
"github.com/Tom5521/MyGolangTools/commands"
9+
"github.com/gookit/color"
710
)
811

12+
var sh = commands.Sh{}
13+
914
func main() {
1015
if len(os.Args) > 1 {
1116
if os.Args[1] == "install" {
@@ -30,5 +35,12 @@ func main() {
3035
src.Fstab()
3136
src.Grub()
3237
}
38+
if os.Args[1] == "newconfig" {
39+
data.NewYamlFile()
40+
err := sh.Cmd("vim " + data.Pfilename)
41+
if err != nil {
42+
color.Red.Println("Error oppening vim." + err.Error())
43+
}
44+
}
3345
}
3446
}

src/src.go

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,22 @@ import (
77

88
"github.com/Tom5521/ArchLinuxInstaller/data"
99
"github.com/Tom5521/MyGolangTools/commands"
10+
"github.com/Tom5521/MyGolangTools/file"
1011
"github.com/gookit/color"
1112
)
1213

1314
var (
15+
// Functions
16+
sh = commands.Sh{}
17+
f = fmt.Sprintf // Set a more comfortable alias for fmt.Sprintf()
18+
fmRed = color.Red.Println
19+
fmGreen = color.Green.Println
20+
fmYellow = color.Yellow.Println
21+
// Data
1422
conf = data.GetYamldata()
1523
partitions = conf.Partitions
1624
wifi = conf.Wifi
17-
sh = commands.Sh{}
18-
f = fmt.Sprintf
1925
wifi_pkg string
20-
fmRed = color.Red.Println
21-
fmGreen = color.Green.Println
22-
fmYellow = color.Yellow.Println
2326
pacmanConf = `
2427
#Pacman-config-modifyed by Tom5521 ---YES---THATS---MODIFIED---
2528
@@ -112,7 +115,7 @@ func Mount() {
112115
}
113116
if conf.Uefi {
114117
fmYellow("uefi is true")
115-
if !data.CheckDir("/mnt/efi") {
118+
if check_efi, _ := file.CheckFile("/mnt/efi"); !check_efi {
116119
err = os.Mkdir("/mnt/efi", os.ModePerm)
117120
if err != nil {
118121
fmRed("Error making /mnt/efi")
@@ -127,7 +130,7 @@ func Mount() {
127130
} else {
128131
fmGreen("Boot mounted successfully!")
129132
}
130-
} else if !data.CheckDir("/mnt/boot") {
133+
} else if check_Boot, _ := file.CheckFile("/mnt/boot"); !check_Boot {
131134
err = os.Mkdir("/mnt/boot", os.ModePerm)
132135
if err != nil {
133136
fmRed("Error making /mnt/boot")
@@ -143,7 +146,7 @@ func Mount() {
143146
}
144147
}
145148
if partitions.Home.Partition != "" {
146-
if !data.CheckDir("/mnt/home") {
149+
if checkdir, _ := file.CheckFile("/mnt/home"); !checkdir {
147150
err = os.Mkdir("/mnt/home", os.ModePerm)
148151
if err != nil {
149152
fmRed("Error making /mnt/home")
@@ -172,22 +175,18 @@ func Mount() {
172175
}
173176

174177
func PacmanConf() {
175-
if conf.CustomPacmanConfig && !data.CheckDir("pacman.conf") {
178+
if check_pacman_cfg, _ := file.CheckFile("pacman.conf"); conf.CustomPacmanConfig && !check_pacman_cfg {
176179
fmYellow("No custom pacman conf found... Creatig a new one...")
177-
file, err := os.Create("pacman.conf")
180+
err := file.ReWriteFile("pacman.conf", pacmanConf)
178181
if err != nil {
179-
fmRed("Error Creating new pacman.conf file")
180-
}
181-
_, err = file.WriteString(pacmanConf)
182-
if err != nil {
183-
fmRed("Error writing new pacman.conf")
182+
fmRed("Error creating new pacman.conf")
184183
} else {
185184
fmGreen("pacman.conf created successfully!")
186185
}
187186
}
188-
pacmanfl, _ := os.ReadFile("/etc/pacman.conf")
187+
pacmanfl, _ := file.ReadFileCont("/etc/pacman.conf")
189188
if conf.CustomPacmanConfig && !strings.Contains("---YES---THATS---MODIFIED---", string(pacmanfl)) {
190-
err := sh.Cmd("cp pacman.conf /etc/")
189+
err := file.ReWriteFile("/etc/pacman.conf", pacmanConf)
191190
if err != nil {
192191
fmRed("Error copying pacman.conf file")
193192
} else {

0 commit comments

Comments
 (0)