Skip to content

Commit aa2d6a7

Browse files
committed
shfmt
Signed-off-by: Akihiro Suda <[email protected]>
1 parent 17c4a70 commit aa2d6a7

File tree

9 files changed

+172
-159
lines changed

9 files changed

+172
-159
lines changed

.github/workflows/test.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,21 @@ jobs:
3838
# https://github.com/koalaman/shellcheck/wiki/SC2086
3939
run: find . -name '*.sh' | xargs shellcheck -e SC2086
4040

41+
shfmt:
42+
runs-on: ubuntu-20.04
43+
timeout-minutes: 20
44+
steps:
45+
- uses: actions/setup-go@v2
46+
with:
47+
go-version: 1.16.x
48+
- uses: actions/checkout@v2
49+
with:
50+
fetch-depth: 1
51+
- name: Install shfmt
52+
run: GO111MODULE=on go get mvdan.cc/sh/v3/cmd/shfmt
53+
- name: Run shfmt
54+
run: find . -name '*.sh' | xargs shfmt -s -d
55+
4156
basic:
4257
name: Basic tests
4358
runs-on: ${{ matrix.os }}

hack/test-example.sh

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ function ERROR() {
1313
echo >&2 "TEST| [ERROR] $*"
1414
}
1515

16-
if [[ "${BASH_VERSINFO:-0}" -lt 4 ]]; then
16+
if [[ ${BASH_VERSINFO:-0} -lt 4 ]]; then
1717
ERROR "Bash version is too old: ${BASH_VERSION}"
1818
exit 1
1919
fi
@@ -74,21 +74,21 @@ limactl shell "$NAME" uname -a
7474
limactl shell "$NAME" cat /etc/os-release
7575
set +x
7676

77-
if [[ -n "${CHECKS["systemd"]}" ]]; then
77+
if [[ -n ${CHECKS["systemd"]} ]]; then
7878
set -x
7979
if ! limactl shell "$NAME" systemctl is-system-running --wait; then
80-
ERROR "\"systemctl is-system-running\" failed"
80+
ERROR '"systemctl is-system-running" failed'
8181
limactl shell "$NAME" systemctl
82-
if [[ -z "${CHECKS["systemd-strict"]}" ]]; then
83-
INFO "Ignoring \"systemctl is-system-running\" failure"
82+
if [[ -z ${CHECKS["systemd-strict"]} ]]; then
83+
INFO 'Ignoring "systemctl is-system-running" failure'
8484
else
8585
exit 1
8686
fi
8787
fi
8888
set +x
8989
fi
9090

91-
if [[ -n "${CHECKS["mount-home"]}" ]]; then
91+
if [[ -n ${CHECKS["mount-home"]} ]]; then
9292
hometmp="$HOME/lima-test-tmp"
9393
INFO "Testing home access (\"$hometmp\")"
9494
rm -rf "$hometmp"
@@ -104,7 +104,7 @@ if [[ -n "${CHECKS["mount-home"]}" ]]; then
104104
fi
105105
fi
106106

107-
if [[ -n "${CHECKS["containerd-user"]}" ]]; then
107+
if [[ -n ${CHECKS["containerd-user"]} ]]; then
108108
INFO "Run a nginx container with port forwarding 127.0.0.1:8080"
109109
set -x
110110
limactl shell "$NAME" nerdctl info
@@ -119,7 +119,7 @@ if [[ -n "${CHECKS["containerd-user"]}" ]]; then
119119
set +x
120120
fi
121121

122-
if [[ -n "${CHECKS["restart"]}" ]]; then
122+
if [[ -n ${CHECKS["restart"]} ]]; then
123123
INFO "Create file in the guest home directory and verify that it still exists after a restart"
124124
# shellcheck disable=SC2016
125125
limactl shell "$NAME" sh -c 'touch $HOME/sweet-home'

pkg/cidata/cidata.TEMPLATE.d/boot.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
#!/bin/sh
22
set -eu
33

