Repository navigation
Expand file tree
/
Copy pathparted.elv
More file actions
79 lines (74 loc) · 2.07 KB
/
Copy pathparted.elv
File metadata and controls
79 lines (74 loc) · 2.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# Copyright (c) 2021, Cody Opel <cwopel@chlorm.net>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
use github.com/chlorm/elvish-stl/list
use github.com/chlorm/elvish-stl/map
use github.com/chlorm/elvish-util-wrappers/su
# Creates a new partition table with the specified partitions.
# parts = [
# &1=[
# type=logical|primary
# fs=btrfs (optional)
# name='partition label'
# start=''
# end=''
# flags=[
# boot
# root
# ]
# ]
# ]
fn new {|device parts|
var cmds = [ 'mklabel' 'gpt' ]
var valid-fs = [
'btrfs'
'ext2'
'fat32'
'linux-swap'
]
var valid-flags = [
'bios_grub'
'boot'
'irst'
'root'
'swap'
]
var valid-types = [
'extended'
'logical'
'primary'
]
for i [ (map:keys $parts) ] {
var _ = (list:has $valid-types $parts[$i]['type'])
var fs = ''
if (map:has-key $parts[$i] 'fs') {
var _ = (list:has $valid-fs $parts[$i]['fs'])
set fs = $parts[$i]['fs']
}
set cmds = [
$@cmds
'mkpart' $parts[$i]['type'] $fs $parts[$i]['start'] $parts[$i]['end']
'name' $i $parts[$i]['name']
]
if (map:has-key $parts[$i] 'flags') {
for o $parts[$i]['flags'] {
var _ = (list:has $valid-flags $o)
set cmds = [
$@cmds
'set' $i $o 'on'
]
}
}
}
su:do 'parted' $device $cmds
}