-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathenable-repo.sh
executable file
·84 lines (66 loc) · 1.86 KB
/
enable-repo.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
#!/bin/bash
repo_path="repo"
destination="dest"
apt_sources="/etc/apt/sources.list"
read_args() {
local -n map="$1"
shift
local args=("$@")
for arg in "${args[@]}"; do
local arg_name="${arg%%=*}"
if [[ "${arg:0:2}" = "--" ]]; then
local value=""
if [[ "$arg" =~ "=" ]]; then
value="${arg##*=}"
else
value="1"
fi
map["${arg_name:2}"]="$value"
fi
done
}
test_privileges() {
if [[ $EUID -ne 0 ]]; then
echo "This script must be run as root" 1>&2
exit 1
fi
}
usage() {
echo """
Usage: <enable-repo.sh> <params>,
params:
repo specify path to the directory containing repos (main, alternative)
dest specify path for repo installation (e.g., /var/distr)
Example: enable-repo.sh --repo=repo.tar.gz --dest=/var/distr
"""
}
main() {
declare -A arg_map
read_args arg_map "$@"
# globals
repos="${arg_map["$repo_path"]/"~"/"$HOME"}"
dest="${arg_map["$destination"]/"~"/"$HOME"}"
if [[ "${arg_map["help"]}" = "1" || ${#arg_map[@]} -eq 0 ]]; then
usage && exit 0
fi
test_privileges
if [[ "$repos" =~ ".gz" ]]; then
if ! tar -xzf "$repos" > /dev/null 2>&1; then
tar -xf "$repos"
fi
repos="${repos%%.*}"
echo "$repos"
fi
[[ ! ${dest:0:1} = '/' ]] && dest="$(realpath $dest)"
[[ ! -d "$dest" ]] && mkdir -p $dest > /dev/null 2>&1
for repo in $repos/*; do
echo "copying $repo to $dest..."
cp -r "$repo" "$dest"
done
echo "adding entries to $apt_sources:"
for path in $(find "$dest" -name "Packages.gz"); do
local dir="$(dirname "$path")"
echo "deb [trusted=yes] file:$dir ./" >> /etc/apt/sources.list
done
}
main "$@"