4-
INFO(){
5-
echo "LIMA| $*"
4+
INFO() {
5+
echo "LIMA| $*"
66
}
77

8-
WARNING(){
9-
echo "LIMA| WARNING: $*"
8+
WARNING() {
9+
echo "LIMA| WARNING: $*"
1010
}
1111

1212
# shellcheck disable=SC2163

pkg/cidata/cidata.TEMPLATE.d/boot/05-persistent-data-volume.sh

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -12,40 +12,40 @@ DATADIRS="/home /usr/local /etc/containerd /var/lib/containerd"
1212
# When running from RAM try to move persistent data to data-volume
1313
# FIXME: the test for tmpfs mounts is probably Alpine-specific
1414
if [ "$(awk '$2 == "/" {print $3}' /proc/mounts)" == "tmpfs" ]; then
15-
mkdir -p /mnt/data
16-
if [ -e /dev/disk/by-label/data-volume ]; then
17-
mount -t ext4 /dev/disk/by-label/data-volume /mnt/data
18-
else
19-
# Find an unpartitioned disk and create data-volume
20-
DISKS=$(lsblk --list --noheadings --output name,type | awk '$2 == "disk" {print $1}')
21-
for DISK in ${DISKS}; do
22-
IN_USE=false
23-
# Looking for a disk that is not mounted or partitioned
24-
# shellcheck disable=SC2013
25-
for PART in $(awk '/^\/dev\// {gsub("/dev/", ""); print $1}' /proc/mounts); do
26-
if [ "${DISK}" == "${PART}" ] || [ -e /sys/block/${DISK}/${PART} ]; then
27-
IN_USE=true
28-
break
29-
fi
30-
done
31-
if [ "${IN_USE}" == "false" ]; then
32-
echo 'type=83' | sfdisk --label dos /dev/${DISK}
33-
PART=$(lsblk --list /dev/${DISK} --noheadings --output name,type | awk '$2 == "part" {print $1}')
34-
mkfs.ext4 -L data-volume /dev/${PART}
35-
mount -t ext4 /dev/disk/by-label/data-volume /mnt/data
36-
for DIR in ${DATADIRS}; do
37-
DEST="/mnt/data$(dirname ${DIR})"
38-
mkdir -p ${DIR} ${DEST}
39-
mv ${DIR} ${DEST}
40-
done
41-
break
42-
fi
43-
done
44-
fi
45-
for DIR in ${DATADIRS}; do
46-
if [ -d /mnt/data${DIR} ]; then
47-
[ -e ${DIR} ] && rm -rf ${DIR}
48-
ln -s /mnt/data${DIR} ${DIR}
49-
fi
50-
done
15+
mkdir -p /mnt/data
16+
if [ -e /dev/disk/by-label/data-volume ]; then
17+
mount -t ext4 /dev/disk/by-label/data-volume /mnt/data
18+
else
19+
# Find an unpartitioned disk and create data-volume
20+
DISKS=$(lsblk --list --noheadings --output name,type | awk '$2 == "disk" {print $1}')
21+
for DISK in ${DISKS}; do
22+
IN_USE=false
23+
# Looking for a disk that is not mounted or partitioned
24+
# shellcheck disable=SC2013
25+
for PART in $(awk '/^\/dev\// {gsub("/dev/", ""); print $1}' /proc/mounts); do
26+
if [ "${DISK}" == "${PART}" ] || [ -e /sys/block/${DISK}/${PART} ]; then
27+
IN_USE=true
28+
break
29+
fi
30+
done
31+
if [ "${IN_USE}" == "false" ]; then
32+
echo 'type=83' | sfdisk --label dos /dev/${DISK}
33+
PART=$(lsblk --list /dev/${DISK} --noheadings --output name,type | awk '$2 == "part" {print $1}')
34+
mkfs.ext4 -L data-volume /dev/${PART}
35+
mount -t ext4 /dev/disk/by-label/data-volume /mnt/data
36+
for DIR in ${DATADIRS}; do
37+
DEST="/mnt/data$(dirname ${DIR})"
38+
mkdir -p ${DIR} ${DEST}
39+
mv ${DIR} ${DEST}
40+
done
41+
break
42+
fi
43+
done
44+
fi
45+
for DIR in ${DATADIRS}; do
46+
if [ -d /mnt/data${DIR} ]; then
47+
[ -e ${DIR} ] && rm -rf ${DIR}
48+
ln -s /mnt/data${DIR} ${DIR}
49+
fi
50+
done
5151
fi

pkg/cidata/cidata.TEMPLATE.d/boot/10-alpine-prep.sh

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@ test -f /etc/alpine-release || exit 0
88
BRANCH=edge
99
VERSION_ID=$(awk -F= '$1=="VERSION_ID" {print $2}' /etc/os-release)
1010
case ${VERSION_ID} in
11-
*_alpha*|*_beta*) BRANCH=edge;;
12-
*.*.*) BRANCH=v${VERSION_ID%.*};;
11+
*_alpha* | *_beta*) BRANCH=edge ;;
12+
*.*.*) BRANCH=v${VERSION_ID%.*} ;;
1313
esac
1414

1515
for REPO in main community; do
16-
URL="https://dl-cdn.alpinelinux.org/alpine/${BRANCH}/${REPO}"
17-
if ! grep -q "^${URL}$" /etc/apk/repositories; then
18-
echo "${URL}" >> /etc/apk/repositories
19-
fi
16+
URL="https://dl-cdn.alpinelinux.org/alpine/${BRANCH}/${REPO}"
17+
if ! grep -q "^${URL}$" /etc/apk/repositories; then
18+
echo "${URL}" >>/etc/apk/repositories
19+
fi
2020
done
2121

2222
# Alpine doesn't use PAM so we need to explicitly allow public key auth

pkg/cidata/cidata.TEMPLATE.d/boot/20-rootless-base.sh

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ command -v systemctl >/dev/null 2>&1 || exit 0
66

77
# Set up env
88
for f in .profile .bashrc; do
9-
if ! grep -q "# Lima BEGIN" "/home/${LIMA_CIDATA_USER}.linux/$f"; then
10-
cat >>"/home/${LIMA_CIDATA_USER}.linux/$f" <<EOF
9+
if ! grep -q "# Lima BEGIN" "/home/${LIMA_CIDATA_USER}.linux/$f"; then
10+
cat >>"/home/${LIMA_CIDATA_USER}.linux/$f" <<EOF
1111
# Lima BEGIN
1212
# Make sure iptables and mount.fuse3 are available
1313
PATH="$PATH:/usr/sbin:/sbin"
@@ -16,13 +16,13 @@ CONTAINERD_SNAPSHOTTER="fuse-overlayfs"
1616
export PATH CONTAINERD_SNAPSHOTTER
1717
# Lima END
1818
EOF
19-
chown "${LIMA_CIDATA_USER}" "/home/${LIMA_CIDATA_USER}.linux/$f"
20-
fi
19+
chown "${LIMA_CIDATA_USER}" "/home/${LIMA_CIDATA_USER}.linux/$f"
20+
fi
2121
done
2222
# Enable cgroup delegation (only meaningful on cgroup v2)
2323
if [ ! -e "/etc/systemd/system/[email protected]/lima.conf" ]; then
24-
mkdir -p "/etc/systemd/system/[email protected]"
25-
cat >"/etc/systemd/system/[email protected]/lima.conf" <<EOF
24+
mkdir -p "/etc/systemd/system/[email protected]"
25+
cat >"/etc/systemd/system/[email protected]/lima.conf" <<EOF
2626
[Service]
2727
Delegate=yes
2828
EOF
@@ -32,17 +32,17 @@ systemctl daemon-reload
3232
# Set up sysctl
3333
sysctl_conf="/etc/sysctl.d/99-lima.conf"
3434
if [ ! -e "${sysctl_conf}" ]; then
35-
if [ -e "/proc/sys/kernel/unprivileged_userns_clone" ]; then
36-
echo "kernel.unprivileged_userns_clone=1" >> "${sysctl_conf}"
37-
fi
38-
echo "net.ipv4.ping_group_range = 0 2147483647" >> "${sysctl_conf}"
39-
echo "net.ipv4.ip_unprivileged_port_start=0" >> "${sysctl_conf}"
40-
sysctl --system
35+
if [ -e "/proc/sys/kernel/unprivileged_userns_clone" ]; then
36+
echo "kernel.unprivileged_userns_clone=1" >>"${sysctl_conf}"
37+
fi
38+
echo "net.ipv4.ping_group_range = 0 2147483647" >>"${sysctl_conf}"
39+
echo "net.ipv4.ip_unprivileged_port_start=0" >>"${sysctl_conf}"
40+
sysctl --system
4141
fi
4242

