自建Gogs简易一键安装脚本
20250321更新
修复useradd命令解决报错gogsfatal: protocol error: bad line length character: this
报错的来源是直接ssh git@gogs.local返回最后一句This account is currently not available.
必须分配一个有效的shell才能生效force command正常push代码
正常返回信息
Hi there, You've successfully authenticated, but Gogs does not provide shell access.
If this is unexpected, please log in with password and setup Gogs under another user.
脚本
更换了一台arm64的设备做低功耗服务器7x24待命,顺手写个脚本部署Gogs备用。
脚本需要sudo运行。暂不支持自动判断架构,后续可能会更新,思路是uname -m
正则匹配。
#!/bin/bash
[[ $(id -u) != 0 ]] && echo "Pls run with sudo" && exit -1
# set gogs url modify if needed
URL=https://dl.gogs.io/0.12.3/gogs_0.12.3_linux_armv8.tar.gz
# download gogs and create git user
wget $URL -O /dev/shm/gogs.tgz
adduser \
--system \
--shell /bin/bash \
--gecos 'Git Version Control' \
--group \
--disabled-password \
--home /home/git \
git
sudo -u git tar zxvf /dev/shm/gogs.tgz -C /home/git
rm /dev/shm/gogs.tgz
# create system service
echo "[Unit]
Description=Gogs
After=syslog.target
After=network.target
[Service]
RestartSec=2s
Type=simple
User=git
Group=git
WorkingDirectory=/home/git/gogs
ExecStart=/home/git/gogs/gogs web
Restart=always
Environment=USER=git
HOME=/home/git
[Install]
WantedBy=multi-user.target
" > /etc/systemd/system/gogs.service
# launch with startup
systemctl daemon-reload
systemctl enable gogs
systemctl start gogs
echo "DONE!"