-
Notifications
You must be signed in to change notification settings - Fork 0
/
entrypoint.sh
executable file
·130 lines (106 loc) · 3.65 KB
/
entrypoint.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
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
#!/bin/bash
set -e
#set -x
cd /data
# function that will build .deb files in specific folder
function build_deb {
echo "Build .deb files for repo $1"
cd src/$1
base_dir=$(pwd)
# iterate through all folders in src/$1
for folder in $(ls); do
echo "Build all .debs for $folder"
cd $folder
for version in $(ls); do
echo "Build $version"
dpkg-deb --build $version
mkdir -p ${root_dir}/repo-list/$1/
mv ${version}.deb ${root_dir}/repo-list/$1/
cd $base_dir/$folder
done
cd $base_dir
done
cd $root_dir
}
function run_nginx {
list_repo=$(aptly repo list -raw)
if [ -z "$WEB_URL" ]; then
echo "WEB_URL is not defined, using default value"
WEB_URL="http://URL_OF_THIS_SITE"
fi
if [ -z "$REPO_NAME" ]; then
echo "REPO_NAME is not defined, using default value"
REPO_NAME="TheBidouilleur"
fi
code_text=$(echo -e "wget -O - -q $WEB_URL/gpg | gpg --dearmor | sudo tee -a /etc/apt/trusted.gpg.d/$REPO_NAME.gpg >/dev/null<br>#Create a file /etc/apt/sources.list.d/$REPO_NAME.list with the following content<br>")
for repo in $(aptly repo list -raw); do
code_text=$(echo -e "${code_text}deb $WEB_URL $repo main<br>")
done
cp -r /data/html/* /var/www/html/
sed -i -z "s;CODE_HERE;${code_text};" /var/www/html/index.html
sed -i "s/REPO_NAME/${REPO_NAME}/g" /var/www/html/index.html
service nginx start
tail -f /var/log/nginx/access.log
}
# check if repo-list exists
if [ ! -d "repo-list" ]; then
echo "repo-list does not exists"
fi
root_dir=$(pwd)
if [ ! -d "repo-list" ]; then
echo "No repo-list folder, unarchive data.tar.gz to create the structure"
cd /data
tar xfz /data.tar.gz
cd $root_dir
fi
repos=$(ls repo-list)
rm -rf ~/.aptly/
mkdir -p ~/.aptly/public/ /data/gpg/
# if GPG_EMAIL is empty, define a default value
if [ -z "$GPG_EMAIL" ]; then
GPG_EMAIL="aptly@default"
fi
nb_of_key=$(gpg --list-keys | grep "^pub" | wc -l)
echo "$nb_of_key keys are stored in gnugpg"
# if /root/.gnupg does not exist, generate keys or copy from volume
if [ ! -f "/data/gpg/key" ]; then
echo "Generate GPG key"
mkdir -p /root/.gnupg
chmod 700 /root/.gnupg
gpg --full-gen-key --batch <(echo "Key-Type: 1"; \
echo "Key-Length: 4096"; \
echo "Subkey-Type: 1"; \
echo "Subkey-Length: 4096"; \
echo "Expire-Date: 0"; \
echo "Name-Real: Root Superuser"; \
echo "Name-Email: $GPG_EMAIL"; \
echo "%no-protection"; )
# export gpg key to volume
gpg --list-keys
gpg -o /data/gpg/key --export-secret-key
else
echo "Copy GPG key from volume"
gpg --no-tty --import /data/gpg/key
echo "Key imported"
fi
GPG_KEYID=$(gpg --batch --list-keys | grep -oP '[A-Z0-9]{10,}')
# If ~/.aptly/public/gpg does not exists, then create it
if [ ! -f "/root/.aptly/public/gpg" ]; then
gpg --batch --armor --output ~/.aptly/public/gpg --export $GPG_KEYID
fi
for repo in $repos; do
if [ -d "src/$repo" ]; then
echo "Directory src/$repo exists."
build_deb "$repo"
aptly repo create $repo
aptly repo add $repo repo-list/$repo
aptly snapshot create $repo from repo $repo
aptly publish snapshot -architectures="amd64,arm64" -distribution="$repo" -gpg-key="$GPG_KEYID" $repo
else
echo "Directory src/$repo does not exist."
fi
done
#aptly serve
rm -rf /var/www/html/*
mv ~/.aptly/public/* /var/www/html
run_nginx