Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup of various scripts #148

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
.git
variants
.github
variants/**

.gitignore
docker-compose*.yml
variants.tar
58 changes: 4 additions & 54 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ rm -rf variants.tar variants/ 2>/dev/null >/dev/null

TAG=$(./get-version.sh)

if echo "$@" | grep -v "force" 2>/dev/null >/dev/null; then
if echo "$@" | grep -v "force" 2>/dev/null >/dev/null; then
# if there was a commit within the last hour, rebuild the container - even if it's already build
ONE_HOUR_IN_SECONDS=3600
EPOCH_SINCE_LAST_PUSH=$(git log -1 --format=%cd --date=iso | xargs -I {} date -d "{}" +%s || git log -1 --format=%cd --date=iso | xargs -I {} date -jf '%Y-%m-%d %H:%M:%S %z' "{}" +%s)
Expand All @@ -26,59 +26,9 @@ docker buildx build -q --pull --no-cache --platform "$PLATFORM" -t "$IMG:$TAG" -
echo "$@" | grep "release" 2>/dev/null >/dev/null && echo ">> releasing new latest" && docker buildx build -q --pull --platform "$PLATFORM" -t "$IMG:latest" --push .

# make sure to exit if this is only version check
echo "$@" | grep "version-check" && exit 0
echo "$@" | grep "version-check" && exit 0

# make sure this is only executed in main script
echo "$@" | grep "variant" && exit 0
echo "$@" | grep "variant" && exit 0


tar cf variants.tar --exclude .git/ --exclude variants.tar .

mkdir -p variants/smbd-only variants/smbd-avahi variants/smbd-wsdd2


cd variants/smbd-only
tar xf ../../variants.tar
cat Dockerfile | grep -v avahi | grep -v wsdd2 > Dockerfile.new
echo "ENV WSDD2_DISABLE=disabled" >> Dockerfile.new
echo "ENV AVAHI_DISABLE=disabled" >> Dockerfile.new
mv Dockerfile.new Dockerfile
rm -rf config/avahi config/runit/avahi
rm -rf config/runit/wsdd2

sed -i.bak 's/:$TAG" --push/:smbd-only-$TAG" --push/g' build.sh && rm build.sh.bak
sed -i.bak 's/:[l]atest/:smbd-only-latest/g' build.sh && rm build.sh.bak

./build.sh "variant" "$@"

cd ../../


cd variants/smbd-avahi
tar xf ../../variants.tar
cat Dockerfile | grep -v wsdd2 > Dockerfile.new
echo "ENV WSDD2_DISABLE=disabled" >> Dockerfile.new
mv Dockerfile.new Dockerfile
rm -rf config/runit/wsdd2

sed -i.bak 's/:$TAG" --push/:smbd-avahi-$TAG" --push/g' build.sh && rm build.sh.bak
sed -i.bak 's/:[l]atest/:smbd-avahi-latest/g' build.sh && rm build.sh.bak

./build.sh "variant" "$@"

cd ../../


cd variants/smbd-wsdd2
tar xf ../../variants.tar
cat Dockerfile | grep -v avahi > Dockerfile.new
echo "ENV AVAHI_DISABLE=disabled" >> Dockerfile.new
mv Dockerfile.new Dockerfile
rm -rf config/avahi config/runit/avahi

sed -i.bak 's/:$TAG" --push/:smbd-wsdd2-$TAG" --push/g' build.sh && rm build.sh.bak
sed -i.bak 's/:[l]atest/:smbd-wsdd2-latest/g' build.sh && rm build.sh.bak

./build.sh "variant" "$@"

cd ../../
./generate-variants.sh "build-image"
41 changes: 29 additions & 12 deletions generate-variants.sh
Original file line number Diff line number Diff line change
@@ -1,49 +1,66 @@
#!/bin/sh -x

tar cf variants.tar --exclude .git/ --exclude variants.tar .
tar cf variants.tar --exclude-ignore=.dockerignore .

mkdir -p variants/smbd-only variants/smbd-avahi variants/smbd-wsdd2


# create smbd-only variant
cd variants/smbd-only
tar xf ../../variants.tar
cat Dockerfile | grep -v avahi | grep -v wsdd2 > Dockerfile.new
echo "ENV WSDD2_DISABLE=disabled" >> Dockerfile.new
echo "ENV AVAHI_DISABLE=disabled" >> Dockerfile.new
mv Dockerfile.new Dockerfile
rm -rf config/avahi
rm -rf config/runit/avahi
rm -rf config/runit/wsdd2

sed -i.bak '/avahi/d' ./scripts/docker-healthcheck.sh && rm ./scripts/docker-healthcheck.sh.sh.bak
sed -i.bak '/WSD/d' ./scripts/docker-healthcheck.sh && rm ./scripts/docker-healthcheck.sh.sh.bak
sed -i '/avahi/d' ./scripts/docker-healthcheck.sh
sed -i '/WSD/d' ./scripts/docker-healthcheck.sh

sed -i.bak 's/:$TAG" --push/:smbd-only-$TAG" --push/g' build.sh && rm build.sh.bak
sed -i.bak 's/:[l]atest/:smbd-only-latest/g' build.sh && rm build.sh.bak
sed -i 's/:$TAG" --push/:smbd-only-$TAG" --push/g' build.sh
sed -i 's/:[l]atest/:smbd-only-latest/g' build.sh

cd ../../
# build variant if invocation mentions build
echo "$@" | grep "build-image" && ./build.sh "variant" "$@"

cd ../../

# create smbd-avahi variant
cd variants/smbd-avahi
tar xf ../../variants.tar
cat Dockerfile | grep -v wsdd2 > Dockerfile.new
echo "ENV WSDD2_DISABLE=disabled" >> Dockerfile.new
mv Dockerfile.new Dockerfile
rm -rf config/runit/wsdd2

sed -i.bak '/WSD/d' ./scripts/docker-healthcheck.sh && rm ./scripts/docker-healthcheck.sh.sh.bak
sed -i '/WSD/d' ./scripts/docker-healthcheck.sh

sed -i.bak 's/:$TAG" --push/:smbd-avahi-$TAG" --push/g' build.sh && rm build.sh.bak
sed -i.bak 's/:[l]atest/:smbd-avahi-latest/g' build.sh && rm build.sh.bak
sed -i 's/:$TAG" --push/:smbd-avahi-$TAG" --push/g' build.sh
sed -i 's/:[l]atest/:smbd-avahi-latest/g' build.sh

# build variant if invocation mentions build
echo "$@" | grep "build-image" && ./build.sh "variant" "$@"

cd ../../


# create smbd-wsdd2 variant
cd variants/smbd-wsdd2
tar xf ../../variants.tar
cat Dockerfile | grep -v avahi > Dockerfile.new
echo "ENV AVAHI_DISABLE=disabled" >> Dockerfile.new
mv Dockerfile.new Dockerfile
rm -rf config/avahi
rm -rf config/runit/avahi

sed -i.bak '/avahi/d' ./scripts/docker-healthcheck.sh && rm ./scripts/docker-healthcheck.sh.sh.bak
sed -i '/avahi/d' ./scripts/docker-healthcheck.sh

sed -i 's/:$TAG" --push/:smbd-wsdd2-$TAG" --push/g' build.sh
sed -i 's/:[l]atest/:smbd-wsdd2-latest/g' build.sh

sed -i.bak 's/:$TAG" --push/:smbd-wsdd2-$TAG" --push/g' build.sh && rm build.sh.bak
sed -i.bak 's/:[l]atest/:smbd-wsdd2-latest/g' build.sh && rm build.sh.bak
# build variant if invocation mentions build
echo "$@" | grep "build-image" && ./build.sh "variant" "$@"

cd ../../
26 changes: 15 additions & 11 deletions scripts/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ if [ ! -f "$INITALIZED" ]; then
echo ">> CONTAINER: starting initialisation"

cp /container/config/samba/smb.conf /etc/samba/smb.conf
cp /container/config/avahi/samba.service /etc/avahi/services/samba.service
[ ! -z ${AVAHI_DISABLE+x} ] || cp /container/config/avahi/samba.service /etc/avahi/services/samba.service

##
# MAIN CONFIGURATION
Expand Down Expand Up @@ -131,7 +131,7 @@ if [ ! -f "$INITALIZED" ]; then
echo -e "$ACCOUNT_PASSWORD\n$ACCOUNT_PASSWORD" | passwd "$ACCOUNT_NAME"
echo -e "$ACCOUNT_PASSWORD\n$ACCOUNT_PASSWORD" | smbpasswd "$ACCOUNT_NAME"
fi

smbpasswd -e "$ACCOUNT_NAME"
done

Expand Down Expand Up @@ -164,7 +164,7 @@ if [ ! -f "$INITALIZED" ]; then
[ -z ${MODEL+x} ] && MODEL="TimeCapsule"
sed -i 's/TimeCapsule/'"$MODEL"'/g' /etc/samba/smb.conf

if ! grep '<txt-record>model=' /etc/avahi/services/samba.service 2> /dev/null >/dev/null;
if [ -f /etc/avahi/services/samba.service ] && ! grep '<txt-record>model=' /etc/avahi/services/samba.service 2> /dev/null >/dev/null;
then
# remove </service-group>
sed -i '/<\/service-group>/d' /etc/avahi/services/samba.service
Expand Down Expand Up @@ -246,7 +246,7 @@ if [ ! -f "$INITALIZED" ]; then
' >> /etc/samba/smb.conf
fi

if echo "$VOL_PATH" | grep '%U$' 2>/dev/null >/dev/null;
if echo "$VOL_PATH" | grep '%U$' 2>/dev/null >/dev/null;
then
VOL_PATH_BASE=$(echo "$VOL_PATH" | sed 's,/%U$,,g')
echo " >> multiuser volume - $VOL_PATH"
Expand All @@ -260,17 +260,21 @@ if [ ! -f "$INITALIZED" ]; then
[ ! -z ${AVAHI_NAME+x} ] && echo ">> ZEROCONF: custom avahi samba.service name: $AVAHI_NAME" && sed -i 's/%h/'"$AVAHI_NAME"'/g' /etc/avahi/services/samba.service
[ ! -z ${AVAHI_NAME+x} ] && echo ">> ZEROCONF: custom avahi avahi-daemon.conf host-name: $AVAHI_NAME" && sed -i "s/#host-name=foo/host-name=${AVAHI_NAME}/" /etc/avahi/avahi-daemon.conf

echo ">> ZEROCONF: samba.service file"
echo "############################### START ####################################"
cat /etc/avahi/services/samba.service
echo "################################ END #####################################"
if [ -z ${AVAHI_DISABLE+x} ]
then
echo ">> ZEROCONF: samba.service file"
echo "############################### START ####################################"
cat /etc/avahi/services/samba.service
echo "################################ END #####################################"
else
echo ">> AVAHI - DISABLED"
rm -rf /container/config/runit/avahi
fi

[ ! -z ${WSDD2_PARAMETERS+x} ] && echo ">> WSDD2: custom parameters for wsdd2 daemon: wsdd2 $WSDD2_PARAMETERS" && sed -i 's/wsdd2/wsdd2 '"$WSDD2_PARAMETERS"'/g' /container/config/runit/wsdd2/run

[ ! -z ${WSDD2_DISABLE+x} ] && echo ">> WSDD2 - DISABLED" && rm -rf /container/config/runit/wsdd2

[ ! -z ${AVAHI_DISABLE+x} ] && echo ">> AVAHI - DISABLED" && rm -rf /container/config/runit/avahi

[ ! -z ${NETBIOS_DISABLE+x} ] && echo ">> NETBIOS - DISABLED" && rm -rf /container/config/runit/nmbd

if [ -z ${AVAHI_DISABLE+x} ] && [ ! -f "/external/avahi/not-mounted" ]
Expand All @@ -283,7 +287,7 @@ if [ ! -f "$INITALIZED" ]; then
echo ">> EXTERNAL AVAHI: list of services"
ls -l /external/avahi/*.service
fi

echo ""
echo ">> SAMBA: check smb.conf file using 'testparm -s'"
echo "############################### START ####################################"
Expand Down
Loading