Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
X
ximperconf
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Ximper Linux
ximperconf
Commits
a751baae
Verified
Commit
a751baae
authored
Nov 30, 2025
by
Kirill Unitsaev
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add system subcommands
parent
a0099789
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
140 additions
and
0 deletions
+140
-0
main.go
main.go
+2
-0
commands.go
system/commands.go
+46
-0
grub-actions.go
system/grub-actions.go
+92
-0
No files found.
main.go
View file @
a751baae
...
...
@@ -7,6 +7,7 @@ import (
"ximperconf/create"
"ximperconf/hyprland"
"ximperconf/repo"
"ximperconf/system"
"github.com/urfave/cli/v3"
)
...
...
@@ -26,6 +27,7 @@ func main() {
repo
.
CommandList
(),
create
.
CommandList
(),
hyprland
.
CommandList
(),
system
.
CommandList
(),
{
Name
:
"help"
,
Aliases
:
[]
string
{
"h"
},
...
...
system/commands.go
0 → 100644
View file @
a751baae
package
system
import
(
"fmt"
"ximperconf/config"
"context"
"github.com/urfave/cli/v3"
)
func
CommandList
()
*
cli
.
Command
{
return
&
cli
.
Command
{
Name
:
"system"
,
Hidden
:
!
config
.
Env
.
IsRoot
,
Usage
:
"System Management"
,
Before
:
func
(
ctx
context
.
Context
,
command
*
cli
.
Command
)
(
context
.
Context
,
error
)
{
if
!
config
.
Env
.
IsRoot
{
fmt
.
Printf
(
"Эта команда требует root.
\n
"
)
return
nil
,
fmt
.
Errorf
(
""
)
}
return
ctx
,
nil
},
Commands
:
[]
*
cli
.
Command
{
{
Name
:
"fix-grub-resolution"
,
Usage
:
"Fix GRUB resolution"
,
Action
:
SystemGrubFixResolutionCommand
,
Flags
:
[]
cli
.
Flag
{
&
cli
.
BoolFlag
{
Name
:
"update"
,
Usage
:
"Automatically run update-grub after fixing"
,
Aliases
:
[]
string
{
"u"
},
Value
:
false
,
},
&
cli
.
BoolFlag
{
Name
:
"verbose"
,
Usage
:
"Enable verbose output"
,
Aliases
:
[]
string
{
"V"
},
Value
:
false
,
},
},
},
},
}
}
system/grub-actions.go
0 → 100644
View file @
a751baae
package
system
import
(
"context"
"fmt"
"os"
"os/exec"
"strings"
"github.com/urfave/cli/v3"
)
var
(
grubFile
=
"/etc/default/grub"
grub_gfxmode
=
"3840x2160,3200x1800,2560x1440,1920x1080,auto"
)
func
SystemGrubFixResolution
(
autoUpdate
,
verbose
bool
)
error
{
content
,
err
:=
os
.
ReadFile
(
grubFile
)
if
err
!=
nil
{
return
fmt
.
Errorf
(
"не удалось прочитать %s: %w"
,
grubFile
,
err
)
}
lines
:=
strings
.
Split
(
string
(
content
),
"
\n
"
)
found
:=
false
changed
:=
false
oldValue
:=
""
for
i
,
line
:=
range
lines
{
if
strings
.
HasPrefix
(
line
,
"GRUB_GFXMODE="
)
{
found
=
true
oldValue
=
strings
.
Trim
(
strings
.
SplitN
(
line
,
"="
,
2
)[
1
],
`"`
)
if
oldValue
==
""
||
oldValue
==
"auto"
{
lines
[
i
]
=
fmt
.
Sprintf
(
`GRUB_GFXMODE="%s"`
,
grub_gfxmode
)
changed
=
true
}
break
}
}
if
!
found
{
lines
=
append
(
lines
,
fmt
.
Sprintf
(
`GRUB_GFXMODE="%s"`
,
grub_gfxmode
))
changed
=
true
oldValue
=
"<empty>"
}
if
!
changed
{
return
fmt
.
Errorf
(
"GRUB_GFXMODE уже установлен: %s"
,
oldValue
)
}
newContent
:=
strings
.
Join
(
lines
,
"
\n
"
)
if
err
:=
os
.
WriteFile
(
grubFile
,
[]
byte
(
newContent
),
0644
);
err
!=
nil
{
return
fmt
.
Errorf
(
"не удалось записать %s: %w"
,
grubFile
,
err
)
}
if
verbose
{
fmt
.
Printf
(
"GRUB_GFXMODE: %s → %s
\n
"
,
oldValue
,
grub_gfxmode
)
}
if
autoUpdate
{
cmd
:=
exec
.
Command
(
"update-grub"
)
out
,
err
:=
cmd
.
CombinedOutput
()
if
err
!=
nil
{
return
fmt
.
Errorf
(
"ошибка при выполнении update-grub: %v (%s)"
,
err
,
out
)
}
if
verbose
{
fmt
.
Println
(
"Лог update-grub:
\n
"
,
string
(
out
))
}
}
return
nil
}
func
SystemGrubFixResolutionCommand
(
ctx
context
.
Context
,
cmd
*
cli
.
Command
)
error
{
autoUpdate
:=
cmd
.
Bool
(
"update"
)
verbose
:=
cmd
.
Bool
(
"verbose"
)
if
err
:=
SystemGrubFixResolution
(
autoUpdate
,
verbose
);
err
!=
nil
{
fmt
.
Println
(
err
)
return
err
}
if
!
verbose
{
fmt
.
Println
(
"GRUB_GFXMODE исправлен успешно."
)
}
if
autoUpdate
&&
!
verbose
{
fmt
.
Println
(
"Выполнен update-grub."
)
}
return
nil
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment