-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit_repo.sh
More file actions
executable file
·131 lines (116 loc) · 3.58 KB
/
init_repo.sh
File metadata and controls
executable file
·131 lines (116 loc) · 3.58 KB
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
#!/bin/bash
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
function main {
init_script
error_check
create_repo
sign_repo
serve_repo
update_repo
}
# create repo from .deb packages
function create_repo {
aptly repo create \
-component="$COMPONENT" \
-distribution="$DISTRIBUTION" \
$REPO_NAME
aptly repo add $REPO_NAME /debs/
aptly publish repo \
-architectures="$ARCHITECTURES" \
-skip-signing=true \
$REPO_NAME
}
# manually sign Release file for authenticated repo if specified
# Aptly gpg2 signing is not supported so this is done manually
function sign_repo {
if [ "$GPG_ID" != "" ]
then
gpg -u $GPG_ID --batch --pinentry-mode loopback --passphrase "$GPG_PASS" \
--clearsign -o $RELEASE_PATH/InRelease $RELEASE_PATH/Release
gpg -u $GPG_ID --batch --pinentry-mode loopback --passphrase "$GPG_PASS" \
-abs -o $RELEASE_PATH/Release.gpg $RELEASE_PATH/Release
fi
}
# delete repo in order to re-publish
function drop_repo {
if [[ $(aptly publish list -raw) ]]
then
aptly publish drop $DISTRIBUTION
fi
if [[ $(aptly repo list -raw) ]]
then
aptly repo drop $REPO_NAME
fi
}
# move repo to whatever location hosting software is using
# additionally, generate and add status file for Repo
function serve_repo {
rm -r /var/www/html
mkdir /var/www/html
cp -r ~/.aptly/public/. /var/www/html/.
generate_status
}
# check for changes to .deb directory
# update repo when change is detected
function update_repo {
CHECK_DIR='debs'
stat -t $CHECK_DIR > deb_check.txt
INIT_STAT=`cat deb_check.txt`
while true; do
sleep 30
CHECK_STAT=`stat -t $CHECK_DIR`
if [ "$INIT_STAT" != "$CHECK_STAT" ]
then
drop_repo
create_repo
sign_repo
serve_repo
CHECK_STAT=`stat -t $CHECK_DIR`
INIT_STAT=`echo $CHECK_STAT`
fi
done
}
# initializes script with necessary variables and starts Apache
# also keeps track of the number of times the container restarts
# drops any pre-existing repos in case the container has restarted
function init_script {
RELEASE_PATH=~/.aptly/public/dists/$DISTRIBUTION
touch restarts.txt
RESTARTS=`cat restarts.txt`
RESTARTS=$((RESTARTS+1))
echo $RESTARTS > restarts.txt
START_TIME=`date`
/usr/sbin/apache2ctl start
drop_repo
}
# looks for issues with keys and packages
# stops container if a problem is detected and alerts the user
function error_check {
set -e
if [ ! -d /debs ]
then
echo "Mount your Debian package directory to /debs."
exit 1
fi
}
# generates repo and container status for debugging purposes
function generate_status {
echo "Last Started:" $START_TIME > status.txt
echo "Restarted:" $((RESTARTS-1)) "times" >> status.txt
echo `ls -l debs | wc -l` "packages uploaded" >> status.txt
echo "" >> status.txt
echo "Packages included in this repo:" >> status.txt
echo `ls -1 debs` >> status.txt
cp status.txt /var/www/html/.
}
main "$@"