4343
# Set up subuid
4444
for f in /etc/subuid /etc/subgid; do
45-
grep -qw "${LIMA_CIDATA_USER}" $f || echo "${LIMA_CIDATA_USER}:100000:65536" >> $f
45+
grep -qw "${LIMA_CIDATA_USER}" $f || echo "${LIMA_CIDATA_USER}:100000:65536" >>$f
4646
done
4747

4848
# Start systemd session

pkg/cidata/cidata.TEMPLATE.d/boot/25-guestagent-base.sh

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,23 @@ set -eux
44
# Create mount points
55
# NOTE: Busybox sh does not support `for ((i=0;i<$N;i++))` form
66
for f in $(seq 0 $((LIMA_CIDATA_MOUNTS - 1))); do
7-
mountpointvar="LIMA_CIDATA_MOUNTS_${f}_MOUNTPOINT"
8-
mountpoint="$(eval echo \$$mountpointvar)"
9-
mkdir -p "${mountpoint}"
10-
chown "${LIMA_CIDATA_USER}" "${mountpoint}"
7+
mountpointvar="LIMA_CIDATA_MOUNTS_${f}_MOUNTPOINT"
8+
mountpoint="$(eval echo \$$mountpointvar)"
9+
mkdir -p "${mountpoint}"
10+
chown "${LIMA_CIDATA_USER}" "${mountpoint}"
1111
done
1212

1313
# Install or update the guestagent binary
1414
install -m 755 "${LIMA_CIDATA_MNT}"/lima-guestagent /usr/local/bin/lima-guestagent
1515

1616
# Launch the guestagent service
1717
if [ -f /etc/alpine-release ]; then
18-
# Create directory for the lima-guestagent socket (normally done by systemd)
19-
mkdir -p /run/user/${LIMA_CIDATA_UID}
20-
chown "${LIMA_CIDATA_USER}" /run/user/${LIMA_CIDATA_UID}
21-
chmod 700 /run/user/${LIMA_CIDATA_UID}
22-
# Install the openrc lima-guestagent service script
23-
cat >/etc/init.d/lima-guestagent <<'EOF'
18+
# Create directory for the lima-guestagent socket (normally done by systemd)
19+
mkdir -p /run/user/${LIMA_CIDATA_UID}
20+
chown "${LIMA_CIDATA_USER}" /run/user/${LIMA_CIDATA_UID}
21+
chmod 700 /run/user/${LIMA_CIDATA_UID}
22+
# Install the openrc lima-guestagent service script
23+
cat >/etc/init.d/lima-guestagent <<'EOF'
2424
#!/sbin/openrc-run
2525
supervisor=supervise-daemon
2626
@@ -34,11 +34,11 @@ command_background=true
3434
command_user="${LIMA_CIDATA_USER}:${LIMA_CIDATA_USER}"
3535
pidfile="${XDG_RUNTIME_DIR}/lima-guestagent.pid"
3636
EOF
37-
chmod 755 /etc/init.d/lima-guestagent
37+
chmod 755 /etc/init.d/lima-guestagent
3838

39-
rc-update add lima-guestagent default
40-
rc-service lima-guestagent start
39+
rc-update add lima-guestagent default
40+
rc-service lima-guestagent start
4141
else
42-
until [ -e "/run/user/${LIMA_CIDATA_UID}/systemd/private" ]; do sleep 3; done
43-
sudo -iu "${LIMA_CIDATA_USER}" "XDG_RUNTIME_DIR=/run/user/${LIMA_CIDATA_UID}" lima-guestagent install-systemd
42+
until [ -e "/run/user/${LIMA_CIDATA_UID}/systemd/private" ]; do sleep 3; done
43+
sudo -iu "${LIMA_CIDATA_USER}" "XDG_RUNTIME_DIR=/run/user/${LIMA_CIDATA_UID}" lima-guestagent install-systemd
4444
fi
Lines changed: 42 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,52 @@
11
#!/bin/sh
22
set -eux
33

