forked from tuna/tunasync-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrubygems.sh
executable file
·49 lines (40 loc) · 881 Bytes
/
rubygems.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
#!/bin/bash
GEM=${GEM:-"gem"}
export HOME="/tmp/rubygems"
CONF="$HOME/.gem/.mirrorrc"
mkdir -p "$HOME/.gem"
INIT=${INIT:-"0"}
BUSYBOX=${BUSYBOX:-"0"}
if [ ! -d "$TUNASYNC_WORKING_DIR" ]; then
mkdir -p $TUNASYNC_WORKING_DIR
INIT="1"
fi
echo "Syncing to $TUNASYNC_WORKING_DIR"
cat > $CONF << EOF
---
- from: https://rubygems.org
to: ${TUNASYNC_WORKING_DIR}
parallelism: 10
retries: 2
delete: true
skiperror: true
EOF
if [[ $INIT == "0" ]]; then
if [[ $BUSYBOX == "0" ]]; then
timeout -s INT 7200 $GEM mirror -V
else
timeout -t 7200 -s INT $GEM mirror -V
fi
else
$GEM mirror -V
fi
ret=$?
if [[ $ret == 124 ]]; then
echo 'Sync timeout (/_\\)'
fi
if [[ $ret == 0 ]]; then
curl -fsSL https://rubygems.org/versions > "$TUNASYNC_WORKING_DIR/.versions.new" && \
mv "$TUNASYNC_WORKING_DIR/.versions.new" "$TUNASYNC_WORKING_DIR/versions"
ret=$?
fi
exit $ret