Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Install Gitea on Raspbian
#!/bin/sh
# Freely inspired by https://gist.github.com/mirhec/1c8af440aa4917d6ccd61ea628e5510c
# and Gentoo ebuild "styling".
# License: GPLv2
BN="$(basename $0)"
PN="gitea"
P="${BN%-*}"
PV="${P#${PN}-}"
SRC_URI="https://github.com/go-gitea/gitea/archive/v${PV}.tar.gz"
DISTFILES=/opt/distfiles
WORKDIR="$(mktemp -d /tmp/${PN}.XXXXXX)"
DEPEND="git unzip golang-go go-bindata"
S="${WORKDIR}/src/code.gitea.io/${PN}"
GITEA_HOME="/var/lib/gitea"
GITEA_USER="gitea"
SWAP_FILE="${WORKDIR}/swap.bin"
src_fetch() {
[ ! -d ${DISTFILES} ] && mkdir -p ${DISTFILES}
if [ ! -f "${DISTFILES}/${P}.tar.gz" ]; then
curl -L "${SRC_URI}" -o "${DISTFILES}/${P}.tar.gz"
fi
}
src_prepare() {
systemctl stop ${PN}
for dir in "${WORKDIR}" "${WORKDIR}/src/code.gitea.io"; do
[ ! -d ${dir} ] && mkdir -p ${dir}
done
DEPS=""
for dep in ${DEPEND} ; do
dpkg-query -l "${dep}" >/dev/null 2>&1
if [ ! $? -eq 0 ]; then
echo "${dep} is missing, installation targeted"
DEPS="${dep} "
fi
done
if [ ! "${DEPS}" = "" ]; then
apt install -y ${DEPS}
fi
id ${GITEA_USER} >/dev/null 2>&1
if [ ! $? -eq 0 ]; then
echo "create ${GITEA_USER} user"
useradd -s /bin/bash -m -d ${GITEA_HOME} ${GITEA_USER}
fi
dd if=/dev/zero of=${SWAP_FILE} bs=1M count=600
chmod 0400 ${SWAP_FILE}
mkswap -L sw ${SWAP_FILE}
swapon ${SWAP_FILE}
}
src_unpack() {
tar xzf "${DISTFILES}/${P}.tar.gz" -C ${WORKDIR}/src/code.gitea.io/
mv "${WORKDIR}/src/code.gitea.io/${P}" "${WORKDIR}/src/code.gitea.io/${PN}"
}
src_compile() {
cd ${S}
sed -i 's#main.Version=$(GITEA_VERSION)#main.Version='${PV}'#' Makefile
export GOPATH="${WORKDIR}/"
TAGS="bindata sqlite" make generate build
}
src_cleanup() {
swapoff ${SWAP_FILE}
rm -rf ${WORKDIR}
}
src_install() {
install -m 0755 ${WORKDIR}/src/code.gitea.io/${PN}/${PN} /usr/local/bin/${PN}
cat << EOF > /etc/systemd/system/${PN}.service
[Unit]
Description=${PN}
After=syslog.target
After=network.target
After=mariadb.service mysqld.service postgresql.service memcached.service redis.service
[Service]
Type=simple
User=${GITEA_USER}
Group=${GITEA_USER}
ExecStart=/usr/local/bin/${PN} web
Restart=always
Environment=USER=${GITEA_USER} GITEA_WORK_DIR=${GITEA_HOME}
PIDFile=/run/${PN}.pid
[Install]
WantedBy=multi-user.target
EOF
systemctl daemon-reload
systemctl enable ${PN}
systemctl start ${PN}
}
src_uninstall() {
systemctl stop ${PN}
systemctl disable ${PN}
rm -f /usr/local/bin/${PN}
rm -f /etc/systemd/system/${PN}.service
echo "${GITEA_HOME} not removed, it contain your data"
}
case "$1" in
uninstall)
src_uninstall
;;
fetch)
src_fetch
;;
unpack)
src_fetch
src_prepare
src_unpack
;;
merge|*)
src_fetch
src_prepare
src_unpack
src_compile
src_install
src_cleanup
;;
esac
@dguglielmi

This comment has been minimized.

Copy link
Owner Author

dguglielmi commented Dec 8, 2019

Updated for Rasbian Buster who provided Golang 1.11

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.