4-
update_fuse_conf(){
5-
# Modify /etc/fuse.conf to allow "-o allow_root"
6-
if [ "${LIMA_CIDATA_MOUNTS}" -gt 0 ]; then
7-
if ! grep -q "^user_allow_other" /etc/fuse.conf ; then
8-
echo "user_allow_other" >> /etc/fuse.conf
9-
fi
10-
fi
4+
update_fuse_conf() {
5+
# Modify /etc/fuse.conf to allow "-o allow_root"
6+
if [ "${LIMA_CIDATA_MOUNTS}" -gt 0 ]; then
7+
if ! grep -q "^user_allow_other" /etc/fuse.conf; then
8+
echo "user_allow_other" >>/etc/fuse.conf
9+
fi
10+
fi
1111
}
1212

1313
# Install minimum dependencies
1414
if command -v apt-get >/dev/null 2>&1; then
15-
DEBIAN_FRONTEND=noninteractive
16-
export DEBIAN_FRONTEND
17-
apt-get update
18-
if [ "${LIMA_CIDATA_MOUNTS}" -gt 0 ]; then
19-
apt-get install -y sshfs
20-
update_fuse_conf
21-
fi
22-
if [ "${LIMA_CIDATA_CONTAINERD_SYSTEM}" = 1 ] || [ "${LIMA_CIDATA_CONTAINERD_USER}" = 1 ]; then
23-
apt-get install -y iptables
24-
fi
25-
if [ "${LIMA_CIDATA_CONTAINERD_USER}" = 1 ]; then
26-
apt-get install -y uidmap fuse3 dbus-user-session
27-
fi
15+
DEBIAN_FRONTEND=noninteractive
16+
export DEBIAN_FRONTEND
17+
apt-get update
18+
if [ "${LIMA_CIDATA_MOUNTS}" -gt 0 ]; then
19+
apt-get install -y sshfs
20+
update_fuse_conf
21+
fi
22+
if [ "${LIMA_CIDATA_CONTAINERD_SYSTEM}" = 1 ] || [ "${LIMA_CIDATA_CONTAINERD_USER}" = 1 ]; then
23+
apt-get install -y iptables
24+
fi
25+
if [ "${LIMA_CIDATA_CONTAINERD_USER}" = 1 ]; then
26+
apt-get install -y uidmap fuse3 dbus-user-session
27+
fi
2828
elif command -v dnf >/dev/null 2>&1; then
29-
if [ "${LIMA_CIDATA_MOUNTS}" -gt 0 ]; then
30-
dnf install -y fuse-sshfs
31-
update_fuse_conf
32-
fi
33-
if [ "${LIMA_CIDATA_CONTAINERD_SYSTEM}" = 1 ] || [ "${LIMA_CIDATA_CONTAINERD_USER}" = 1 ]; then
34-
dnf install -y iptables
35-
fi
36-
if [ "${LIMA_CIDATA_CONTAINERD_USER}" = 1 ]; then
37-
dnf install -y shadow-utils fuse3
38-
if [ ! -f /usr/bin/fusermount ]; then
39-
# Workaround for https://github.com/containerd/stargz-snapshotter/issues/340
40-
ln -s fusermount3 /usr/bin/fusermount
41-
fi
42-
fi
29+
if [ "${LIMA_CIDATA_MOUNTS}" -gt 0 ]; then
30+
dnf install -y fuse-sshfs
31+
update_fuse_conf
32+
fi
33+
if [ "${LIMA_CIDATA_CONTAINERD_SYSTEM}" = 1 ] || [ "${LIMA_CIDATA_CONTAINERD_USER}" = 1 ]; then
34+
dnf install -y iptables
35+
fi
36+
if [ "${LIMA_CIDATA_CONTAINERD_USER}" = 1 ]; then
37+
dnf install -y shadow-utils fuse3
38+
if [ ! -f /usr/bin/fusermount ]; then
39+
# Workaround for https://github.com/containerd/stargz-snapshotter/issues/340
40+
ln -s fusermount3 /usr/bin/fusermount
41+
fi
42+
fi
4343
elif command -v apk >/dev/null 2>&1; then
44-
if [ "${LIMA_CIDATA_MOUNTS}" -gt 0 ]; then
45-
if ! command -v sshfs >/dev/null 2>&1; then
46-
apk update
47-
apk add sshfs
48-
fi
49-
update_fuse_conf
50-
modprobe fuse
51-
fi
44+
if [ "${LIMA_CIDATA_MOUNTS}" -gt 0 ]; then
45+
if ! command -v sshfs >/dev/null 2>&1; then
46+
apk update
47+
apk add sshfs
48+
fi
49+
update_fuse_conf
50+
modprobe fuse
51+
fi
5252
fi
53-

0 commit comments

Comments
 (0)