User Tools

Site Tools


windows:hgsync

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
windows:hgsync [2021/10/20 14:38]
tschulz
windows:hgsync [2021/10/20 16:14] (current)
tschulz [userkeygen.sh]
Line 1: Line 1:
 ====== Mercurial Sync Script ====== ====== Mercurial Sync Script ======
  
-===== hgsync_login.cmd ​=====+===== Client Side =====
  
-<code batch hgsync_login.cmd>+==== merge.bat ==== 
 + 
 +<code batch merge.cmd>​ 
 +echo %1 
 +copy %1 %1.%COMPUTERNAME%.conflict 
 +del /Q %1.orig 
 +del /Q %1.orig 
 +exit 1 
 +</​code>​ 
 + 
 + 
 +==== merge_other.cmd ==== 
 + 
 +<code batch merge_other.bat>​ 
 +echo %2 
 +copy %2 %1.%COMPUTERNAME%.conflict 
 +del /Q %1.orig 
 +exit 1 
 +</​code>​ 
 + 
 + 
 +==== hgsync_login_ssh.cmd ==== 
 + 
 +<code batch hgsync_login_ssh.cmd>
 @echo off @echo off
  
Line 9: Line 32:
 set REMOTE_REPO="​h:​\Documents"​ set REMOTE_REPO="​h:​\Documents"​
 set SSH_REPO="​ssh://​%USERNAME%@sfs/​Documents"​ set SSH_REPO="​ssh://​%USERNAME%@sfs/​Documents"​
