-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.deb.sh.template
executable file
·60 lines (52 loc) · 1.57 KB
/
install.deb.sh.template
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
#!/bin/bash
# defaults
echo "- BRANCH [${BRANCH:=@branch@}]"
NAME="apt-proxy-detect"
VERSION="1.0.0"
HEADHASH="$(date +%s)"
TARGET="/usr/local/bin/${NAME}.sh"
APT_CONFIG_NAME="/etc/apt/apt.conf.d/30${NAME}.conf"
# workdir
T_DIR=$(mktemp -d)
trap 'rm -Rf "${T_DIR}"' EXIT
# create debian structure
# TODO get metric information out of github.
(
cd "${T_DIR}" || exit
mkdir DEBIAN
cat <<EOF > DEBIAN/control
Package: ${NAME}
Version: ${VERSION}-${BRANCH//\//-}-${HEADHASH}
Section: base
Priority: optional
Architecture: all
Depends: coreutils, grep, sed, wget, avahi-utils
Conflict: squid-deb-proxy-client
Maintainer: [email protected]
Description: apt proxy detection
EOF
# main program
mkdir -p "${T_DIR}$(dirname "${TARGET}")"
echo -n "- downloading ... "
if ! wget -q -O "${T_DIR}${TARGET}" "https://raw.githubusercontent.com/hastmu/apt-proxy-detect/refs/heads/${BRANCH}/apt-proxy-detect.sh"
then
echo "failed."
exit 1
else
echo "ok."
chmod a+rx "${T_DIR}${TARGET}"
fi
# apt config
mkdir -p "${T_DIR}$(dirname "${APT_CONFIG_NAME}")"
# shellcheck disable=SC2027
echo "Acquire::http::ProxyAutoDetect \""${TARGET}"\";" > "${T_DIR}${APT_CONFIG_NAME}"
echo "Acquire::https::ProxyAutoDetect \""${TARGET}"\";" >> "${T_DIR}${APT_CONFIG_NAME}"
)
DPKG_NAME="${NAME}_${VERSION}_${BRANCH//\//-}_${HEADHASH}.deb"
if dpkg -b "${T_DIR}" "${DPKG_NAME}"
then
apt-cache show "$(pwd)/${DPKG_NAME}"
apt-get install --allow-downgrades -y "$(pwd)/${DPKG_NAME}"
rm -fv "$(pwd)/${DPKG_NAME}"
dpkg -l "${NAME}"
fi