aboutsummaryrefslogtreecommitdiff

cgit config

Custom cgit config options/files/etc for my personal git server.

Mainly, changes are:

  • make rendering of /about/ page quicker (remove syntax highlight from md2html)
  • use highlight.js for code syntax highlighting
  • some custom JS to do things like automatically link to /about/ pages and fix image URLs
  • custom image/favicon/descriptions/etc
  • NGINX configuration
  • scripts
  • to add an automatic deployment on push, with post-receive (web_deployment scripts)
  • to mirror all repositories to gitlab
  • to create a new repository
  • to change repository categorisation

cgit backup/restore

# restore (from here)
sudo apt install cgit
cp /etc/cgitrc /etc/cgitrc.bak
cp ./etc/cgitrc /etc/cgitrc
cp ./usr/share/cgit/* /usr/share/cgit/
cp ./etc/nginx/sites-available/git /etc/nginx/sites-available/git
cp /usr/lib/cgit/filters/html-converters/md2html /usr/lib/cgit/filters/html-converters/md2html.bak
cp ./usr/lib/cgit/filters/html-converters/md2html /usr/lib/cgit/filters/html-converters/md2html
cp ./usr/git/scripts/* /usr/git/scripts/
echo "do a few other things, sorry (make sure nginx works)"

# backup (to here)
cp /etc/cgitrc ./etc/cgitrc
cp /usr/share/cgit/* ./usr/share/cgit/
cp /etc/nginx/sites-available/git ./etc/nginx/sites-available/git
cp /usr/lib/cgit/filters/html-converters/md2html ./usr/lib/cgit/filters/html-converters/md2html
cp /usr/git/scripts/*.sh ./usr/git/scripts/

server setup

locally

# set up local ssh config for git user
cat << EOCONF >> ~/.ssh/config
Host git
  HostName git.alifeee.net
  User git
  IdentityFile ~/.ssh/id_rsa
EOCONF

on server

# add git user
sudo adduser \
   --system \
   --shell /bin/bash \
   --gecos 'Git Version Control' \
   --group \
   --disabled-password \
   --home /home/git \
   git
sudo -u git git config --global init.defaultBranch <name>
sudo -u git git config user.name alifeee
sudo -u git git config user.email git@alifeee.net

# set up SSH keys
sudo -u git mkdir /home/git/.ssh/
echo "ssh-rsa2989828fu28892……289ur823u8rt28rt2…28528= alifeee's PC" \
  | sudo -u git tee /home/git/.ssh/authorized_keys
sudo tree -af /home/git/

# contain git in /usr/git/ (visible to www-data user)
sudo mkdir -p /usr/git/
sudo chown git: /usr/git/
sudo ln -s /usr/git/alifeee/ /home/git/alifeee

git-daemon

allows arbitrary git clone of repos :]

sudo ufw allow 9418
cat << EOUNIT | sudo tee /etc/systemd/system/git-daemon.service
[Unit]
Description=Start Git Daemon

[Service]
ExecStart=/usr/bin/git daemon --reuseaddr --export-all --base-path=/usr/git/ /usr/git

Restart=always
RestartSec=500ms

StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=git-daemon

User=git
Group=git

[Install]
WantedBy=multi-user.target
EOUNIT

sudo systemctl enable git-daemon.service
sudo systemctl start git-daemon.service
sudo systemctl status git-daemon.service

move from GitHub

to download a list of all (public) repositories on GitHub, run this

curl --request GET \
  --url "https://api.github.com/users/${user}/repos?per_page=100&page=1" \
  --header "Authorization: Bearer ${TOKEN}" \
  > repositories.json

then, to compare which ones have already been mirrored, run something like:

# show all with
cat repositories.json | jq -r \
  '.[] | (if (.fork == true) then "f " else "  " end) as $fork
    | "\($fork)\(.full_name) - \(.description)\n    size: \(.size), issues: \(.open_issues_count)"' \
  | less -S
# show only non-mirrored with:
existing=$(cat ../lists/*.txt | sort | uniq | awk '{printf "%s\"%s\"", fs, $0; fs=","} BEGIN {printf "["} END {print "]"}')
cat repositories.json \
  | jq --argjson existing "${existing}" '.[] | select([.name] | inside($existing) | not )' \
  | jq --slurp \
  | jq -r \
    '.[] | (if (.fork == true) then "f " else "  " end) as $fork
      | "\($fork)\(.full_name) - \(.description)\n    size: \(.size), issues: \(.open_issues_count)"' \
  | less -S

gitlab mirror setup

  • create gitlab group on gitlab
  • create gitlab user, add ssh key to git user, and get personal API TOKEN

add this to crontab for git user:

sudo su git
crontab -e
# 16 5 * * * (cd /usr/git/scripts/; ./mirror_to_gitlab.sh > cron.log 2>&1)

personally, when a cron job fails, I get an email.