-
Notifications
You must be signed in to change notification settings - Fork 0
/
pat-print-gui
executable file
·233 lines (199 loc) · 7.72 KB
/
pat-print-gui
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
#!/bin/bash
# BEFORE RUNNING:
# 1. Make sure you have a callsign logo saved in the images directory. Must be titled "CALLSIGN.png" and be 758x100px.
# 2. Edit your callsign below.
# 3. NOW you can run the program.
clear
# USER Variables
#-------- CHANGE THESE AS NEEDED --------
export CALLSIGN="UNSET" # MUST be in the pat-winlink-print/images directory, AND be a 758x120px PNG file!
#-------- THOU SHALL NOT MESSETH AROUND BELOW HERE! --------
export USERNAME=$(whoami)
APPLICATIONDIR="/home/$USERNAME/.local/share/applications/"
APPNAME="pat-print-gui"
export WORKING="/home/$USERNAME/pat-winlink-print"
export DATA="/home/$USERNAME/.local/share/pat/mailbox/$CALLSIGN"
export BUILD="build"
export WHEN=$(date)
export FILE=""
export FILEPATH=""
export FROM=""
export PREC=""
export PRECEDENCE=""
export PRINTDOC=""
export MID=""
export FROM=""
export PRECEDENCE=""
export PID=""
#-------- ROUTINES --------
# Initial part of the HTML file as a template - works better than other solutions I've tried.
template1 () {
cat <<TP1AAAA
<!DOCTYPE html>
<html>
<head>
<title>Winlink: $MID - $PRECEDENCE</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<meta http-equiv="content-type" content="application/xhtml+xml; charset=UTF-8">
<meta http-equiv="content-style-type" content="text/css">
<style type="text/css">
@import url(https://www.w3schools.com/w3css/4/w3.css);
p {
margin-left: 24px;
margin-right: 24px;
}
</style>
</head>
<body>
<br>
<div class="w3-panel w3-light-gray w3-border w3-border-black w3-center">
<p class="w3-text-white w3-xlarge" style="text-shadow:1px 1px 0 #808080"><img src="file:///$WORKING/$CALLSIGN.png" alt="$CALLSIGN" width="380px"></p>
</div>
<div class="w3-panel w3-black w3-center">
<p class="w3-text-white w3-xlarge" style="text-shadow:1px 1px 0 #808080">$PRECEDENCE de $FROM</p>
</div>
<div class="w3-container w3-border w3-border-black w3-small">
<p>
TP1AAAA
}
template2 () {
cat <<TP2AAAA
</p></div><div class="w3-container w3-border w3-border-black w3-small"><p>
TP2AAAA
}
template3 () {
cat <<TP3AAAA
</p>
</div>
<div class="w3-round-large w3-border w3-border-black w3-center w3-small">
<p>Printed $WHEN.</p>
</div>
</body>
</html>
TP3AAAA
}
desktopfile () {
cat <<DTFAAAA
[Desktop Entry]
Encoding=UTF-8
Version=1.0
Type=Application
Terminal=false
Exec=$WORKING/$APPNAME
Name=Pat Winlink Print
Icon=$WORKING/images/logo.png
DTFAAAA
}
# VERY basic initial setup
if [ ! -f $WORKING/.setupdone ];then
source $WORKING/lib/ansi.sh
ansi::bold
ansi::heading "pat-winlink-print setup for $USERNAME"
ansi::reset
ansi::fg yellow; echo "Performing initial setup."
ansi::hnline
if [ $CALLSIGN == "UNSET" ];then
ansi::bell;ansi::bell;ansi::bell
ansi::left_right "Callsign set?" "$(ansi::fg red; ansi::bold)NOT SET$(ansi::reset)" 80
ansi::bold;echo "EXITING SETUP!";ansi::reset
exit
fi
ansi::left_right "Callsign set?" "$(ansi::fg green)$CALLSIGN$(ansi::reset)" 80
if [ ! -f images/$CALLSIGN.png ];then
ansi::bell;ansi::bell;ansi::bell
ansi::left_right "Callsign logo present?" "$(ansi::fg red; ansi::bold)NOT FOUND$(ansi::reset)" 80
ansi::bold;echo "EXITING SETUP!";ansi::reset
exit
fi
ansi::left_right "Callsign logo present?" "$(ansi::fg green)FOUND$(ansi::reset)" 80
mkdir $WORKING/$BUILD
if [ ! -d $WORKING/$BUILD ];then
ansi::bell;ansi::bell;ansi::bell
ansi::left_right "Creating build directory." "$(ansi::fg red; ansi::bold)ERROR$(ansi::reset)" 80
ansi::bold;echo "Build directory not created.\nPlease create it manually via \"mkdir build\".\nEXITING SETUP!";ansi::reset
exit
fi
ansi::left_right "Creating build directory." "$(ansi::fg green)DONE$(ansi::reset)" 80
desktopfile > $APPLICATIONDIR/$APPNAME.desktop
if [ ! -f $APPLICATIONDIR/$APPNAME.desktop ];then
ansi::bell;ansi::bell;ansi::bell
ansi::left_right "Adding program to your menu." "$(ansi::fg red; ansi::bold)ERROR$(ansi::reset)" 80
ansi::bold;echo "$APPNAME.desktop was not created.\nPlease follow the instructions in \"DESKTOP\" to create it manually.\nEXITING SETUP!";ansi::reset
exit
fi
ansi::left_right "Adding program to your menu." "$(ansi::fg green)DONE$(ansi::reset)" 80
OUTPUT="file://$WORKING/$BUILD/print.html"
sed -i "s|\.FIXME\.|$OUTPUT|g" $WORKING/selenium-print.py
if [ $? != 0 ];then
ansi::bell;ansi::bell;ansi::bell
ansi::left_right "Configuring print script." "$(ansi::fg red; ansi::bold)ERROR$(ansi::reset)" 80
ansi::bold;echo "selenium-print.py was not configured.\nPlease follow the instructions in \"PRINTCONFIG\" to configure it manually.\nEXITING SETUP!";ansi::reset
exit
fi
ansi::left_right "Configuring print script." "$(ansi::fg green)DONE$(ansi::reset)" 80
ansi::hnline
ansi::left_right "Initial configuration" "$(ansi::fg green)COMPLETE$(ansi::reset)" 80
touch $WORKING/.setupdone; sleep 5s
ansi::heading "You may now start the program via the icon in your menu.\nIf you don't see it, please log out and log back in."
exit
fi
# Make the temporary build directory to hold the files needed to build the output. Skip it if it's already there.
# Select the file to print and assign to FILE
#DIR=$(dialog --title "Select the appropriate directory." --dselect "/home/jason/.local/share/pat/mailbox/WY7EMT/" "30" "50" --stdout)
#DIR="$DIR/"
cd $DATA
FILEPATH=$(zenity --title "Select a file to print." --file-selection)
FILE=$(basename "$FILEPATH")
#dialog --title "Working" --infobox "Performing our magic behind the scenes..." "15" "30"
zenity --title "Message selected!" --info --text "Click OK to continue! " "15" "30"
# Make sure that the line endings are correct for *nix
dos2unix $FILEPATH > /dev/null 2>&1
# Get the headers and write out to file
cat $FILEPATH | sed '/^$/q' | sed 's/\n/<br>/ p' > $WORKING/$BUILD/$FILE.header
# Grab the sender from the following header
export MID=$(echo $FILE | cut -f 1 -d '.')
mv $WORKING/$BUILD/$FILE.header $WORKING/$BUILD/$MID.header
export FROM=$(cat $WORKING/$BUILD/$MID.header | sed -e '1,/\=\=/ s/X\-Sonic\-Dkim\-Sign.*//' | grep From - | sed 's/From\:\ //') # From
# Grab the precendence from the following header
PREC=$(cat $WORKING/$BUILD/$MID.header | grep X-Wl2kprecedence - | awk '{print $2}' FS=": ") # Initial Precedence
# Convert precendence to all caps
export PRECEDENCE=$(echo $PREC | tr '[:lower:]' '[:upper:]')
# Remove blank lines
sed -i '/^$/d' $WORKING/$BUILD/$MID.header
# Add HTML to the end of each line
sed -i 's/$/\<br\>/' $WORKING/$BUILD/$MID.header
# Get the body and write out to file
cat $FILEPATH | tr -d '\r' | sed '1,/^$/d' > $WORKING/$BUILD/$MID.body
sed -i 's/$/\<br\>/' $WORKING/$BUILD/$MID.body
# The output filename MUST stay the same! I had to hard wire it into the python script that prints it.
template1 $MID $FROM $WORKING $CALLSIGN $PRECEDENCE > $WORKING/$BUILD/print.html
cat $WORKING/$BUILD/$MID.header >> $WORKING/$BUILD/print.html
template2 >> $WORKING/$BUILD/print.html
cat $WORKING/$BUILD/$MID.body >> $WORKING/$BUILD/print.html
template3 $WHEN >> $WORKING/$BUILD/print.html
zenity --title "Ready to print!" --info --text "Click OK to print message!"
# Print it!
$WORKING/selenium-print.py > /dev/null 2>&1
# Kill the pop-up browser window
PID=$(ps -xa | grep "firefox --marionette" | head -n1 | awk '{print $1}' FS=" ")
kill -9 $PID
zenity --title "Done!" --info --text "Click OK to end."
# Clean up the build directory
rm $WORKING/$BUILD/*
# Clean up the variables
unset CALLSIGN
unset WORKING
unset BUILD
unset FILE
unset FILEPATH
unset FROM
unset PREC
unset PRECEDENCE
unset PRINTDOC
unset MID
unset FROM
unset PRECEDENCE
unset WHEN
unset PID
unset USERNAME
unset DATA