From 48afceb7a05760676deafb8b384c2ac021d3ef6c Mon Sep 17 00:00:00 2001 From: zeus Date: Fri, 26 Mar 2021 22:32:24 +0200 Subject: [PATCH] change bash script --- swarmlabconfig/sudorun-storage-run | 24 ++++++++++++++++++++++++ swarmlabconfig/sudorun-storage-stop | 24 ++++++++++++++++++++++++ 2 files changed, 48 insertions(+) diff --git a/swarmlabconfig/sudorun-storage-run b/swarmlabconfig/sudorun-storage-run index 3d7e894..b9c9c32 100644 --- a/swarmlabconfig/sudorun-storage-run +++ b/swarmlabconfig/sudorun-storage-run @@ -1,3 +1,27 @@ +#!/bin/bash + +SOURCE="${BASH_SOURCE[0]}" +while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink + TARGET="$(readlink "$SOURCE")" + if [[ $TARGET == /* ]]; then + #echo "SOURCE '$SOURCE' is an absolute symlink to '$TARGET'" + SOURCE="$TARGET" + else + DIR="$( dirname "$SOURCE" )" + #echo "SOURCE '$SOURCE' is a relative symlink to '$TARGET' (relative to '$DIR')" + SOURCE="$DIR/$TARGET" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located + fi +done + +SRPATH="$( dirname "$SOURCE" )" +SFPATH="$( cd -P "$( dirname "$SOURCE" )" && pwd )" +if [ "$SFPATH" != "$SRPATH" ]; then + RDIR=$SRPATH # relativ path directory +fi + + +cd $SFPATH + openssl rand -base64 700 > .docker/mongodb/file.key chmod 400 .docker/mongodb/file.key sudo chown 999:999 .docker/mongodb/file.key diff --git a/swarmlabconfig/sudorun-storage-stop b/swarmlabconfig/sudorun-storage-stop index a018748..e7426cc 100644 --- a/swarmlabconfig/sudorun-storage-stop +++ b/swarmlabconfig/sudorun-storage-stop @@ -1 +1,25 @@ +#!/bin/bash + +SOURCE="${BASH_SOURCE[0]}" +while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink + TARGET="$(readlink "$SOURCE")" + if [[ $TARGET == /* ]]; then + #echo "SOURCE '$SOURCE' is an absolute symlink to '$TARGET'" + SOURCE="$TARGET" + else + DIR="$( dirname "$SOURCE" )" + #echo "SOURCE '$SOURCE' is a relative symlink to '$TARGET' (relative to '$DIR')" + SOURCE="$DIR/$TARGET" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located + fi +done + +SRPATH="$( dirname "$SOURCE" )" +SFPATH="$( cd -P "$( dirname "$SOURCE" )" && pwd )" +if [ "$SFPATH" != "$SRPATH" ]; then + RDIR=$SRPATH # relativ path directory +fi + + +cd $SFPATH + sudo chmod 777 .docker/mongodb/file.key