This repository was archived by the owner on May 3, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcreate_n_deploy.sh
executable file
·106 lines (92 loc) · 3.22 KB
/
create_n_deploy.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
#!/usr/bin/env bash
set -e
set -u
# Set magic variable for working dir, thx kvz.io
__dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
[ $(id -u) -eq 0 ] || {
printf >&2 '%s requires root\n' "$0"
exit 1
}
usage() {
printf >&2 '%s: [-a arch] [-d]\n' "$0"
exit 1
}
mkimages() {
cd "${__dir}"
# Iterate over every directory excluding dirs starting with _ or .
for OSDIR in $(find ${__dir} -maxdepth 1 -mindepth 1 -regextype posix-egrep -type d -regex '^\/?(\w+\/)*[^_.]\w+$')
do
OS=${OSDIR##*/}
VERSIONFILE="${OSDIR}/Versionfile"
if [ ! -f "${VERSIONFILE}" -o ! -r ${VERSIONFILE} -o ! -f "${OSDIR}/wrapper.sh" ]
then
echo "${OS}: Not all needed files accessible. Skipping."
continue
fi
while read VERSIONLINE
do
REGEGGS='^#'
[[ ${VERSIONLINE} =~ ${REGEGGS} ]] && continue
REL=${VERSIONLINE%:*}
TAGS_CSV=${VERSIONLINE##*:}
MAIN_TAG=${TAGS_CSV%%,*}
echo "### Processing '${VERSIONLINE}'."
# bash "${OSDIR}/mkimage-${OS}.sh" -r "${REL}" -s </dev/null
bash "${OSDIR}/wrapper.sh" -a ${ARCH} -o ${OS} -r ${REL} </dev/null
mkdir -p "${OSDIR}/${MAIN_TAG}"
[ -f "${__dir}/rootfs.tar.xz" ] && mv "${__dir}/rootfs.tar.xz" "${OSDIR}/${MAIN_TAG}"
# Check for Default files
for FILE in $(ls -1 "${__dir}/${SKEL_DIR}")
do
[ -f "${OSDIR}/${MAIN_TAG}/${FILE}" ] || {
cp --preserve=mode,ownership "${__dir}/${SKEL_DIR}/${FILE}" "${OSDIR}/${MAIN_TAG}/"
# substitute placeholders if existing
sed -i -e "s/%HUB_USER%/${HUB_USER}/g" \
-e "s/%REL%/${REL}/g" -e "s/%OS%/${OS}/g" \
-e "s/%MAIN_TAG%/${MAIN_TAG}/g" "${OSDIR}/${MAIN_TAG}/${FILE}"
}
done
IMAGE_ID=$(docker images -q |head -1)
# # Create correct Tags and remove unneeded ones from the creation script
# for TAG in $(echo "${TAGS_CSV}"| sed 's/,/ /g')
# do
# FULL_IMAGE_NAME="${HUB_USER}/${ARCH}-${OS}:${TAG}"
# docker tag -f ${IMAGE_ID} ${FULL_IMAGE_NAME}
# docker rmi ${OS}:${TAG} || true
# docker push ${FULL_IMAGE_NAME}
# done
# Remove the docker container started for testing the image and the last unneeded tag
# docker rmi -f ${OS}:${REL} || true
docker rm $(docker ps -l -q) 2>/dev/null || true
docker rmi -f ${IMAGE_ID} 2>/dev/null || true
echo "### DONE."
done < ${VERSIONFILE}
done
}
gitpush(){
cd ${__dir}
# Do a pull in case I changed the repo on Github again
git pull --no-edit
git add -A
git commit -m "Automatic push from deployment script"
git push
}
while getopts "ha:u:" opt; do
case $opt in
a)
ARCH=$OPTARG
;;
u)
HUB_USER=$OPTARG
;;
*)
usage
;;
esac
done
export ARCH=${ARCH:-armhf}
DAILY=${DAILY:-0}
HUB_USER=${HUB_USER:-m3adow}
SKEL_DIR=${SKEL_DIR:-_skel}
mkimages
gitpush