Install os Debian 9

To facilitate the installation of gogs on a Debian 9 system, I wrote a script in bash. I hope to help someone. Sorry if off topic …

    # install & build googs
    ## preparation
    sudo apt update && sudo apt upgrade
    sudo apt-get install -y git golang golang-go golang-any golang-doc golang-src
    # golang version should be no lower 1.7
    sudo adduser --disabled-login --gecos 'Gogs' git
    mkdir -p $gogs_path
    mkdir -p $gogs_conf/custom/conf;
    touch $gogs_conf/custom/conf/app.ini;
    mkdir -p $gogs_conf/custom/sert;
    ## certificates for gogs
    cd $gogs_conf/custom/sert
    openssl req -new -x509 -days 3650 -nodes -out gogs.pem.cert -keyout        gogs.pem.key
    echo "export GOPATH=$git_path/gogs">>$git_path/.bashrc;
    echo "export GOROOT=$git_path/go">>$git_path/.bashrc;
    echo 'export PATH=$PATH:$GOROOT/bin:$GOPATH/bin' >> $git_path/.bashrc;
    chown -R git:git $gogs_path;
    chown -R git:git $gogs_conf;
    sudo su - git;
    mkdir -p $git_path/go/src;
    mkdir -p $git_path/go/bin;
    mkdir -p $git_path/go/pkg;
    ln -s /usr/lib/go/src/* $git_path/go/src
    ln -s /usr/lib/go/bin/* $git_path/go/bin
    ln -s /usr/lib/go/pkg/* $git_path/go/pkg
    go get -u;
    ln -s $git_path/go/src/ $git_path;
    cd $git_path/gogs;
    # build gogs
    go build;
    ln -s $git_path/gogs/gogs $git_path/go/bin/gogs;
    ln -s $gogs_conf/custom $git_path/gogs;
    # installation on debian
    cp -f $gogs_path/gogs/scripts/init/debian/gogs /etc/init.d/gogs
    update-rc.d gogs defaults
    chmod 0755 /etc/init.d/gogs
    cp -f $gogs_path/gogs/scripts/systemd/gogs.service /lib/systemd/syste/gogs.service
    systemctl enable gogs.service
    # make changes to the configuration file for the postgresql database
    #editor go/src/
    # copy in /etc/gogs/custom/conf/app.ini
    systemctl start gogs.service
    ## redirect port 3000 to 80 if input is used through localhost:3000
    ## section NAT
    iptables -A PREROUTING -p tcp --dport 80 -j REDIRECT --to-port 3000
    ## save to reboot
    if [ -d /etc/scripts/iptables ];
            mkdir -p /etc/scripts/iptables;
    iptables-save > /etc/scripts/iptables/rule;
1 Like