-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathadd-molior-repo
executable file
·120 lines (99 loc) · 3.09 KB
/
add-molior-repo
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
#!/bin/sh
. /usr/lib/molior-tools/molior.sh.inc
PROGRAM_NAME="$0"
usage()
{
ERROR_MESSAGE="$1"
echo "Usage: $PROGRAM_NAME [OPTIONS] PROJECT PROJECT_VERSION"
echo "Options:"
echo " -f Force add entry to the source.list even if compatibility checks (distribution, version, ...) fail"
echo " -m MOLIOR_URL Alternative molior url (Default in ~/.moliorrc)"
echo
echo "Example:"
echo " $PROGRAM_NAME myproject 1.2"
if [ ! -z "$ERROR_MESSAGE" ]
then
echo
echo "$ERROR_MESSAGE"
fi
exit 1
}
add_molior_project()
{
PROJECT="$1"
VERSION="$2"
APT_SOURCES="$(curl -s --retry 10 $MOLIOR_URL/api/projectsources/$PROJECT/$VERSION)"
if [ -z "$APT_SOURCES" ]
then
echo "Error downloading apt sources from '$MOLIOR_URL'"
exit 1
fi
# remove comments
APT_SOURCES=$(echo "$APT_SOURCES" | sed '/^#/d')
MIRROR=$(echo "$APT_SOURCES" | head -1)
if [ -z "$MIRROR" ]
then
echo "No APT repo found"
exit 1
fi
# add the repository key
# get the apt url from the molior api
APT_URL=$(echo $MIRROR | cut -d' ' -f 2 | cut -d/ -f 1-3)
curl -s --retry 10 $APT_URL/$PUBKEY_FILE | apt-key add - > /dev/null
# remove the mirror from the apt sources
APT_SOURCES=$(echo "${APT_SOURCES}" | tail -n +2)
# if not forced check whether the base mirror matches
if [ "$FORCE" != "yes" ]
then
OS_DISTRIBUTION=$(lsb_release --codename --short)
PROJECT_DISTRIBUTION=$(echo $MIRROR | cut -d' ' -f 2 | cut -d/ -f 4)
if [ "$OS_DISTRIBUTION" != "$PROJECT_DISTRIBUTION" ]
then
echo "Target distribution '$OS_DISTRIBUTION' does not match project distribution '$PROJECT_DISTRIBUTION'"
echo "Use the -f (force) option to overwrite"
exit 1
fi
if ! grep "$(echo $MIRROR | cut -d' ' -f 2)" /etc/apt/sources.list > /dev/null
then
echo "The current system is not based on the same base mirror."
echo "'$PROJECT@$VERSION' requires '$MIRROR'"
echo "Use the -f (force) option to overwrite"
exit 1
fi
fi
# add the required sources.list entries if they do not exist
echo "${APT_SOURCES}" | while IFS= read -r line
do
if ! grep "$line" /etc/apt/sources.list /etc/apt/sources.list.d/*.list > /dev/null
then
echo " - $line"
echo $line >> ${ROOTFS_DIRECTORY}/etc/apt/sources.list.d/molior-$(echo $line | cut -d/ -f7).list
fi
done
}
if [ "$(id -u)" != "0" ]
then
usage "Please run $0 as root"
fi
FORCE="no"
while getopts "hfm:" opt
do
case "$opt" in
h|\?) usage;;
m) MOLIOR_URL=$OPTARG; shift 2;;
f) FORCE="yes"; shift 1;;
*) break ;;
esac
done
PROJECT="$1"
VERSION="$2"
if [ -z "$PROJECT" ]
then
usage "Please specify a molior project, you can see them on $MOLIOR_URL"
fi
if [ -z "$VERSION" ]
then
echo "No project version specified, default 'next'"
VERSION="next"
fi
add_molior_project $PROJECT $VERSION