-set PATH=C:​\Progra~1\Mercurial;​C:​\Windows\System32\OpenSSH;​+set SSHHOST="​sfs"​ 
 +set PATH=C:​\Progra~1\Mercurial;​C:​\Windows\System32\OpenSSH;​C:​\Windows\System32;​ 
 + 
 + 
 + 
 +If exist "​%USERPROFILE%\.ssh\id_rsa"​ ( 
 +    If exist "​%USERPROFILE%\.ssh\known_hosts"​ ( 
 + echo SSH env ready 
 + xcopy /Y /S H:\.ssh %USERPROFILE%\.ssh\ 
 + ) else ( 
 + echo Setting up SSH env 
 + mkdir %USERPROFILE%\.ssh 
 + xcopy /Y /S H:\.ssh %USERPROFILE%\.ssh\ 
 + ssh -oStrictHostKeyChecking=no %USERNAME%@%SSHHOST% "​id"​ 
 + )  
 +) else ( 
 + echo Setting up SSH env 
 + mkdir %USERPROFILE%\.ssh 
 + xcopy /Y /S H:\.ssh %USERPROFILE%\.ssh\ 
 + ssh -oStrictHostKeyChecking=no %USERNAME%@%SSHHOST% "​id"​ 
 +)
  
 If exist "​%LOCAL_REPO%\.hg"​ ( If exist "​%LOCAL_REPO%\.hg"​ (
Line 34: Line 77:
 hg addremove hg addremove
 hg --config ui.username=%USERNAME% commit -m "​update from %COMPUTERNAME%"​ hg --config ui.username=%USERNAME% commit -m "​update from %COMPUTERNAME%"​
-hg pull  %REMOTE_REPO%+hg pull %SSH_REPO%
 hg merge -t "​W:​\scripts\merge.bat"​ hg merge -t "​W:​\scripts\merge.bat"​
 hg resolve -t internal:​other --all hg resolve -t internal:​other --all
Line 40: Line 83:
 hg addremove hg addremove
 hg --config ui.username=%USERNAME% commit -m "merge update from %COMPUTERNAME%"​ hg --config ui.username=%USERNAME% commit -m "merge update from %COMPUTERNAME%"​
-hg push  %REMOTE_REPO+hg push %SSH_REPO
-h: +echo "​remote update start" 
-cd %REMOTE_REPO% +ssh %USERNAME%@sfs "/scripts/​hgsync_login.sh
-hg --config ui.username=%USERNAME% ​commit -m "merge update from %COMPUTERNAME%"​ +echo "remote ​update ​end
-hg merge -t "W:\scripts\merge_other.bat+hg pull %SSH_REPO%
-hg resolve -t internal:​local --all +
-hg update +
-hg addremove +
-hg --config ui.username=%USERNAME% commit -m "merge update ​from %COMPUTERNAME%" +
-c: +
-cd %LOCAL_REPO% +
-hg pull  %REMOTE_REPO%+
 hg update hg update
 goto END goto END
Line 57: Line 93:
 :onlylocal :onlylocal
 Echo File exist only local Echo File exist only local
-mkdir %REMOTE_REPO% +echo "​remote init start" 
-H: +ssh %USERNAME%@sfs "/​scripts/​hgsync_init.sh"​ 
-cd %REMOTE_REPO+echo "​remote ​init end" 
-hg init +c: 
-c:+
 cd %LOCAL_REPO% cd %LOCAL_REPO%
 hg addremove hg addremove
 hg --config ui.username=%USERNAME% commit -m "​update from %COMPUTERNAME%"​ hg --config ui.username=%USERNAME% commit -m "​update from %COMPUTERNAME%"​
-hg push  %REMOTE_REPO+hg push %SSH_REPO
-H: +echo "​remote update ​start"​ 
-cd %REMOTE_REPO% +ssh %USERNAME%@sfs "/scripts/​hgsync_login.sh
-hg addremove +echo "​remote update ​end
-hg --config ui.username=%USERNAME% commit -m "​remote update ​from %COMPUTERNAME%" +hg pull %SSH_REPO%
-hg merge -t "W:\scripts\merge.bat+
-hg resolve -t internal:​other --all +
-hg update +
-hg addremove +
-hg --config ui.username=%USERNAME% commit -m "​remote ​merge update ​from %COMPUTERNAME%" +
-c: +
-cd %LOCAL_REPO% +
-hg pull  %REMOTE_REPO%+
 hg merge -t "​W:​\scripts\merge_other.bat"​ hg merge -t "​W:​\scripts\merge_other.bat"​
 hg resolve -t internal:​local --all hg resolve -t internal:​local --all
Line 83: Line 110:
 hg addremove hg addremove
 hg --config ui.username=%USERNAME% commit -m "merge update from %COMPUTERNAME%"​ hg --config ui.username=%USERNAME% commit -m "merge update from %COMPUTERNAME%"​
-hg push %REMOTE_REPO%+hg push %SSH_REPO%
 h: h:
-cd %REMOTE_REPO%+cd %SSH_REPO%
 hg update hg update
 goto END goto END
Line 94: Line 121:
 cd %LOCAL_REPO% cd %LOCAL_REPO%
 hg init hg init
-hg pull  %REMOTE_REPO%+hg pull %SSH_REPO%
 hg addremove hg addremove
 hg --config ui.username=%USERNAME% commit -m "​update from %COMPUTERNAME%"​ hg --config ui.username=%USERNAME% commit -m "​update from %COMPUTERNAME%"​
Line 102: Line 129:
 hg addremove hg addremove
 hg --config ui.username=%USERNAME% commit -m "merge update from %COMPUTERNAME%"​ hg --config ui.username=%USERNAME% commit -m "merge update from %COMPUTERNAME%"​
-hg push %REMOTE_REPO+hg push %SSH_REPO
-h: +echo "​remote update start" 
-cd %REMOTE_REPO+ssh %USERNAME%@sfs "/​scripts/​hgsync_update.sh"​ 
-hg update+echo "​remote ​update ​end"
 goto END goto END
  
Line 114: Line 141:
 cd %LOCAL_REPO% cd %LOCAL_REPO%
 hg init hg init
-mkdir %REMOTE_REPO% +echo "​remote init start" 
-H: +ssh %USERNAME%@sfs "/​scripts/​hgsync_init.sh"​ 
-cd %REMOTE_REPO+echo "​remote ​init end"
-hg init +
-c: +
-cd %LOCAL_REPO%+
 hg addremove hg addremove
 hg --config ui.username=%USERNAME% commit -m "​update from %COMPUTERNAME%"​ hg --config ui.username=%USERNAME% commit -m "​update from %COMPUTERNAME%"​
-hg push %REMOTE_REPO+hg push %SSH_REPO
-H: +echo "​remote update ​start"​ 
-cd %REMOTE_REPO% +ssh %USERNAME%@sfs "/scripts/​hgsync_logout.sh
-hg addremove +echo "​remote update ​end
-hg --config ui.username=%USERNAME% commit -m "​remote update ​from %COMPUTERNAME%" +hg pull %SSH_REPO%
-hg merge -t "W:\scripts\merge.bat+
-hg resolve -t internal:​other --all +
-hg update +
-hg addremove +
-hg --config ui.username=%USERNAME% commit -m "​remote ​merge update ​from %COMPUTERNAME%" +
-c: +
-cd %LOCAL_REPO% +
-hg pull  %REMOTE_REPO%+
 hg merge -t "​W:​\scripts\merge_other.bat"​ hg merge -t "​W:​\scripts\merge_other.bat"​
 hg resolve -t internal:​local --all hg resolve -t internal:​local --all
Line 140: Line 156:
 hg addremove hg addremove
 hg --config ui.username=%USERNAME% commit -m "merge update from %COMPUTERNAME%"​ hg --config ui.username=%USERNAME% commit -m "merge update from %COMPUTERNAME%"​
-hg push %REMOTE_REPO+hg push %SSH_REPO
-h: +echo "​remote update start" 
-cd %REMOTE_REPO+ssh %USERNAME%@sfs "/​scripts/​hgsync_update.sh"​ 
-hg update+echo "​remote ​update ​end"
 goto END goto END
  
Line 150: Line 166:
 </​code>​ </​code>​
  
-===== hgsync_logout.cmd ===== 
  
-<code batch hgsync_logout.cmd>+==== hgsync_logout_ssh.cmd ==== 
 + 
 +<code batch hgsync_logout_ssh.cmd>
 @echo off @echo off
 +
 set LOCAL_REPO="​%USERPROFILE%\Documents"​ set LOCAL_REPO="​%USERPROFILE%\Documents"​
 set REMOTE_REPO="​h:​\Documents"​ set REMOTE_REPO="​h:​\Documents"​
-set PATH=C:​\Progra~1\Mercurial;​C:​\Windows\System32\OpenSSH;​+set SSH_REPO="​ssh://​%USERNAME%@sfs/​Documents"​ 
 +set SSHHOST="​sfs"​ 
 +set PATH=C:​\Progra~1\Mercurial;​C:​\Windows\System32\OpenSSH;​C:​\Windows\System32;​ 
 + 
 +If exist "​%USERPROFILE%\.ssh\id_rsa"​ ( 
 +    If exist "​%USERPROFILE%\.ssh\known_hosts"​ ( 
 + echo SSH env ready 
 + xcopy /Y /S H:\.ssh %USERPROFILE%\.ssh\ 
 + ) else ( 
 + echo Setting up SSH env 
 + mkdir %USERPROFILE%\.ssh 
 + xcopy /Y /S H:\.ssh %USERPROFILE%\.ssh\ 
 + ssh -oStrictHostKeyChecking=no %USERNAME%@%SSHHOST% "​id"​ 
 + )  
 +) else ( 
 + echo Setting up SSH env 
 + mkdir %USERPROFILE%\.ssh 
 + xcopy /Y /S H:\.ssh %USERPROFILE%\.ssh\ 
 + ssh -oStrictHostKeyChecking=no %USERNAME%@%SSHHOST% "​id"​ 
 +)
  
 If exist "​%LOCAL_REPO%\.hg"​ ( If exist "​%LOCAL_REPO%\.hg"​ (
Line 181: Line 218:
 hg addremove hg addremove
 hg --config ui.username=%USERNAME% commit -m "​update from %COMPUTERNAME%"​ hg --config ui.username=%USERNAME% commit -m "​update from %COMPUTERNAME%"​
-hg pull  %REMOTE_REPO%+hg pull %SSH_REPO%
 hg merge -t "​W:​\scripts\merge_other.bat"​ hg merge -t "​W:​\scripts\merge_other.bat"​
 hg resolve -t internal:​local --all hg resolve -t internal:​local --all
Line 187: Line 224:
 hg addremove hg addremove
 hg --config ui.username=%USERNAME% commit -m "merge update from %COMPUTERNAME%"​ hg --config ui.username=%USERNAME% commit -m "merge update from %COMPUTERNAME%"​
-hg push  %REMOTE_REPO+hg push  %SSH_REPO
-h: +echo "​remote update start" 
-cd %REMOTE_REPO% +ssh %USERNAME%@sfs "/scripts/​hgsync_logout.sh
-hg --config ui.username=%USERNAME% ​commit -m "merge update from %COMPUTERNAME%"​ +echo "remote ​update ​end
-hg merge -t "W:\scripts\merge.bat+hg pull  %SSH_REPO%
-hg resolve -t internal:​other --all +
-hg update +
-hg addremove +
-hg --config ui.username=%USERNAME% commit -m "merge update ​from %COMPUTERNAME%" +
-c: +
-cd %LOCAL_REPO% +
-hg pull  %REMOTE_REPO%+
 hg update hg update
 goto END goto END
Line 204: Line 234:
 :onlylocal :onlylocal
 Echo File exist only local Echo File exist only local
-mkdir %REMOTE_REPO% 
-H: 
-cd %REMOTE_REPO% 
-hg init 
 c: c:
 cd %LOCAL_REPO% cd %LOCAL_REPO%
 +echo "​remote init start"
 +ssh %USERNAME%@sfs "/​scripts/​hgsync_init.sh"​
 +echo "​remote init end"
 hg addremove hg addremove
 hg --config ui.username=%USERNAME% commit -m "​update from %COMPUTERNAME%"​ hg --config ui.username=%USERNAME% commit -m "​update from %COMPUTERNAME%"​
-hg push  %REMOTE_REPO+hg push  %SSH_REPO
-H: +echo "​remote update ​start"​ 
-cd %REMOTE_REPO% +ssh %USERNAME%@sfs "/scripts/​hgsync_login.sh
-hg addremove +echo "​remote update ​end
-hg --config ui.username=%USERNAME% commit -m "​remote update ​from %COMPUTERNAME%" +hg pull  %SSH_REPO%
-hg merge -t "W:\scripts\merge.bat+
-hg resolve -t internal:​other --all +
-hg update +
-hg addremove +
-hg --config ui.username=%USERNAME% commit -m "​remote ​merge update ​from %COMPUTERNAME%" +
-c: +
-cd %LOCAL_REPO% +
-hg pull  %REMOTE_REPO%+
 hg merge -t "​W:​\scripts\merge_other.bat"​ hg merge -t "​W:​\scripts\merge_other.bat"​
 hg resolve -t internal:​local --all hg resolve -t internal:​local --all
Line 230: Line 251:
 hg addremove hg addremove
 hg --config ui.username=%USERNAME% commit -m "merge update from %COMPUTERNAME%"​ hg --config ui.username=%USERNAME% commit -m "merge update from %COMPUTERNAME%"​
-hg push %REMOTE_REPO+hg push %SSH_REPO
-h: +echo "​remote update start" 
-cd %REMOTE_REPO+ssh %USERNAME%@sfs "/​scripts/​hgsync_update.sh"​ 
-hg update+echo "​remote ​update ​end"
 goto END goto END
  
Line 241: Line 262:
 cd %LOCAL_REPO% cd %LOCAL_REPO%
 hg init hg init
-hg pull  %REMOTE_REPO%+hg pull  %SSH_REPO%
 hg addremove hg addremove
 hg --config ui.username=%USERNAME% commit -m "​update from %COMPUTERNAME%"​ hg --config ui.username=%USERNAME% commit -m "​update from %COMPUTERNAME%"​
Line 249: Line 270:
 hg addremove hg addremove
 hg --config ui.username=%USERNAME% commit -m "merge update from %COMPUTERNAME%"​ hg --config ui.username=%USERNAME% commit -m "merge update from %COMPUTERNAME%"​
-hg push %REMOTE_REPO+hg push %SSH_REPO
-h: +echo "​remote update start" 
-cd %REMOTE_REPO+ssh %USERNAME%@sfs "/​scripts/​hgsync_update.sh"​ 
-hg update+echo "​remote ​update ​end"
 goto END goto END
  
Line 261: Line 282:
 cd %LOCAL_REPO% cd %LOCAL_REPO%
 hg init hg init
-mkdir %REMOTE_REPO% +echo "​remote init start" 
-H: +ssh %USERNAME%@sfs "/​scripts/​hgsync_init.sh"​ 
-cd %REMOTE_REPO+echo "​remote ​init end"
-hg init +
-c: +
-cd %LOCAL_REPO%+
 hg addremove hg addremove
 hg --config ui.username=%USERNAME% commit -m "​update from %COMPUTERNAME%"​ hg --config ui.username=%USERNAME% commit -m "​update from %COMPUTERNAME%"​
-hg push %REMOTE_REPO+hg push %SSH_REPO
-H: +echo "​remote update ​start"​ 
-cd %REMOTE_REPO% +ssh %USERNAME%@sfs "/scripts/​hgsync_logout.sh
-hg addremove +echo "​remote update ​end
-hg --config ui.username=%USERNAME% commit -m "​remote update ​from %COMPUTERNAME%" +hg pull %SSH_REPO%
-hg merge -t "W:\scripts\merge.bat+
-hg resolve -t internal:​other --all +
-hg update +
-hg addremove +
-hg --config ui.username=%USERNAME% commit -m "​remote ​merge update ​from %COMPUTERNAME%" +
-c: +
-cd %LOCAL_REPO% +
-hg pull  %REMOTE_REPO%+
 hg merge -t "​W:​\scripts\merge_other.bat"​ hg merge -t "​W:​\scripts\merge_other.bat"​
 hg resolve -t internal:​local --all hg resolve -t internal:​local --all
Line 287: Line 297:
 hg addremove hg addremove
 hg --config ui.username=%USERNAME% commit -m "merge update from %COMPUTERNAME%"​ hg --config ui.username=%USERNAME% commit -m "merge update from %COMPUTERNAME%"​
-hg push %REMOTE_REPO+hg push %SSH_REPO
-h: +echo "​remote update start" 
-cd %REMOTE_REPO+ssh %USERNAME%@sfs "/​scripts/​hgsync_update.sh"​ 
-hg update+echo "​remote ​update ​end"
 goto END goto END
  
 :END :END
 echo done echo done
 +</​code>​
 +
 +===== Server Side =====
 +
 +==== userkeygen.sh ====
 +<code bash /​scripts/​user_keygen.sh>​
 +#!/bin/bash
 +
 +if [ "echo ${PAM_USER} | grep +" != ""​ ]
 +then
 +        TMP="​`echo ${PAM_USER} | cut -d \"​+\"​ -f2`"
 +        PAM_USER="​${TMP}"​
 +        #echo ${PAM_USER}
 +fi
 +
 +USERHOME="/​vol1/​homes/​${PAM_USER}"​
 +
 +echo "​`date` ${PAM_USER} ${USERHOME} ${PAM_SERVICE}"​ >> /​tmp/​pam_exec.log
 +
 +if [ "`ls ${USERHOME}/​.ssh/​authorized_keys`"​ = ""​ ]
 +then
 +        echo "Keys Missing"​
 +        cd ${USERHOME}
 +        mkdir .ssh
 +        cd .ssh/
 +        ssh-keygen -t rsa -N ""​ -f id_rsa
 +        cp id_rsa.pub authorized_keys
 +        chmod -R 700 ${USERHOME}
 +        chown -R ${PAM_USER} ${USERHOME}
 +
 +else
 +        echo "Keys Present"​
 +        chmod -R 700 ${USERHOME}
 +        chown -R ${PAM_USER} ${USERHOME}
 +
 +fi
 +</​code>​
 +
 +==== hgsync_init.sh ====
 +<code bash /​scripts/​hgsync_init.sh>​
 +#!/bin/sh
 +
 +mkdir -p ~/Documents
 +cd ~/Documents
 +hg init
 +</​code>​
 +
 +==== hgsync_login.sh ====
 +<code bash /​scripts/​hgsync_login.sh>​
 +#!/bin/sh
 +
 +cd ~/Documents
 +hg commit -m "merge update"​
 +hg merge -t internal:​local
 +hg update
 +hg addremove
 +hg commit -m "merge update"​
 +</​code>​
 +
 +==== hgsync_logout.sh ====
 +<code bash /​scripts/​hgsync_logout.sh>​
 +#!/bin/sh
 +
 +cd ~/Documents
 +hg commit -m "merge update"​
 +hg merge -t internal:​other
 +hg update
 +hg addremove
 +hg commit -m "merge update"​
 +</​code>​
 +
 +==== hgsync_update.sh ====
 +<code bash /​scripts/​hgsync_update.sh>​
 +#!/bin/sh
 +
 +cd ~/Documents
 +hg update
 +</​code>​
 +
 +==== /​etc/​pam.d/​common-session ====
 +<code pam/​etc/​pam.d/​common-session>​
 +...
 +session ​   required ​   pam_mkhomedir.so skel=/​etc/​skel/​ umask=0077
 +session ​   optional ​   pam_exec.so /​bin/​bash ​ /​scripts/​user_keygen.sh
 +...
 </​code>​ </​code>​
windows/hgsync.1634758721.txt.gz · Last modified: 2021/10/20 14:38 by tschulz