From a822e786ef08b6e2ee9e214d5fcc43ff99dbc6e3 Mon Sep 17 00:00:00 2001 From: Tobias Herre Date: Fri, 9 May 2025 16:07:49 -0400 Subject: [PATCH] Unison reactivated --- install.sh | 8 +++--- wmde-rp-include-conf.sh | 8 ++++++ wmde-rp-unison-ssh.sh | 58 ++++++++++++++----------------------- wmde-rp.conf | 64 +++++++++++++++++++++++++++++++++++++++-- 4 files changed, 94 insertions(+), 44 deletions(-) create mode 100644 wmde-rp-include-conf.sh diff --git a/install.sh b/install.sh index 53a67fc..3e13287 100755 --- a/install.sh +++ b/install.sh @@ -39,9 +39,9 @@ copy_files() { rm -rf /etc/systemd/user/default.target.wants/wmde-rp-sync.service ln -s /etc/systemd/user/wmde-rp-sync.service /etc/systemd/user/default.target.wants/wmde-rp-sync.service - cp wmde-rp-full.prf /etc - cp wmde-rp-config.prf /etc - cp wmde-rp-perm.prf /etc +# cp wmde-rp-full.prf /etc +# cp wmde-rp-config.prf /etc +# cp wmde-rp-perm.prf /etc cp wmde-rp.conf /etc git clone https://srcsrv.wikimedia.de/WMDE/osync.git /tmp/osync @@ -56,7 +56,7 @@ update_pam() { cp postlogin /etc/authselect/custom/wmde/postlogin - authselect select custom/wmde with-mkhomedir with-sudo + authselect select custom/wmde with-mkhomedir with-sudo authselect apply-changes } diff --git a/wmde-rp-include-conf.sh b/wmde-rp-include-conf.sh new file mode 100644 index 0000000..7ade7ac --- /dev/null +++ b/wmde-rp-include-conf.sh @@ -0,0 +1,8 @@ +#!/bin/sh +. /etc/wmde-rp.conf +if [ -d /etc/wmde-rp.conf.d ]; then + for file in /etc/wmde-rp.conf.d/*.conf; do + [ -f "$file" ] && . "$file" + done +fi + diff --git a/wmde-rp-unison-ssh.sh b/wmde-rp-unison-ssh.sh index 4fafe34..b712c49 100755 --- a/wmde-rp-unison-ssh.sh +++ b/wmde-rp-unison-ssh.sh @@ -14,28 +14,15 @@ set -x #echo `who am i` > /tmp/usersync-session.txt +. $PREFIX/wmde-rp-common.sh HOMEDIR=$(getent passwd "$PAM_USER" | cut -d: -f6) -SSHARGS="-o UserKnownHostsFile=$HOMEDIR/.wmdesync/known_hosts" - -. $PREFIX/wmde-rp-common.sh - -mkdir -p $HOMEDIR/.wmdesync -LASTERROR=$? -if [ $LASTERROR -ne 0 ]; then - echo $$ > $CONFIGSYNC - echo $$ > $FULLSYNC - exit $LASTERROR -fi +SSHARGS="-o UserKnownHostsFile=$WMDERPDIR/known_hosts -o ControlMaster=auto -o ControlPath=~/.ssh/cm-%r@%h:%p -o ControlPersist=10m" -#LOGFILE=$HOMEDIR/.wmdesync/usersync.log -#PIDFILE=$HOMEDIR/.wmdesync/usersync.pid -#FIRSTSYNC=$HOMEDIR/.wmdesync/firstsync-done -#FULLSYNC=$HOMEDIR/.wmdesync/fullsync-done -#CONFIGSYNC=$HOMEDIR/.wmdesync/configsync-done -. $PREFIX/wmde-rp-common.sh +create_wmderpdir + if [ -f "$PIDFILE" ]; then OLD_PID=`cat "$PIDFILE"` @@ -61,7 +48,7 @@ if [ $LASTERROR -ne 0 ]; then exit $LASTERROR fi -echo $KNOWNHOSTS > "$HOMEDIR/.wmdesync/known_hosts" +echo $KNOWNHOSTS > "$WMDERPDIR/known_hosts" LASTERROR=$? if [ $LASTERROR -ne 0 ]; then echo $$ > $CONFIGSYNC @@ -69,6 +56,7 @@ if [ $LASTERROR -ne 0 ]; then exit $LASTERROR fi + # The following creates users home directory on the nfs server if not already exists ssh $SSHARGS $PAM_USER@$NFSSERVER /usr/bin/true LASTERROR=$? @@ -85,10 +73,11 @@ IGNORES="-ignore 'Path .wmdesync'" OTHERARGS="-auto -log -prefer newer -maxerrors 500000 -fastcheck true" export UNISONLOCALHOSTNAME=`hostname` -export UNISON=$HOMEDIR/.wmdesync/unison-$UNISONLOCALHOSTNAME -WMDE_UNISON_PRF=/etc/wmde-rp-full.prf -WMDE_UNISON_CFG_PRF=/etc/wmde-rp-config.prf -WMDE_UNISON_PERM_PRF=/etc/wmde-rp-perm.prf +export UNISON=$WMDERPDIR/unison-$UNISONLOCALHOSTNAME + +#WMDE_UNISON_PRF=/etc/wmde-rp-full.prf +#WMDE_UNISON_CFG_PRF=/etc/wmde-rp-config.prf +#WMDE_UNISON_PERM_PRF=/etc/wmde-rp-perm.prf SERVERCMD="UNISONLOCALHOSTNAME=$UNISONLOCALHOSTNAME UNISON=$UNISON unison" @@ -101,6 +90,9 @@ if [ $LASTERROR -ne 0 ]; then exit $LASTERROR fi + + + # Arbeits-Directory auch auf dem SSH-Server erstellen ssh $SSHARGS $NFSSERVER "mkdir -p $UNISON" LASTERROR=$? @@ -149,24 +141,16 @@ generate_profile() { PROFILE="$UNISON/$1.prf" echo "root = $HOMEDIR" > $PROFILE echo "root = ssh://$NFSSERVER/$HOMEDIR" >> $PROFILE - cat /etc/wmde-rp-$1.prf >> $PROFILE + echo "$2" >> $PROFILE } -generate_profile full -generate_profile config -generate_profile perm - -#cp "$WMDE_UNISON_PRF" "$UNISON/full.prf"; -#cp "$WMDE_UNISON_CFG_PRF" "$UNISON/config.prf"; +generate_profile config "$UNISON_CONFIG_DIRS" +generate_profile full "$UNISON_FULL_DIRS" +generate_profile perm "$UNISON_PERM_DIRS" -# Sync config -#for item in $CONFIGDIRS; do -# CONFIGDIRSARGS="$CONFIGDIRSARGS -path $item" -#done - -yes | unison config -times -sshargs "$SSHARGS" -servercmd "$SERVERCMD" $OTHERARGS -batch -ignore 'Path .wmdesync' +yes | unison config -times -sshargs "$SSHARGS" -servercmd "$SERVERCMD" $OTHERARGS -batch #-ignore 'Path .wmde-rp' echo "PUT PID INTO CONFIG_SYNC" @@ -175,12 +159,12 @@ echo "$$" > $CONFIGSYNC echo "DONE PUT PID INTO CONFIG_SYNC" # Sync all -yes | unison full -times -sshargs "$SSHARGS" -servercmd "$SERVERCMD" $OTHERARGS -batch -ignore 'Path .wmdesync' +yes | unison full -times -sshargs "$SSHARGS" -servercmd "$SERVERCMD" $OTHERARGS -batch #-ignore 'Path $WMDERPDIRNAME' echo "$$" > $FULLSYNC echo "$$" > $FIRSTSYNC # Sync all & repeat -yes | unison perm -times -sshargs "$SSHARGS" -servercmd "$SERVERCMD" $OTHERARGS -batch -ignore 'Path .wmdesync' -repeat watch+60 +yes | unison perm -times -sshargs "$SSHARGS" -servercmd "$SERVERCMD" $OTHERARGS -batch -repeat watch+60 #-ignore 'Path $WMDERPDIRNAME' -repeat watch+60 exit 0 diff --git a/wmde-rp.conf b/wmde-rp.conf index b6ffca6..5e0511a 100644 --- a/wmde-rp.conf +++ b/wmde-rp.conf @@ -3,7 +3,7 @@ NFSSERVER=nfsserver.gs.wikimedia.de NFSHOMES=/mnt/home PREFIX=/usr/local/bin/wmde -SYNCPRG=osync +SYNCPRG=unison ADMIN_USERS="admin root" # never run roaming profiles for this users @@ -42,6 +42,64 @@ CONFIG_DIRS=" \ --include=.config/*** \ --exclude='*' \ " +UNISON_CONFIG_DIRS=$(cat << EOF +ignore = Path $WMDERPDIRNAME +path = .config +path = .local/share/backgrounds +path = .ssh +path = .cache/keepassxc +path = .thunderbird +path = .mozilla +ignore = Path Local +ignore = Path cache +ignore = Path */cache +ignore = Path .cache +ignore = Path */.cache +ignore = Path .cache2 +ignore = Path */.cache2 +ignore = Name Cache +ignore = Path */Cache +ignore = Path .thunderbird/*/ImapMail +EOF +) + +UNISON_FULL_DIRS=$(cat << EOF +ignore = Path $WMDERPDIRNAME +ignore = Path Local +ignore = Path cache +ignore = Path */cache +ignore = Path .cache +ignore = Path */.cache +ignore = Path .cache2 +ignore = Path */.cache2 +ignore = Name Cache +ignore = Path */Cache +ignore = Path .thunderbird/*/ImapMail +ignore = Path Downloads +ignore = Path VirtualBox VMs + +EOF +) + +UNISON_PERM_DIRS=$(cat << EOF +ignore = Path $WMDERPDIRNAME +ignore = Path Local +ignore = Path cache +ignore = Path */cache +ignore = Path .cache +ignore = Path */.cache +ignore = Path .cache2 +ignore = Path */.cache2 +ignore = Name Cache +ignore = Path */Cache +ignore = Path .thunderbird/*/ImapMail +ignore = Path Downloads +ignore = Path VirtualBox VMs + +EOF +) + + FULL_DIRS=" \ --exclude='$WMDERPDIRNAME' \ @@ -98,8 +156,8 @@ PERM_DIRS=" \ # .local/share/backgrounds \ # .ssh" -if [ -d /etc/meins.d ]; then - for file in /etc/meins.d/*.conf; do +if [ -d /etc/wmde-rp.d ]; then + for file in $(ls /etc/wmde-rp.d/*.conf 2>/dev/null | sort); do [ -f "$file" ] && . "$file" done fi