Skip to content

Commit b35bb97

Browse files
committed
copy-in: generic command to copy things in a pot
copy-in: first implementation copy-in: adjust verbosity support Add copy-in command to pot Add autocompletion Add tests add-file: mark as deprecated
1 parent 22133d7 commit b35bb97

File tree

6 files changed

+364
-0
lines changed

6 files changed

+364
-0
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,16 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
99
- update-config: new command that will update a pot configuration
1010
- execute: an orchestration oriented command that imports and automatically set several settings on a pot
1111
- prepare: new command, taking the place of execute
12+
- copy-in: new command, to copy files or directory inside a pot (generalized replacement of add-file)
1213

1314
### Changed
1415
- export-ports: removed -S for static port export
1516
- export-ports: add the ability to associate any host port to a pot port to be exported using pot_port:host_port format
1617
- execute: an alias for prepare
1718

19+
### Deprecated
20+
- add-file: deprecated, replaced by the more general new copy-in command
21+
1822
## [0.6.1] 2019-06-25
1923
### Fixed
2024
- init: make pf.conf more robust

bin/pot

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ Commands:
9090
promote -- Promote a cloned pot -- DEPRECATED
9191
rename -- Rename a pot
9292
destroy -- Destroy a pot
93+
copy-in -- Copy a file or a directory into a pot
9394
add-file -- Add a file to a pot
9495
add-fscomp -- Add a fs component or a directory to a pot
9596
add-dep -- Add a dependency
@@ -158,6 +159,7 @@ case "${CMD}" in
158159
list|info|ps|top|\
159160
init|de-init|vnet-start|\
160161
create-base|create-fscomp|create|create-dns|\
162+
copy-in|\
161163
add-file|add-fscomp|destroy|add-dep|set-rss|set-cmd|\
162164
export|import|prepare|\
163165
export-ports|set-attribute|get-attribute|\

share/pot/add-file.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,12 @@ pot-add-file()
5959
esac
6060
done
6161

62+
echo '##############################'
63+
echo '# add-file is deprecated #'
64+
echo '##############################'
65+
echo '# Please use copy-in instead #'
66+
echo '##############################'
67+
6268
if [ -z "$_pname" ]; then
6369
_error "A pot name is mandatory"
6470
add-file-help

share/pot/copy-in.sh

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
#!/bin/sh
2+
:
3+
4+
# shellcheck disable=SC2039
5+
copy-in-help()
6+
{
7+
echo "pot copy-in [-hv] -p pot -s source -d destination"
8+
echo ' -h print this help'
9+
echo ' -v verbose'
10+
echo ' -p pot : the working pot'
11+
echo ' -s source : the file to be added component to be added'
12+
echo ' -d destination : the final location inside the pot'
13+
}
14+
15+
# $1 source
16+
_source_validation()
17+
{
18+
# shellcheck disable=SC2039
19+
local _pname _source _destination
20+
_source="$1"
21+
if [ -f "$_source" ] || [ -d "$_source" ]; then
22+
if [ -r "$_source" ]; then
23+
return 0 # true
24+
else
25+
_error "$_source not readable"
26+
fi
27+
else
28+
_error "$_source not valid"
29+
return 1 # false
30+
fi
31+
}
32+
33+
# shellcheck disable=SC2039
34+
pot-copy-in()
35+
{
36+
local _pname _source _destination _to_be_umount
37+
OPTIND=1
38+
_pname=
39+
_destination=
40+
while getopts "hvs:d:p:" _o ; do
41+
case "$_o" in
42+
h)
43+
copy-in-help
44+
${EXIT} 0
45+
;;
46+
v)
47+
_POT_VERBOSITY=$(( _POT_VERBOSITY + 1))
48+
;;
49+
s)
50+
_source="$OPTARG"
51+
;;
52+
p)
53+
_pname="$OPTARG"
54+
;;
55+
d)
56+
_destination="$OPTARG"
57+
;;
58+
*)
59+
copy-in-help
60+
${EXIT} 1
61+
;;
62+
esac
63+
done
64+
65+
if [ -z "$_pname" ]; then
66+
_error "A pot name is mandatory"
67+
copy-in-help
68+
${EXIT} 1
69+
fi
70+
if [ -z "$_source" ]; then
71+
_error "A source is mandatory"
72+
copy-in-help
73+
${EXIT} 1
74+
fi
75+
if [ -z "$_destination" ]; then
76+
_error "A destination is mandatory"
77+
copy-in-help
78+
${EXIT} 1
79+
fi
80+
if ! _is_absolute_path "$_destination" ; then
81+
_error "The destination has to be an absolute pathname"
82+
${EXIT} 1
83+
fi
84+
_destination="${_destination#/}"
85+
86+
if ! _is_pot "$_pname" ; then
87+
_error "pot $_pname is not valid"
88+
copy-in-help
89+
${EXIT} 1
90+
fi
91+
if ! _is_uid0 ; then
92+
${EXIT} 1
93+
fi
94+
if ! _source_validation "$_source" ; then
95+
copy-in-help
96+
${EXIT} 1
97+
fi
98+
if ! _is_pot_running "$_pname" ; then
99+
_pot_mount "$_pname"
100+
_to_be_umount=1
101+
fi
102+
if _is_verbose ; then
103+
_cp_opt="-va"
104+
else
105+
_cp_opt="-a"
106+
fi
107+
if cp "$_cp_opt" "$_source" "${POT_FS_ROOT}/jails/$_pname/m/$_destination" ; then
108+
_debug "Source $_source copied in the pot $_pname"
109+
else
110+
_error "Source $_source NOT copied because of an error"
111+
fi
112+
if [ "$_to_be_umount" = "1" ]; then
113+
_pot_umount "$_pname"
114+
fi
115+
}

share/zsh/site-functions/_pot

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,14 @@ _pot() {
154154
'-f[fscomp name]:fscomp name:_pot_fscomps' \
155155
'-r[Recursive destroying]'
156156
;;
157+
copy-in)
158+
_arguments \
159+
'-h[Show help]' \
160+
'-v[Verbose output]' \
161+
'-p[pot name]:pot name:_pot_pots' \
162+
'-s[source]:source:_normal' \
163+
'-d[destination]:destination:_normal'
164+
;;
157165
add-file)
158166
_arguments \
159167
'-h[Show help]' \
@@ -324,6 +332,7 @@ _pot_cmds() {
324332
'promote:Promote a cloned pot -- DEPRECATED'
325333
'rename:Rename a pot'
326334
'destroy:Destroy a pot'
335+
'copy-in:Copy a file or a directory into a pot'
327336
'add-file:Add a file to a pot'
328337
'add-fscomp:Add a fs component or a directory to a pot'
329338
'add-dep:Add a dependency to a pot'

0 commit comments

Comments
 (0)