-
Notifications
You must be signed in to change notification settings - Fork 1
/
pragma-askpass
executable file
·73 lines (59 loc) · 2.22 KB
/
pragma-askpass
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/bin/bash
# Home dir
if [ -z ${SYSTEMDRIVE+x} ]
then
# Mac or Linux
TMP="$HOME/.Pragma-git/.tmp"
echo "Mac or Linux" > "$TMP/askpasslog.txt"
env >> "$TMP/askpasslog.txt"
echo $(pwd) > "$TMP/repo_path"
echo "TMP=$TMP" >> "$TMP/askpasslog.txt"
else
# Windows
TMP="$USERPROFILE/.Pragma-git/.tmp"
echo "WINDOWS" > "$TMP/askpasslog.txt"
env >> "$TMP/askpasslog.txt"
echo $(pwd -W) > "$TMP/repo_path"
echo "TMP=$TMP" >> "$TMP/askpasslog.txt"
fi
echo $@ >> "$TMP/askpasslog.txt"
mkdir "$TMP" 2>/dev/null
MAINSIGNALFILE="$TMP/pragma-git-running" # Pragma-git running (needed to show dialog)
RUNNING="$TMP/pragma-askpass-running" # Pragma-git looks for this file, and starts askpass
EXIT="$TMP/exit-pragma-askpass" # Pragma-git closing saves exit-code here, which is transferred to exit code of this script
EXITMESSAGEFILE="$TMP/exit-message-pragma-askpass" # Message to print to stdout
# Bail out if pragma-git not running
if [ ! -f "$MAINSIGNALFILE" ] ; then
echo " " >> "$TMP/askpass.txt"
echo "$(date) Attempt to open pragma-askpass, but pragma-git not running : $TMP/pragma-git-running)" >> "$TMP/askpass.txt"
echo "$(date) Bail out, require pragma-git to be up" >> "$TMP/askpass.txt"
exit
fi
# Bail out if askpass already running
if [ -f "$RUNNING" ] ; then
echo " " >> "$TMP/askpass.txt"
echo "$(date) Attempt to open pragma-askpass, already open (indicated by existence of file : $TMP/pragma-askpass-running)" >> "$TMP/askpass.txt"
echo "$(date) Bail out, already open (indicated by existence of file : $TMP/pragma-askpass-running)" >> "$TMP/askpass.txt"
exit
fi
# Store input parameters for Pragma-git to pick them up (nothing here)
echo $1 > "$TMP/askpass_first"
# Run Pragma-askpass while $RUNNING exists (removed by Pragma-askpass when closed)
touch "$RUNNING"
while [ -f "$RUNNING" ]
do
sleep 1
done
# Exited Pragma-askpass
EXITCODE=$(cat "$EXIT")
rm "$EXIT"
# Print to stdout
echo $(cat "$EXITMESSAGEFILE")
# Clean up
rm "$EXITMESSAGEFILE"
rm "$TMP/askpass_first"
# Log
echo " " >> "$TMP/askpasslog.txt"
echo "$(date) EXIT pragma-askpass" >> "$TMP/askpass.txt"
echo "$(date) EXIT_CODE = $EXITCODE" >> "$TMP/askpass.txt"
exit $EXITCODE