-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path.travis.cache
137 lines (117 loc) · 3.33 KB
/
.travis.cache
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
#!/bin/bash
set -e
##### Constants
VERSION="1.0.0"
if [[ "$OSTYPE" != "darwin"* ]]; then
BLUE='\033[1;34m'
PURPLE='\033[1;35m'
GREEN='\033[1;32m'
RED='\033[1;31m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
fi
TAG="${YELLOW}[CACHE_BOT]:${NC} "
##### Constants
##### Variables
cache=~/.cache/apt
load=0
save=0
verbose=0
##### Variables
function usage()
{
echo -e "${BLUE}Usage: ${YELLOW}[options] ...${NC}"
echo -e "${GREEN}Options:"
echo -e "${GREEN}-c, --cache ${YELLOW}Cache dir to use; defaults to ~/.cache/apt.${NC}"
echo -e "${GREEN}-s, --save ${YELLOW}Updates the cache using apts cache.${NC}"
echo -e "${GREEN}-l, --load ${YELLOW}Loads the cache.${NC}"
echo -e "${GREEN}-v, --verbose ${YELLOW}Detailed messages.${NC}"
}
while [ "$1" != "" ]; do
case $1 in
-c | --cache ) shift
cache=$1
;;
-i | --load ) load=1
;;
-s | --save ) save=1
;;
-v | --verbose ) verbose=1
;;
-h | --help ) usage
exit
;;
* ) usage
exit 1
esac
shift
done
##### Functions
function debug_print()
{
if [ "$verbose" = "1" ]; then echo -e ${TAG} "${1^}"; fi
}
function print()
{
echo -e ${TAG} "${1^}"
}
function exist()
{
[ -e "$1" ]
}
function cache_count()
{
file_count=`ls "${cache}"/*.deb | wc -l`
print "${BLUE}There are "${file_count}" packages cached${NC}"
}
function load_cache
{
print "${BLUE}Print content of "${cache}" ${NC}"
cache_count
if [ "$verbose" = "1" ]; then ls "${cache}"; fi
debug_print "${BLUE}Checking whether apt-get has no cache${NC}"
if [ "$verbose" = "1" ]; then ls /var/cache/apt/archives; fi
if exist "${cache}"/*.deb
then
debug_print "${BLUE}Start loading cache${NC}"
sudo mv "${cache}"/*.deb /var/cache/apt/archives/
if [ "$verbose" = "1" ]; then ls /var/cache/apt/archives; fi
else
print "${GREEN}Cache is empty${NC}"
fi
}
function save_cache()
{
print "${BLUE}Updating the cache${NC}"
if [ "$verbose" = "1" ]; then
cp -v /var/cache/apt/archives/*deb "${cache}"
else
cp /var/cache/apt/archives/*deb "${cache}"
fi
}
##### Functions
###################################################################
########################### Main Script ###########################
###################################################################
# 1 if save and load, which one?
if [ "$save" == "0" ] && [ "$load" == "0" ]; then
print "${GREEN}Do you want me to load or save the cache?${NC}"
exit 1;
fi
if [ "$save" == "1" ] && [ "$load" == "1" ]; then
print "${GREEN}Either save or load, not both duh!!${NC}"
exit 1;
fi
print "${BLUE}Using "${cache}" as cache directory"
# if save run save_cache
if [ "$save" == "1" ]; then
save_cache
fi;
# if load run load_cache
if [ "$load" == "1" ]; then
load_cache
fi;
###################################################################
########################### Main Script ###########################
###################################################################
exit 0;