Skip to content

Instantly share code, notes, and snippets.

@fatihboy
Forked from dguglielmi/gitea-1.10.1-raspbian.sh
Last active August 31, 2018 14:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fatihboy/032a71514ba4893357352765cc10ec10 to your computer and use it in GitHub Desktop.
Save fatihboy/032a71514ba4893357352765cc10ec10 to your computer and use it in GitHub Desktop.
Install Gitea on Raspbian
#!/bin/sh
# Freely inspired by https://gist.github.com/mirhec/1c8af440aa4917d6ccd61ea628e5510c
# and Gentoo ebuild "styling".
################################
# Modified by Fatih Boy <fatih@enterprisecoding.com>
# * Gitea version updated to 1.5.0
# * GITEA_USER shell path fixed
################################
# License: GPLv2
# run: sudo ./gitea-1.5.0-raspbian.sh
PN="gitea"
PV="1.5.0"
P="${PN}-${PV}"
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"
S="${WORKDIR}/src/code.gitea.io/${PN}"
GO_PV="1.10"
GO_ARCH="linux-armv6l"
GO_SRC_URI="https://dl.google.com/go/go${GO_PV}.${GO_ARCH}.tar.gz"
GITEA_HOME="/var/lib/gitea"
GITEA_USER="gitea"
src_fetch() {
[ ! -d ${DISTFILES} ] && mkdir -p ${DISTFILES}
if [ ! -f "${DISTFILES}/${P}.tar.gz" ]; then
curl -L "${SRC_URI}" -o "${DISTFILES}/${P}.tar.gz"
fi
if [ ! -f "${DISTFILES}/go${GO_PV}.${GO_ARCH}.tar.gz" ]; then
curl -L "${GO_SRC_URI}" -o "${DISTFILES}/go${GO_PV}.${GO_ARCH}.tar.gz"
fi
}
src_prepare() {
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
}
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}"
tar xzf "${DISTFILES}/go${GO_PV}.${GO_ARCH}.tar.gz" -C ${WORKDIR}/
}
src_compile() {
PATH="${WORKDIR}/go/bin:${WORKDIR}/bin:${PATH}"
export GOROOT="${WORKDIR}/go"
export GOPATH="${WORKDIR}/"
export GOBIN="${WORKDIR}/bin"
go get github.com/jteeuwen/go-bindata
go install github.com/jteeuwen/go-bindata
cd ${S}
sed -i "s#main.Version=$(shell git describe --tags --always | sed 's/-/+/' | sed 's/^v//')#main.Version="${PV}"#" Makefile
TAGS="bindata sqlite" make generate build
}
src_cleanup() {
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=/var/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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment