forked from apollo-ng/xfce-planet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
xfce-planet.sh
executable file
·189 lines (152 loc) · 6.14 KB
/
xfce-planet.sh
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
#!/bin/sh
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
BASEDIR="${HOME}/.xplanet"
################################################################################
# INIT #
################################################################################
if [ -r ${BASEDIR}/xfce-planet.conf ];
then
# Load config
. ${BASEDIR}/xfce-planet.conf
else
# Likely to be a new install
echo "Hmm, it seems, I have made it to another box... sweet :)"
echo "Let me just check if we've got everything we'll need..."
# Check Dependencies
DEPENDENCIES="awk convert dos2unix find grep unzip wget xplanet"
for i in $DEPENDENCIES;
do
echo -n "Checking for $i ... "
LOC=$(type $i 2>&1 >/dev/null)
if [ $? -eq 0 ];
then
echo "OK"
else
echo "NOT FOUND"
exit 1
fi
done
# Deploy config file from sample and load it
cp ${BASEDIR}/xfce-planet.conf.sample ${BASEDIR}/xfce-planet.conf
. ${BASEDIR}/xfce-planet.conf
echo "I've copied the sample config file to xfce-planet.conf"
fi
# Download new TLE package if local elements are older than 24h ################
if [ ! -e ${BASEDIR}/satellites/.last_updated ] || test "$(find ${BASEDIR}/satellites/.last_updated -mmin +1440)";
then
cd ${BASEDIR}/satellites/
${BASEDIR}/satellites/download-tle.sh
cd ..
fi
# Pick up the TLEs prepared by download-tle.sh in satellites/ ##################
TLE_LIST=$(find ${BASEDIR}/satellites/ -name "*.tle" | grep -v iss.tle)
TLE_COUNT=$(echo $TLE_LIST | wc -w)
COUNTER=0
DELAY_COUNT=0
################################################################################
# MAIN #
################################################################################
while true
do
# Download weather image if local copy is older than 1h ####################
if [ ! -e ${BASEDIR}/world/clouds.jpg ] || test "$(find ${BASEDIR}/world/clouds.jpg -mmin +60)";
then
cd ${BASEDIR}/world/
${BASEDIR}/world/download-clouds.sh
cd ..
fi
# Download new TLE package if local elements are older than 24h ############
if test "$(find ${BASEDIR}/satellites/.last_updated -mmin +1440)";
then
cd ${BASEDIR}/satellites/
${BASEDIR}/satellites/download-tle.sh
cd ..
fi
# Check/Link the appropriate VE/BM texture for this month ##################
MONTH=$(date +%m)
cd ${BASEDIR}/world/
if [ -e ${BASEDIR}/world/earth.jpg ];
then
LINK=$(ls -al ${BASEDIR}/world/earth.jpg | awk {'print $11;'})
MONTH_OF_FILE=$(echo $LINK | awk '{ string=substr($0, 1, 2); print string;}')
if [ "${MONTH}" != "${MONTH_OF_FILE}" ];
then
rm earth.jpg
ln -s ${MONTH}.jpg earth.jpg
fi
else
ln -s ${MONTH}.jpg earth.jpg
fi
cd ..
# Prep xplanets default config for this run ################################
LN=$(($COUNTER+1))
ABS_SATFILE=$(echo $TLE_LIST | cut -d " " -f $LN)
SATFILE=$(basename -s .tle "${ABS_SATFILE}")
echo "satellite_file=${BASEDIR}/satellites/iss" > ${BASEDIR}/default
echo "satellite_file=${BASEDIR}/satellites/${SATFILE}" >> ${BASEDIR}/default
echo "${DEFCFG}" >> ${BASEDIR}/default
# Set viewing distance according to current sat class (leo/geo)
SAT_TYPE=$(echo $SATFILE | cut -d "_" -f 2)
if [ "${SAT_TYPE}" = "geo" ];
then
VIEW=10
else
VIEW=$RAD
fi
# Switch between available tle files with a defined delay ##################
if [ ${COUNTER} -lt ${TLE_COUNT} ];
then
if [ ${DELAY_COUNT} -lt ${DELAY} ];
then
DELAY_COUNT=$(($DELAY_COUNT+1))
else
COUNTER=$((COUNTER+1))
DELAY_COUNT=0
fi
else
COUNTER=0
fi
# Call xplanet #############################################################
nice -n 19 xplanet \
-latitude ${LAT} -longitude ${LON} \
-geometry ${RES} \
-radius ${VIEW} \
-quality 90 \
-font ${FONT} \
-fontsize ${FONTSIZE} \
-starmap ${BASEDIR}/stars/BSC \
-searchdir ${BASEDIR} \
-output ${OUTPUT} \
-pango \
-num_times 1 \
-verbosity -1
# Tell the window manager to update the background image (if needed) #######
if [ "${WM_RELOAD_CMD}" != "" ];
then
${WM_RELOAD_CMD}
fi
# Go to sleep - The timeout is dynamically changed based on ACPI state
# so that a system running on battery automatically decreases the update
# frequency (longer SLEEP) to enhance battery endurance when off-grid.
if [ -r /sys/class/power_supply/AC/online ];
then
if [ $(cat /sys/class/power_supply/AC/online) -eq 1 ];
then
sleep ${SLEEP_ON_AC}
fi
else
sleep ${SLEEP_ON_BAT}
fi
done