SMOLNET PORTAL home about changes
iAllow deleting files from a tree and SLOC halved! - drist - a remote deployment tool	Err	bitreich.org	70
hgit clone git://bitreich.org/drist/ git://enlrupgkhuxnvlhsf6lc3fziv5h2hhfrinws65d7roiv6bfj7d652fid.onion/drist/	URL:git://bitreich.org/drist/ git://enlrupgkhuxnvlhsf6lc3fziv5h2hhfrinws65d7roiv6bfj7d652fid.onion/drist/	bitreich.org	70
1Log	/scm/drist/log.gph	bitreich.org	70
1Files	/scm/drist/files.gph	bitreich.org	70
1Refs	/scm/drist/refs.gph	bitreich.org	70
1Tags	/scm/drist/tag	bitreich.org	70
1README	/scm/drist/file/README.gph	bitreich.org	70
1LICENSE	/scm/drist/file/LICENSE.gph	bitreich.org	70
i---	Err	bitreich.org	70
1commit c93097b6761dd565bbc876957c220e1fcc66b214	/scm/drist/commit/c93097b6761dd565bbc876957c220e1fcc66b214.gph	bitreich.org	70
1parent 610f7e84667a582a83b3b12af8169169503cd6f9	/scm/drist/commit/610f7e84667a582a83b3b12af8169169503cd6f9.gph	bitreich.org	70
hAuthor: Solene Rapenne <solene@perso.pw>	URL:mailto:solene@perso.pw	bitreich.org	70
iDate:   Thu, 19 Jul 2018 11:31:33 +0200	Err	bitreich.org	70
i	Err	bitreich.org	70
iAllow deleting files from a tree and SLOC halved!	Err	bitreich.org	70
i	Err	bitreich.org	70
iDiffstat:	Err	bitreich.org	70
i  M drist                               |      94 +++++++++++++++++--------------	Err	bitreich.org	70
i  M drist.1                             |      85 ++++++++++++++++++++++---------	Err	bitreich.org	70
i	Err	bitreich.org	70
i2 files changed, 111 insertions(+), 68 deletions(-)	Err	bitreich.org	70
i---	Err	bitreich.org	70
1diff --git a/drist b/drist	/scm/drist/file/drist.gph	bitreich.org	70
i@@ -1,61 +1,69 @@	Err	bitreich.org	70
i #!/bin/sh	Err	bitreich.org	70
i 	Err	bitreich.org	70
i-if [ "$#" -ne 1 ]	Err	bitreich.org	70
i-then	Err	bitreich.org	70
i+if [ "$#" -ne 1 ]; then	Err	bitreich.org	70
i         echo "You should pass a server as a parameter"	Err	bitreich.org	70
i         exit 1	Err	bitreich.org	70
i else	Err	bitreich.org	70
i         HOSTNAME=$(ssh "$1" "uname -n")	Err	bitreich.org	70
i-        if [ "$?" -ne 0 ]	Err	bitreich.org	70
i-        then	Err	bitreich.org	70
i+        if [ "$?" -ne 0 ]; then	Err	bitreich.org	70
i                 echo "Error while ssh ${1}"	Err	bitreich.org	70
i                 exit 2	Err	bitreich.org	70
i         fi	Err	bitreich.org	70
i fi	Err	bitreich.org	70
i 	Err	bitreich.org	70
i-# -l = keep symlink / -D = special device	Err	bitreich.org	70
i-if [ -d "files" ]	Err	bitreich.org	70
i-then	Err	bitreich.org	70
i-        LIST=$(mktemp /tmp/drist-rsync.XXXXXXXXXX)	Err	bitreich.org	70
i-        if [ -f "$LIST" ]	Err	bitreich.org	70
i+# $1 = directory name	Err	bitreich.org	70
i+# $2 = remote server	Err	bitreich.org	70
i+copy_files() {	Err	bitreich.org	70
i+        # -l = keep symlink / -D = special device	Err	bitreich.org	70
i+        if [ -d "${1}" ]	Err	bitreich.org	70
i         then	Err	bitreich.org	70
i-                find files/ -type f | cut -d '/' -f 2- > "${LIST}"	Err	bitreich.org	70
i-                printf 'Copying files :\n' ; cat $LIST	Err	bitreich.org	70
i-                rsync -lD --files-from="${LIST}" files/ "${1}":/	Err	bitreich.org	70
i-                rm "$LIST"	Err	bitreich.org	70
i+                LIST=$(mktemp /tmp/drist-rsync.XXXXXXXXXX)	Err	bitreich.org	70
i+                if [ -f "$LIST" ]	Err	bitreich.org	70
i+                then	Err	bitreich.org	70
i+                        printf 'Copying files:\n'	Err	bitreich.org	70
i+                        find "${1}"/ -type f | cut -d '/' -f 2- | tee "${LIST}"	Err	bitreich.org	70
i+                        rsync -lD --files-from="${LIST}" "${1}/" "${2}":/	Err	bitreich.org	70
i+                        rm "$LIST"	Err	bitreich.org	70
i+                fi	Err	bitreich.org	70
i         fi	Err	bitreich.org	70
i-fi	Err	bitreich.org	70
i+}	Err	bitreich.org	70
i 	Err	bitreich.org	70
i-if [ -d "files-${HOSTNAME}" ]	Err	bitreich.org	70
i-then	Err	bitreich.org	70
i-        LIST=$(mktemp /tmp/drist-rsync.XXXXXXXXXX)	Err	bitreich.org	70
i-        if [ -f "$LIST" ]	Err	bitreich.org	70
i+# $1 = script filename	Err	bitreich.org	70
i+# $2 = remote server	Err	bitreich.org	70
i+remote_script() {	Err	bitreich.org	70
i+        if [ -f "${1}" ]	Err	bitreich.org	70
i         then	Err	bitreich.org	70
i-                find "files-${HOSTNAME}/" -type f | cut -d '/' -f 2- > "${LIST}"	Err	bitreich.org	70
i-                printf 'Copying files only for %s:\n' "${HOSTNAME}" ; cat $LIST	Err	bitreich.org	70
i-                rsync -lD --files-from="${LIST}" "files-${HOSTNAME}/" "${1}":/	Err	bitreich.org	70
i-                rm "$LIST"	Err	bitreich.org	70
i+                printf 'Executing script\n'	Err	bitreich.org	70
i+                cat "${1}" | \	Err	bitreich.org	70
i+                        ssh "${2}" 'DRIST=$(mktemp /tmp/drist.XXXXXXXXXXXX) &&	Err	bitreich.org	70
i+                                    cat - > "$DRIST" &&	Err	bitreich.org	70
i+                                    chmod u+x "$DRIST" &&	Err	bitreich.org	70
i+                                    "$DRIST" ;	Err	bitreich.org	70
i+                                    rm "$DRIST"'	Err	bitreich.org	70
i         fi	Err	bitreich.org	70
i-fi	Err	bitreich.org	70
i+}	Err	bitreich.org	70
i 	Err	bitreich.org	70
i-if [ -f "script" ]	Err	bitreich.org	70
i-then	Err	bitreich.org	70
i-        printf 'Executing script\n'	Err	bitreich.org	70
i-        cat "script" | \	Err	bitreich.org	70
i-                ssh "${1}" 'DRIST=$(mktemp /tmp/drist.XXXXXXXXXXXX) &&	Err	bitreich.org	70
i-                            cat - > "$DRIST" &&	Err	bitreich.org	70
i-                            chmod u+x "$DRIST" &&	Err	bitreich.org	70
i-                            "$DRIST" ;	Err	bitreich.org	70
i-                            rm "$DRIST"'	Err	bitreich.org	70
i-fi	Err	bitreich.org	70
i+# $1 = directory name	Err	bitreich.org	70
i+# $2 = remote server	Err	bitreich.org	70
i+# it uses rm -v which is not POSIX compliant but most systems have it	Err	bitreich.org	70
i+delete_files() {	Err	bitreich.org	70
i+        if [ -d "${1}" ]	Err	bitreich.org	70
i+        then	Err	bitreich.org	70
i+                LIST=$(mktemp /tmp/drist-rsync.XXXXXXXXXX)	Err	bitreich.org	70
i+                if [ -f "$LIST" ]	Err	bitreich.org	70
i+                then	Err	bitreich.org	70
i+                        printf 'Removing files:\n' 	Err	bitreich.org	70
i+                        find "$1" -type f | sed 's/"/\\&/' | \	Err	bitreich.org	70
i+                                awk -v path="${1}" '{ printf "\"%s\" ",substr($0,length(path)+1)}' > "${LIST}"	Err	bitreich.org	70
i+                        ssh "$2" "rm -v $(cat $LIST)"	Err	bitreich.org	70
i+                fi	Err	bitreich.org	70
i+        fi	Err	bitreich.org	70
i+}	Err	bitreich.org	70
i 	Err	bitreich.org	70
i-if [ -f "script-${HOSTNAME}" ]	Err	bitreich.org	70
i-then	Err	bitreich.org	70
i-        printf 'Executing script only for %s:\n' "${HOSTNAME}"	Err	bitreich.org	70
i-        cat "script-${HOSTNAME}" | \	Err	bitreich.org	70
i-                ssh "${1}" 'DRIST=$(mktemp /tmp/drist.XXXXXXXXXXXX) &&	Err	bitreich.org	70
i-                            cat - > "$DRIST" &&	Err	bitreich.org	70
i-                            chmod u+x "$DRIST" &&	Err	bitreich.org	70
i-                            "$DRIST" ;	Err	bitreich.org	70
i-                            rm "$DRIST"'	Err	bitreich.org	70
i-fi	Err	bitreich.org	70
i+	Err	bitreich.org	70
i+copy_files "files" "$1"	Err	bitreich.org	70
i+copy_files "files-${HOSTNAME}" "$1"	Err	bitreich.org	70
i+remote_script "script" "$1"	Err	bitreich.org	70
i+remote_script "script-${HOSTNAME}" "$1"	Err	bitreich.org	70
i+delete_files "absent" "$1"	Err	bitreich.org	70
i+delete_files "absent-${HOSTNAME}" "$1"	Err	bitreich.org	70
1diff --git a/drist.1 b/drist.1	/scm/drist/file/drist.1.gph	bitreich.org	70
i@@ -19,43 +19,78 @@ has been designed to be simple, so it may not offer features you want.	Err	bitreich.org	70
i 	Err	bitreich.org	70
i When you run	Err	bitreich.org	70
i .Nm	Err	bitreich.org	70
i-, it will look at two special directories in the current working directory.	Err	bitreich.org	70
i+, it will look at special directories in the current working directory.	Err	bitreich.org	70
i 	Err	bitreich.org	70
i-The first is	Err	bitreich.org	70
i+The whole sequence is the following, with HOSTNAME being the result of	Err	bitreich.org	70
i+.Ql uname -n	Err	bitreich.org	70
i+on the remote system.	Err	bitreich.org	70
i+	Err	bitreich.org	70
i+.Bl -enum -offset indent -compact	Err	bitreich.org	70
i+.It	Err	bitreich.org	70
i+if folder	Err	bitreich.org	70
i .Ar files	Err	bitreich.org	70
i-and the content of this folder will be copied on the remote server	Err	bitreich.org	70
i+exists, files in it are copied on	Err	bitreich.org	70
i+.Ar server	Err	bitreich.org	70
i+.It	Err	bitreich.org	70
i+if folder	Err	bitreich.org	70
i+.Ar files-HOSTNAME	Err	bitreich.org	70
i+exists, files in it are copied on	Err	bitreich.org	70
i+.Ar server	Err	bitreich.org	70
i+.It	Err	bitreich.org	70
i+if folder	Err	bitreich.org	70
i+.Ar absent	Err	bitreich.org	70
i+exists, files in it are removed remotely on	Err	bitreich.org	70
i+.Ar server	Err	bitreich.org	70
i+.It	Err	bitreich.org	70
i+if folder	Err	bitreich.org	70
i+.Ar absent-HOSTNAME	Err	bitreich.org	70
i+exists, files in it are removed remotely on	Err	bitreich.org	70
i .Ar server	Err	bitreich.org	70
i-from the root filesystem /.	Err	bitreich.org	70
i+.It	Err	bitreich.org	70
i+if file	Err	bitreich.org	70
i+.Ar script	Err	bitreich.org	70
i+exists, it is executed remotely on	Err	bitreich.org	70
i+.Ar server	Err	bitreich.org	70
i+.It	Err	bitreich.org	70
i+if file	Err	bitreich.org	70
i+.Ar script-HOSTNAME	Err	bitreich.org	70
i+exists, it is executed remotely on	Err	bitreich.org	70
i+.Ar server	Err	bitreich.org	70
i+.El	Err	bitreich.org	70
i 	Err	bitreich.org	70
i-The second directory is	Err	bitreich.org	70
i-.Ar files-servername	Err	bitreich.org	70
i+	Err	bitreich.org	70
i+If directory	Err	bitreich.org	70
i+.Ar files	Err	bitreich.org	70
i+is present, the content of this folder will be copied on the remote server	Err	bitreich.org	70
i+.Ar server	Err	bitreich.org	70
i+from the root filesystem /. You can create	Err	bitreich.org	70
i+.Ar files-HOSTNAME	Err	bitreich.org	70
i with	Err	bitreich.org	70
i-.Ar servername	Err	bitreich.org	70
i+.Ar HOSTNAME	Err	bitreich.org	70
i being the result of the command	Err	bitreich.org	70
i .Ql uname -n	Err	bitreich.org	70
i-on the remote server. The content of this folder will be copied on the remote server	Err	bitreich.org	70
i-.Ar server	Err	bitreich.org	70
i-from the root filesystem /. This folder is useful if you need to add some files only	Err	bitreich.org	70
i-on certains servers.	Err	bitreich.org	70
i+on the remote server. The content of this foldre will be copied on the remote server	Err	bitreich.org	70
i+after the	Err	bitreich.org	70
i+.Ar files	Err	bitreich.org	70
i+directory. This folder is useful if you need to add some files only on certains servers.	Err	bitreich.org	70
i 	Err	bitreich.org	70
i After the files are copied,	Err	bitreich.org	70
i .Nm	Err	bitreich.org	70
i-will look at two files in the current working directory.	Err	bitreich.org	70
i+will look at two the folders	Err	bitreich.org	70
i+.Ar absent	Err	bitreich.org	70
i+and	Err	bitreich.org	70
i+.Ar absent-HOSTNAME	Err	bitreich.org	70
i+in the current working directory.	Err	bitreich.org	70
i+.Nm	Err	bitreich.org	70
i+will remotely delete all files listed in the tree of the directory.	Err	bitreich.org	70
i 	Err	bitreich.org	70
i-The first file is	Err	bitreich.org	70
i+Finally, the file	Err	bitreich.org	70
i .Ar script	Err	bitreich.org	70
i-and will be copied on the remote server and then executed and deleted after execution	Err	bitreich.org	70
i-(shall the script succeed or fail).	Err	bitreich.org	70
i-	Err	bitreich.org	70
i-The second file is	Err	bitreich.org	70
i-.Ar script-hostname	Err	bitreich.org	70
i-with	Err	bitreich.org	70
i-.Ar servername	Err	bitreich.org	70
i-being the result of the command	Err	bitreich.org	70
i-.Ql uname -n	Err	bitreich.org	70
i-, if it exists, it will be copied on the remote server and then executed and deleted after execution	Err	bitreich.org	70
i-(shall the script succeed or fail). This is useful if you need to run commands on a particular	Err	bitreich.org	70
i-servers.	Err	bitreich.org	70
i+be copied on the remote server and then executed and deleted after execution	Err	bitreich.org	70
i+(shall the script succeed or fail). If	Err	bitreich.org	70
i+.Ar script-HOSTNAME	Err	bitreich.org	70
i+exists, it will be procedded too in the same way. This is useful if you need 	Err	bitreich.org	70
i+to run commands on a particular servers.	Err	bitreich.org	70
i 	Err	bitreich.org	70
i I recommend to write small "modules" installing required packages for a task and providing	Err	bitreich.org	70
i the files needed rather than an all-in-one module to deploy an entire system.	Err	bitreich.org	70
.
Response: text/plain
Original URLgopher://bitreich.org/0/scm/drist/commit/c93097b6761dd565...
Content-Typetext/plain; charset=utf-8