-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtoolbox
More file actions
executable file
·74 lines (71 loc) · 2.13 KB
/
toolbox
File metadata and controls
executable file
·74 lines (71 loc) · 2.13 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
#!/usr/bin/env bash
# shellcheck disable=SC2086
# the mighty pocket protector,
# Copyright 2025 Anders F Björklund
#
# 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.
NERDCTL=${NERDCTL:-nerdctl}
TOOLBOX=${TOOLBOX:-toolbox}
DISTRO=${DISTRO:-debian}
distro=$(dirname $0)/templates/$DISTRO
image=localhost/$DISTRO-$TOOLBOX-$USER
uid=$(id -u)
gid=$(id -g | sed -e 's/20/1000/') # dialout group
user=$USER
group=$USER
home=/home/$USER.linux
shell=/bin/bash
volumes="-v $TOOLBOX:$home -v /tmp/lima:/tmp/lima"
cmd=$1
if [ -z $cmd ]; then
echo "Usage: $(basename $0) build | create | list | remove | root | rsync | run | setup | shell"
exit 1
fi
shift
case $cmd in
setup)
uid=$uid gid=$gid user=$user group=$group home=$home shell=$shell envsubst <$distro/Containerfile.in >Containerfile
cp $distro/ufetch.sh .
;;
build)
$NERDCTL build -t $image .
;;
ls|list)
$NERDCTL container ls --all --filter name=$TOOLBOX; echo
$NERDCTL images $image; echo
;;
create)
$NERDCTL create $volumes --name $TOOLBOX --hostname $TOOLBOX --init $image sleep infinity | cut -c1-12
$NERDCTL start $TOOLBOX >/dev/null
;;
enter|shell)
$NERDCTL exec -u $uid:$gid -e TERM -e COLORTERM -it $TOOLBOX "${@:-$shell}"
;;
root|sudo)
$NERDCTL exec -u 0:0 -w /root -e TERM -e COLORTERM -it $TOOLBOX "${@:-$shell}"
;;
rm|remove)
$NERDCTL stop $TOOLBOX >/dev/null
$NERDCTL rm $TOOLBOX
;;
rsync)
rsync --rsh="$NERDCTL exec -i" --info=progress2 "$@"
;;
run)
$NERDCTL run $volumes --rm -u $uid:$gid -it $image "${@:-$shell}"
;;
*)
echo "Unknown command: $cmd" >&2
exit 255
;;
esac