-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathinstall-package
executable file
·124 lines (91 loc) · 2.69 KB
/
install-package
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
#!/bin/bash
# Package installer with caching, version 2.2
show_usage_and_exit() {
echo -e "Package installer that caches packages\n"
echo -e "Usage: install-package [--update] [--skip-update] [--update-new] pkg1[=version] [pkg2[=version]] [-o APT::Option] ...\n"
echo "--update Forces repository list update before installing the packages"
echo "--skip-update Skips repository list update"
echo "--update-new Update only repository lists added in the last 1h"
exit 1
}
skip_global_update() {
touch "$apt_update_ran"
}
update_repo_lists() {
echo ">> Updating repository lists and keys..."
sudo apt-key update
sudo apt-get update
skip_global_update
}
install_packages() {
echo ">> Installing packages..."
sudo apt-get install -y --force-yes -o Dir::Cache::archives="$temp_deb_store" "${packages[@]}"
}
unpack_pkg_archive_if_available() {
echo ">> Unpacking package archive..."
cache restore install_package_cache
skip_global_update
}
archive_packages() {
echo ">> Storing packages in archive..."
sudo chown "$USER" -R "$temp_deb_store"
cache store install_package_cache "$temp_deb_store"
}
init() {
deb_cache_base_name=".deb-cache"
temp_deb_store="/home/$(whoami)/$deb_cache_base_name"
apt_update_ran="/tmp/.apt_update_ran"
mkdir -p "$temp_deb_store"
}
run_selective_update() {
recently_modified_lists=$(find /etc/apt/sources.list.d/ -name "*.list" -type f -mmin -59)
if [ -n "${recently_modified_lists}" ]; then
for list in $recently_modified_lists; do
echo "* pulling from: $list"
sudo apt-get update -o Dir::Etc::sourcelist="$list" -o Dir::Etc::sourceparts="-" -o APT::Get::List-Cleanup="0"
done
else
echo "* no PPA list found which is modified in the last hour"
fi
}
# Show usage and exit if no arguments provided
[[ $# -eq 0 ]] && show_usage_and_exit
init
unpack_pkg_archive_if_available
POSITIONAL=()
while [ $# -gt 0 ]; do
case "$1" in
--skip-update | -s )
echo "* global package lists will not be updated"
skip_global_update
shift
;;
--update | -u )
echo "* global package list update will run"
rm -f $apt_update_ran
shift
;;
--update-new | -n )
echo "* only the recent package lists will be updated"
skip_global_update
run_selective_update
shift
;;
* )
POSITIONAL+=("$1")
shift
;;
esac
done
set -- "${POSITIONAL[@]}"
# Run apt-get update if flag is not set
[[ ! -f $apt_update_ran ]] && update_repo_lists
packages=("$@")
if install_packages;then
if archive_packages;then
echo ">> Finished successfully."
fi
else
echo ">> Errors have occured during package installation."
exit 1
fi