Skip to content
Snippets Groups Projects
Commit 6a9de461 authored by Bob Mottram's avatar Bob Mottram
Browse files

gogs commit

parent ccb07ff3
No related branches found
No related tags found
No related merge requests found
...@@ -35,612 +35,612 @@ GIT_CODE= ...@@ -35,612 +35,612 @@ GIT_CODE=
GIT_ONION_PORT=8090 GIT_ONION_PORT=8090
GIT_DOMAIN_REPO="https://github.com/gogits/gogs" GIT_DOMAIN_REPO="https://github.com/gogits/gogs"
GIT_ADMIN_PASSWORD= GIT_ADMIN_PASSWORD=
GOGS_COMMIT='3fb4f7f4980b4339fd9ef6a3ba5b0acab83d264d' GOGS_COMMIT='37305a59ca0cdc7efe880d4e54f68ecbe3eacc29'
function get_mariadb_git_admin_password { function get_mariadb_git_admin_password {
if [ -f /home/$MY_USERNAME/README ]; then if [ -f /home/$MY_USERNAME/README ]; then
if grep -q "Gogs admin user password" /home/$MY_USERNAME/README; then if grep -q "Gogs admin user password" /home/$MY_USERNAME/README; then
GIT_ADMIN_PASSWORD=$(cat /home/$MY_USERNAME/README | grep "Gogs admin user password" | awk -F ':' '{print $2}' | sed 's/^ *//') GIT_ADMIN_PASSWORD=$(cat /home/$MY_USERNAME/README | grep "Gogs admin user password" | awk -F ':' '{print $2}' | sed 's/^ *//')
fi fi
fi fi
} }
function gogs_create_database { function gogs_create_database {
function_check get_mariadb_git_admin_password function_check get_mariadb_git_admin_password
get_mariadb_git_admin_password get_mariadb_git_admin_password
if [ ! $GIT_ADMIN_PASSWORD ]; then if [ ! $GIT_ADMIN_PASSWORD ]; then
if [ -f $IMAGE_PASSWORD_FILE ]; then if [ -f $IMAGE_PASSWORD_FILE ]; then
GIT_ADMIN_PASSWORD="$(printf `cat $IMAGE_PASSWORD_FILE`)" GIT_ADMIN_PASSWORD="$(printf `cat $IMAGE_PASSWORD_FILE`)"
else else
GIT_ADMIN_PASSWORD="$(create_password ${MINIMUM_PASSWORD_LENGTH})" GIT_ADMIN_PASSWORD="$(create_password ${MINIMUM_PASSWORD_LENGTH})"
fi fi
fi fi
if [ ! $GIT_ADMIN_PASSWORD ]; then if [ ! $GIT_ADMIN_PASSWORD ]; then
return return
fi fi
function_check create_database function_check create_database
create_database gogs "$GOGS_ADMIN_PASSWORD" create_database gogs "$GOGS_ADMIN_PASSWORD"
} }
function reconfigure_gogs { function reconfigure_gogs {
echo -n '' echo -n ''
} }
function upgrade_gogs { function upgrade_gogs {
if ! grep -Fxq "install_gogs" $COMPLETION_FILE; then if ! grep -Fxq "install_gogs" $COMPLETION_FILE; then
return return
fi fi
function_check select_go_version function_check select_go_version
select_go_version select_go_version
function_check set_repo_commit function_check set_repo_commit
set_repo_commit $GOPATH/src/github.com/gogits/gogs "Gogs commit" "$GOGS_COMMIT" $GIT_DOMAIN_REPO set_repo_commit $GOPATH/src/github.com/gogits/gogs "Gogs commit" "$GOGS_COMMIT" $GIT_DOMAIN_REPO
} }
function backup_local_gogs { function backup_local_gogs {
if ! grep -q "Gogs domain" $COMPLETION_FILE; then if ! grep -q "Gogs domain" $COMPLETION_FILE; then
return return
fi fi
if [ ! -d /home/git/gogs-repositories ]; then if [ ! -d /home/git/gogs-repositories ]; then
return return
fi fi
GIT_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "Gogs domain" | awk -F ':' '{print $2}') GIT_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "Gogs domain" | awk -F ':' '{print $2}')
echo $"Backing up gogs" echo $"Backing up gogs"
function_check backup_database_to_usb function_check backup_database_to_usb
backup_database_to_usb gogs backup_database_to_usb gogs
function_check backup_directory_to_usb function_check backup_directory_to_usb
backup_directory_to_usb $GOPATH/src/github.com/gogits/gogs/custom gogs backup_directory_to_usb $GOPATH/src/github.com/gogits/gogs/custom gogs
backup_directory_to_usb /home/git/gogs-repositories gogsrepos backup_directory_to_usb /home/git/gogs-repositories gogsrepos
backup_directory_to_usb /home/git/.ssh gogsssh backup_directory_to_usb /home/git/.ssh gogsssh
echo $"Gogs backup complete" echo $"Gogs backup complete"
} }
function restore_local_gogs { function restore_local_gogs {
if ! grep -q "Gogs domain" $COMPLETION_FILE; then if ! grep -q "Gogs domain" $COMPLETION_FILE; then
return return
fi fi
if [ ! -d /home/git/gogs-repositories ]; then if [ ! -d /home/git/gogs-repositories ]; then
return return
fi fi
GIT_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "Gogs domain" | awk -F ':' '{print $2}') GIT_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "Gogs domain" | awk -F ':' '{print $2}')
export GVM_ROOT=$GVM_HOME export GVM_ROOT=$GVM_HOME
if [ -d $GVM_ROOT/bin ]; then if [ -d $GVM_ROOT/bin ]; then
cd $GVM_ROOT/bin cd $GVM_ROOT/bin
[[ -s "$GVM_ROOT/scripts/gvm" ]] && source "$GVM_ROOT/scripts/gvm" [[ -s "$GVM_ROOT/scripts/gvm" ]] && source "$GVM_ROOT/scripts/gvm"
gvm use go${GO_VERSION} --default gvm use go${GO_VERSION} --default
systemctl set-environment GOPATH=$GOPATH systemctl set-environment GOPATH=$GOPATH
fi fi
if [ ${#GIT_DOMAIN_NAME} -gt 2 ]; then if [ ${#GIT_DOMAIN_NAME} -gt 2 ]; then
function_check gogs_create_database function_check gogs_create_database
gogs_create_database gogs_create_database
function_check restore_database function_check restore_database
restore_database gogs ${GIT_DOMAIN_NAME} restore_database gogs ${GIT_DOMAIN_NAME}
temp_restore_dir=/root/tempgogs temp_restore_dir=/root/tempgogs
if [ -d $USB_MOUNT/backup/gogs ]; then if [ -d $USB_MOUNT/backup/gogs ]; then
echo $"Restoring Gogs settings" echo $"Restoring Gogs settings"
if [ ! -d $GOPATH/src/github.com/gogits/gogs/custom ]; then if [ ! -d $GOPATH/src/github.com/gogits/gogs/custom ]; then
mkdir -p $GOPATH/src/github.com/gogits/gogs/custom mkdir -p $GOPATH/src/github.com/gogits/gogs/custom
fi fi
cp -r ${temp_restore_dir}/$GOPATH/src/github.com/gogits/gogs/custom/* $GOPATH/src/github.com/gogits/gogs/custom cp -r ${temp_restore_dir}/$GOPATH/src/github.com/gogits/gogs/custom/* $GOPATH/src/github.com/gogits/gogs/custom
if [ ! "$?" = "0" ]; then if [ ! "$?" = "0" ]; then
function_check set_user_permissions function_check set_user_permissions
set_user_permissions set_user_permissions
function_check backup_unmount_drive function_check backup_unmount_drive
backup_unmount_drive backup_unmount_drive
exit 981 exit 981
fi fi
echo $"Restoring Gogs repos" echo $"Restoring Gogs repos"
function_check restore_directory_from_usb function_check restore_directory_from_usb
restore_directory_from_usb ${temp_restore_dir}repos gogsrepos restore_directory_from_usb ${temp_restore_dir}repos gogsrepos
cp -r ${temp_restore_dir}repos/home/git/gogs-repositories/* /home/git/gogs-repositories/ cp -r ${temp_restore_dir}repos/home/git/gogs-repositories/* /home/git/gogs-repositories/
if [ ! "$?" = "0" ]; then if [ ! "$?" = "0" ]; then
function_check set_user_permissions function_check set_user_permissions
set_user_permissions set_user_permissions
function_check backup_unmount_drive function_check backup_unmount_drive
backup_unmount_drive backup_unmount_drive
exit 67574 exit 67574
fi fi
echo $"Restoring Gogs authorized_keys" echo $"Restoring Gogs authorized_keys"
function_check restore_directory_from_usb function_check restore_directory_from_usb
restore_directory_from_usb ${temp_restore_dir}ssh gogsssh restore_directory_from_usb ${temp_restore_dir}ssh gogsssh
if [ ! -d /home/git/.ssh ]; then if [ ! -d /home/git/.ssh ]; then
mkdir /home/git/.ssh mkdir /home/git/.ssh
fi fi
cp -r ${temp_restore_dir}ssh/home/git/.ssh/* /home/git/.ssh/ cp -r ${temp_restore_dir}ssh/home/git/.ssh/* /home/git/.ssh/
if [ ! "$?" = "0" ]; then if [ ! "$?" = "0" ]; then
function_check set_user_permissions function_check set_user_permissions
set_user_permissions set_user_permissions
function_check backup_unmount_drive function_check backup_unmount_drive
backup_unmount_drive backup_unmount_drive
exit 8463 exit 8463
fi fi
rm -rf ${temp_restore_dir} rm -rf ${temp_restore_dir}
rm -rf ${temp_restore_dir}repos rm -rf ${temp_restore_dir}repos
rm -rf ${temp_restore_dir}ssh rm -rf ${temp_restore_dir}ssh
chown -R git:git /home/git chown -R git:git /home/git
fi fi
fi fi
} }
function backup_remote_gogs { function backup_remote_gogs {
export GVM_ROOT=/home/git/gvm export GVM_ROOT=/home/git/gvm
if [ -d $GVM_ROOT/bin ]; then if [ -d $GVM_ROOT/bin ]; then
cd $GVM_ROOT/bin cd $GVM_ROOT/bin
[[ -s "$GVM_ROOT/scripts/gvm" ]] && source "$GVM_ROOT/scripts/gvm" [[ -s "$GVM_ROOT/scripts/gvm" ]] && source "$GVM_ROOT/scripts/gvm"
gvm use go${GO_VERSION} --default gvm use go${GO_VERSION} --default
systemctl set-environment GOPATH=$GOPATH systemctl set-environment GOPATH=$GOPATH
fi fi
if [ -d $GOPATH/src/github.com/gogits ]; then if [ -d $GOPATH/src/github.com/gogits ]; then
GIT_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "Gogs domain" | awk -F ':' '{print $2}') GIT_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "Gogs domain" | awk -F ':' '{print $2}')
function_check suspend_site function_check suspend_site
suspend_site ${GIT_DOMAIN_NAME} suspend_site ${GIT_DOMAIN_NAME}
function_check backup_database_to_friend function_check backup_database_to_friend
backup_database_to_friend gogs backup_database_to_friend gogs
echo $"Obtaining Gogs settings backup" echo $"Obtaining Gogs settings backup"
function_check backup_directory_to_friend function_check backup_directory_to_friend
backup_directory_to_friend $GOPATH/src/github.com/gogits/gogs/custom gogs backup_directory_to_friend $GOPATH/src/github.com/gogits/gogs/custom gogs
echo $"Obtaining Gogs repos backup" echo $"Obtaining Gogs repos backup"
mv /home/git/gogs-repositories/*.git /home/git/gogs-repositories/bob mv /home/git/gogs-repositories/*.git /home/git/gogs-repositories/bob
backup_directory_to_friend /home/git/gogs-repositories gogsrepos backup_directory_to_friend /home/git/gogs-repositories gogsrepos
echo $"Obtaining Gogs authorized_keys backup" echo $"Obtaining Gogs authorized_keys backup"
backup_directory_to_friend /home/git/.ssh gogsssh backup_directory_to_friend /home/git/.ssh gogsssh
function_check restart_site function_check restart_site
restart_site restart_site
echo $"Gogs backup complete" echo $"Gogs backup complete"
fi fi
} }
function restore_remote_gogs { function restore_remote_gogs {
export GVM_ROOT=$GVM_HOME export GVM_ROOT=$GVM_HOME
if [ -d $GVM_ROOT/bin ]; then if [ -d $GVM_ROOT/bin ]; then
cd $GVM_ROOT/bin cd $GVM_ROOT/bin
[[ -s "$GVM_ROOT/scripts/gvm" ]] && source "$GVM_ROOT/scripts/gvm" [[ -s "$GVM_ROOT/scripts/gvm" ]] && source "$GVM_ROOT/scripts/gvm"
gvm use go${GO_VERSION} --default gvm use go${GO_VERSION} --default
systemctl set-environment GOPATH=$GOPATH systemctl set-environment GOPATH=$GOPATH
fi fi
if grep -q "Gogs domain" $COMPLETION_FILE; then if grep -q "Gogs domain" $COMPLETION_FILE; then
GIT_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "Gogs domain" | awk -F ':' '{print $2}') GIT_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "Gogs domain" | awk -F ':' '{print $2}')
function_check gogs_create_database function_check gogs_create_database
gogs_create_database gogs_create_database
function_check restore_database_from_friend function_check restore_database_from_friend
restore_database_from_friend gogs $GIT_DOMAIN_NAME restore_database_from_friend gogs $GIT_DOMAIN_NAME
if [ -d $SERVER_DIRECTORY/backup/gogs ]; then if [ -d $SERVER_DIRECTORY/backup/gogs ]; then
if [ ! -d $GOPATH/src/github.com/gogits/gogs/custom ]; then if [ ! -d $GOPATH/src/github.com/gogits/gogs/custom ]; then
mkdir -p $GOPATH/src/github.com/gogits/gogs/custom mkdir -p $GOPATH/src/github.com/gogits/gogs/custom
fi fi
cp -r /root/tempgogs/$GOPATH/src/github.com/gogits/gogs/custom/* $GOPATH/src/github.com/gogits/gogs/custom/ cp -r /root/tempgogs/$GOPATH/src/github.com/gogits/gogs/custom/* $GOPATH/src/github.com/gogits/gogs/custom/
if [ ! "$?" = "0" ]; then if [ ! "$?" = "0" ]; then
exit 5885 exit 5885
fi fi
echo $"Restoring Gogs repos" echo $"Restoring Gogs repos"
restore_directory_from_friend /root/tempgogsrepos gogsrepos restore_directory_from_friend /root/tempgogsrepos gogsrepos
cp -r /root/tempgogsrepos/home/git/gogs-repositories/* /home/git/gogs-repositories/ cp -r /root/tempgogsrepos/home/git/gogs-repositories/* /home/git/gogs-repositories/
if [ ! "$?" = "0" ]; then if [ ! "$?" = "0" ]; then
exit 7649 exit 7649
fi fi
echo $"Restoring Gogs authorized_keys" echo $"Restoring Gogs authorized_keys"
restore_directory_from_friend /root/tempgogsssh gogsssh restore_directory_from_friend /root/tempgogsssh gogsssh
if [ ! -d /home/git/.ssh ]; then if [ ! -d /home/git/.ssh ]; then
mkdir /home/git/.ssh mkdir /home/git/.ssh
fi fi
cp -r /root/tempgogsssh/home/git/.ssh/* /home/git/.ssh/ cp -r /root/tempgogsssh/home/git/.ssh/* /home/git/.ssh/
if [ ! "$?" = "0" ]; then if [ ! "$?" = "0" ]; then
exit 74239 exit 74239
fi fi
rm -rf /root/tempgogs rm -rf /root/tempgogs
rm -rf /root/tempgogsrepos rm -rf /root/tempgogsrepos
rm -rf /root/tempgogsssh rm -rf /root/tempgogsssh
chown -R git:git /home/git chown -R git:git /home/git
echo $"Restore of Gogs complete" echo $"Restore of Gogs complete"
fi fi
fi fi
} }
function remove_gogs { function remove_gogs {
if ! grep -Fxq "install_gogs" $COMPLETION_FILE; then if ! grep -Fxq "install_gogs" $COMPLETION_FILE; then
return return
fi fi
function_check select_go_version function_check select_go_version
select_go_version select_go_version
systemctl stop gogs systemctl stop gogs
systemctl disable gogs systemctl disable gogs
nginx_dissite $GIT_DOMAIN_NAME nginx_dissite $GIT_DOMAIN_NAME
if [ -d /var/www/$GIT_DOMAIN_NAME ]; then if [ -d /var/www/$GIT_DOMAIN_NAME ]; then
rm -rf /var/www/$GIT_DOMAIN_NAME rm -rf /var/www/$GIT_DOMAIN_NAME
fi fi
if [ -f /etc/nginx/sites-available/$GIT_DOMAIN_NAME ]; then if [ -f /etc/nginx/sites-available/$GIT_DOMAIN_NAME ]; then
rm /etc/nginx/sites-available/$GIT_DOMAIN_NAME rm /etc/nginx/sites-available/$GIT_DOMAIN_NAME
fi fi
function_check drop_database function_check drop_database
drop_database gogs drop_database gogs
rm /etc/systemd/system/gogs.service rm /etc/systemd/system/gogs.service
rm -rf $GOPATH/src/github.com/gogits rm -rf $GOPATH/src/github.com/gogits
remove_onion_service gogs ${GIT_ONION_PORT} 9418 remove_onion_service gogs ${GIT_ONION_PORT} 9418
sed -i '/install_gogs/d' $COMPLETION_FILE sed -i '/install_gogs/d' $COMPLETION_FILE
sed -i '/Gogs /d' $COMPLETION_FILE sed -i '/Gogs /d' $COMPLETION_FILE
} }
function install_gogs { function install_gogs {
if [ ! $GIT_DOMAIN_NAME ]; then if [ ! $GIT_DOMAIN_NAME ]; then
return return
fi fi
if grep -Fxq "install_gogs" $COMPLETION_FILE; then if grep -Fxq "install_gogs" $COMPLETION_FILE; then
return return
fi fi
function_check select_go_version function_check select_go_version
select_go_version select_go_version
if [ -d $GOPATH/src/github.com/gogits ]; then if [ -d $GOPATH/src/github.com/gogits ]; then
rm -rf $GOPATH/src/github.com/gogits rm -rf $GOPATH/src/github.com/gogits
fi fi
if [ -d /home/git/gvm/pkgsets/go${GO_VERSION}/global/src/github.com/gogits ]; then if [ -d /home/git/gvm/pkgsets/go${GO_VERSION}/global/src/github.com/gogits ]; then
rm -rf /home/git/gvm/pkgsets/go${GO_VERSION}/global/src/github.com/gogits rm -rf /home/git/gvm/pkgsets/go${GO_VERSION}/global/src/github.com/gogits
fi fi
if [ -d /home/git/gogs-repositories ]; then if [ -d /home/git/gogs-repositories ]; then
rm -rf /home/git/gogs-repositories rm -rf /home/git/gogs-repositories
fi fi
if [ ! -d /home/git ]; then if [ ! -d /home/git ]; then
# add a gogs user account # add a gogs user account
adduser --disabled-login --gecos 'Gogs' git adduser --disabled-login --gecos 'Gogs' git
fi fi
if [ -d /home/git/Maildir ]; then if [ -d /home/git/Maildir ]; then
rm -rf /home/git/Maildir rm -rf /home/git/Maildir
fi fi
if [ -d $GOPATH/src/github.com/gogits ]; then if [ -d $GOPATH/src/github.com/gogits ]; then
rm -rf $GOPATH/src/github.com/gogits rm -rf $GOPATH/src/github.com/gogits
fi fi
# install Go # install Go
apt-get -y install golang libpam0g-dev apt-get -y install golang libpam0g-dev
if ! grep -q "export GOPATH=" ~/.bashrc; then if ! grep -q "export GOPATH=" ~/.bashrc; then
echo "export GOPATH=$GOPATH" >> ~/.bashrc echo "export GOPATH=$GOPATH" >> ~/.bashrc
else else
sed -i "s|export GOPATH=.*|export GOPATH=$GOPATH|g" ~/.bashrc sed -i "s|export GOPATH=.*|export GOPATH=$GOPATH|g" ~/.bashrc
fi fi
systemctl set-environment GOPATH=$GOPATH systemctl set-environment GOPATH=$GOPATH
if ! grep -q "systemctl set-environment GOPATH=" ~/.bashrc; then if ! grep -q "systemctl set-environment GOPATH=" ~/.bashrc; then
echo "systemctl set-environment GOPATH=$GOPATH" >> ~/.bashrc echo "systemctl set-environment GOPATH=$GOPATH" >> ~/.bashrc
else else
sed -i "s|systemctl set-environment GOPATH=.*|systemctl set-environment GOPATH=$GOPATH|g" ~/.bashrc sed -i "s|systemctl set-environment GOPATH=.*|systemctl set-environment GOPATH=$GOPATH|g" ~/.bashrc
fi fi
if [ ! -d $GOPATH ]; then if [ ! -d $GOPATH ]; then
mkdir -p $GOPATH mkdir -p $GOPATH
fi fi
GO_PACKAGE_MANAGER_REPO2=$(echo "$GO_PACKAGE_MANAGER_REPO" | sed 's|https://||g') GO_PACKAGE_MANAGER_REPO2=$(echo "$GO_PACKAGE_MANAGER_REPO" | sed 's|https://||g')
go get -u $GO_PACKAGE_MANAGER_REPO2 go get -u $GO_PACKAGE_MANAGER_REPO2
if [ ! "$?" = "0" ]; then if [ ! "$?" = "0" ]; then
echo $'install_gogs: go get failed' echo $'install_gogs: go get failed'
exit 479832 exit 479832
fi fi
# clone the repo # clone the repo
if [ ! -d $GOPATH/src/github.com/gogits ]; then if [ ! -d $GOPATH/src/github.com/gogits ]; then
mkdir -p $GOPATH/src/github.com/gogits mkdir -p $GOPATH/src/github.com/gogits
fi fi
function_check git_clone function_check git_clone
git_clone $GIT_DOMAIN_REPO $GOPATH/src/github.com/gogits/gogs git_clone $GIT_DOMAIN_REPO $GOPATH/src/github.com/gogits/gogs
if [ ! -d $GOPATH/src/github.com/gogits/gogs ]; then if [ ! -d $GOPATH/src/github.com/gogits/gogs ]; then
echo $"Unable to clone repo $GOPATH/src/github.com/gogits/gogs" echo $"Unable to clone repo $GOPATH/src/github.com/gogits/gogs"
exit 85482 exit 85482
fi fi
cd $GOPATH/src/github.com/gogits/gogs cd $GOPATH/src/github.com/gogits/gogs
# install # install
go get -u ./... go get -u ./...
git checkout $GOGS_COMMIT -b $GOGS_COMMIT git checkout $GOGS_COMMIT -b $GOGS_COMMIT
if ! grep -q "Gogs commit" $COMPLETION_FILE; then if ! grep -q "Gogs commit" $COMPLETION_FILE; then
echo "Gogs commit:$GOGS_COMMIT" >> $COMPLETION_FILE echo "Gogs commit:$GOGS_COMMIT" >> $COMPLETION_FILE
else else
sed -i "s/Gogs commit.*/Gogs commit:$GOGS_COMMIT/g" $COMPLETION_FILE sed -i "s/Gogs commit.*/Gogs commit:$GOGS_COMMIT/g" $COMPLETION_FILE
fi fi
go build go build
if [ ! "$?" = "0" ]; then if [ ! "$?" = "0" ]; then
echo $'install_gogs: go build failed' echo $'install_gogs: go build failed'
exit 546750 exit 546750
fi fi
function_check install_mariadb function_check install_mariadb
install_mariadb install_mariadb
function_check get_mariadb_password function_check get_mariadb_password
get_mariadb_password get_mariadb_password
function_check function_check
gogs_create_database gogs_create_database
if [ ! -f $GOPATH/src/github.com/gogits/gogs/scripts/mysql.sql ]; then if [ ! -f $GOPATH/src/github.com/gogits/gogs/scripts/mysql.sql ]; then
echo $'MySql template for Gogs was not found' echo $'MySql template for Gogs was not found'
exit 72528 exit 72528
fi fi
if ! grep -q $"Gogs admin user password" /home/$MY_USERNAME/README; then if ! grep -q $"Gogs admin user password" /home/$MY_USERNAME/README; then
echo '' >> /home/$MY_USERNAME/README echo '' >> /home/$MY_USERNAME/README
echo '' >> /home/$MY_USERNAME/README echo '' >> /home/$MY_USERNAME/README
echo 'Gogs' >> /home/$MY_USERNAME/README echo 'Gogs' >> /home/$MY_USERNAME/README
echo '====' >> /home/$MY_USERNAME/README echo '====' >> /home/$MY_USERNAME/README
echo $'Install Steps For First-time Run:' >> /home/$MY_USERNAME/README echo $'Install Steps For First-time Run:' >> /home/$MY_USERNAME/README
echo $'Leave email service settings empty' >> /home/$MY_USERNAME/README echo $'Leave email service settings empty' >> /home/$MY_USERNAME/README
echo $'Check "Enable Register Confirmation"' >> /home/$MY_USERNAME/README echo $'Check "Enable Register Confirmation"' >> /home/$MY_USERNAME/README
echo $'Check "Enable Mail Notification"' >> /home/$MY_USERNAME/README echo $'Check "Enable Mail Notification"' >> /home/$MY_USERNAME/README
echo '' >> /home/$MY_USERNAME/README echo '' >> /home/$MY_USERNAME/README
echo $'If you want to disable new account registrations then append the following:' >> /home/$MY_USERNAME/README echo $'If you want to disable new account registrations then append the following:' >> /home/$MY_USERNAME/README
echo ' [service]' >> /home/$MY_USERNAME/README echo ' [service]' >> /home/$MY_USERNAME/README
echo ' DISABLE_REGISTRATION = true' >> /home/$MY_USERNAME/README echo ' DISABLE_REGISTRATION = true' >> /home/$MY_USERNAME/README
echo $'Then restart with:' >> /home/$MY_USERNAME/README echo $'Then restart with:' >> /home/$MY_USERNAME/README
echo ' systemctl restart gogs' >> /home/$MY_USERNAME/README echo ' systemctl restart gogs' >> /home/$MY_USERNAME/README
echo '' >> /home/$MY_USERNAME/README echo '' >> /home/$MY_USERNAME/README
echo $"Note that there's a usability/security trade-off made here." >> /home/$MY_USERNAME/README echo $"Note that there's a usability/security trade-off made here." >> /home/$MY_USERNAME/README
echo $"In order to allow git clone via http we don't redirect everything" >> /home/$MY_USERNAME/README echo $"In order to allow git clone via http we don't redirect everything" >> /home/$MY_USERNAME/README
echo $'over https. Instead only critical things such as user login,' >> /home/$MY_USERNAME/README echo $'over https. Instead only critical things such as user login,' >> /home/$MY_USERNAME/README
echo $'settings and admin are encrypted.' >> /home/$MY_USERNAME/README echo $'settings and admin are encrypted.' >> /home/$MY_USERNAME/README
echo $'There are also potential security issues with cloning/pulling/pushing' >> /home/$MY_USERNAME/README echo $'There are also potential security issues with cloning/pulling/pushing' >> /home/$MY_USERNAME/README
echo $'code over http, since a determined adversary could inject malware' >> /home/$MY_USERNAME/README echo $'code over http, since a determined adversary could inject malware' >> /home/$MY_USERNAME/README
echo $'into the stream as it passes, so beware.' >> /home/$MY_USERNAME/README echo $'into the stream as it passes, so beware.' >> /home/$MY_USERNAME/README
echo $'If you have a bought domain and a non-self signed cert then you' >> /home/$MY_USERNAME/README echo $'If you have a bought domain and a non-self signed cert then you' >> /home/$MY_USERNAME/README
echo $"should change /etc/nginx/sites-available/$GIT_DOMAIN_NAME to redirect everything over https." >> /home/$MY_USERNAME/README echo $"should change /etc/nginx/sites-available/$GIT_DOMAIN_NAME to redirect everything over https." >> /home/$MY_USERNAME/README
chown $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/README chown $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/README
chmod 600 /home/$MY_USERNAME/README chmod 600 /home/$MY_USERNAME/README
fi fi
function_check initialise_database function_check initialise_database
initialise_database gogs $GOPATH/src/github.com/gogits/gogs/scripts/mysql.sql initialise_database gogs $GOPATH/src/github.com/gogits/gogs/scripts/mysql.sql
chmod 600 $GOPATH/src/github.com/gogits/gogs/custom/conf/app.ini chmod 600 $GOPATH/src/github.com/gogits/gogs/custom/conf/app.ini
chown -R git:git /home/git chown -R git:git /home/git
echo '[Unit]' > /etc/systemd/system/gogs.service echo '[Unit]' > /etc/systemd/system/gogs.service
echo 'Description=Gogs (Go Git Service)' >> /etc/systemd/system/gogs.service echo 'Description=Gogs (Go Git Service)' >> /etc/systemd/system/gogs.service
echo 'After=syslog.target' >> /etc/systemd/system/gogs.service echo 'After=syslog.target' >> /etc/systemd/system/gogs.service
echo 'After=network.target' >> /etc/systemd/system/gogs.service echo 'After=network.target' >> /etc/systemd/system/gogs.service
echo 'After=mysqld.service' >> /etc/systemd/system/gogs.service echo 'After=mysqld.service' >> /etc/systemd/system/gogs.service
echo '' >> /etc/systemd/system/gogs.service echo '' >> /etc/systemd/system/gogs.service
echo '[Service]' >> /etc/systemd/system/gogs.service echo '[Service]' >> /etc/systemd/system/gogs.service
echo '#LimitMEMLOCK=infinity' >> /etc/systemd/system/gogs.service echo '#LimitMEMLOCK=infinity' >> /etc/systemd/system/gogs.service
echo '#LimitNOFILE=65535' >> /etc/systemd/system/gogs.service echo '#LimitNOFILE=65535' >> /etc/systemd/system/gogs.service
echo 'Type=simple' >> /etc/systemd/system/gogs.service echo 'Type=simple' >> /etc/systemd/system/gogs.service
echo 'User=git' >> /etc/systemd/system/gogs.service echo 'User=git' >> /etc/systemd/system/gogs.service
echo 'Group=git' >> /etc/systemd/system/gogs.service echo 'Group=git' >> /etc/systemd/system/gogs.service
echo "WorkingDirectory=$GOPATH/src/github.com/gogits/gogs" >> /etc/systemd/system/gogs.service echo "WorkingDirectory=$GOPATH/src/github.com/gogits/gogs" >> /etc/systemd/system/gogs.service
echo "ExecStart=$GOPATH/src/github.com/gogits/gogs/gogs web" >> /etc/systemd/system/gogs.service echo "ExecStart=$GOPATH/src/github.com/gogits/gogs/gogs web" >> /etc/systemd/system/gogs.service
echo 'Restart=always' >> /etc/systemd/system/gogs.service echo 'Restart=always' >> /etc/systemd/system/gogs.service
echo 'RestartSec=10' >> /etc/systemd/system/gogs.service echo 'RestartSec=10' >> /etc/systemd/system/gogs.service
echo 'TimeoutStartSec=120' >> /etc/systemd/system/gogs.service echo 'TimeoutStartSec=120' >> /etc/systemd/system/gogs.service
echo "Environment=\"USER=git\" \"HOME=/home/git\" \"GOPATH=$GOPATH\" \"GVM_ROOT=$GVM_HOME\"" >> /etc/systemd/system/gogs.service echo "Environment=\"USER=git\" \"HOME=/home/git\" \"GOPATH=$GOPATH\" \"GVM_ROOT=$GVM_HOME\"" >> /etc/systemd/system/gogs.service
echo '' >> /etc/systemd/system/gogs.service echo '' >> /etc/systemd/system/gogs.service
echo '[Install]' >> /etc/systemd/system/gogs.service echo '[Install]' >> /etc/systemd/system/gogs.service
echo 'WantedBy=multi-user.target' >> /etc/systemd/system/gogs.service echo 'WantedBy=multi-user.target' >> /etc/systemd/system/gogs.service
systemctl enable gogs systemctl enable gogs
systemctl daemon-reload systemctl daemon-reload
systemctl restart gogs systemctl restart gogs
if [ ! -d /var/www/$GIT_DOMAIN_NAME ]; then if [ ! -d /var/www/$GIT_DOMAIN_NAME ]; then
mkdir /var/www/$GIT_DOMAIN_NAME mkdir /var/www/$GIT_DOMAIN_NAME
fi fi
if [ -d /var/www/$GIT_DOMAIN_NAME/htdocs ]; then if [ -d /var/www/$GIT_DOMAIN_NAME/htdocs ]; then
rm -rf /var/www/$GIT_DOMAIN_NAME/htdocs rm -rf /var/www/$GIT_DOMAIN_NAME/htdocs
fi fi
if [[ $ONION_ONLY == "no" ]]; then if [[ $ONION_ONLY == "no" ]]; then
function_check nginx_http_redirect function_check nginx_http_redirect
nginx_http_redirect $GIT_DOMAIN_NAME nginx_http_redirect $GIT_DOMAIN_NAME
echo 'server {' >> /etc/nginx/sites-available/$GIT_DOMAIN_NAME echo 'server {' >> /etc/nginx/sites-available/$GIT_DOMAIN_NAME
echo ' listen 443 ssl;' >> /etc/nginx/sites-available/$GIT_DOMAIN_NAME echo ' listen 443 ssl;' >> /etc/nginx/sites-available/$GIT_DOMAIN_NAME
echo " root /var/www/$GIT_DOMAIN_NAME/htdocs;" >> /etc/nginx/sites-available/$GIT_DOMAIN_NAME echo " root /var/www/$GIT_DOMAIN_NAME/htdocs;" >> /etc/nginx/sites-available/$GIT_DOMAIN_NAME
echo " server_name $GIT_DOMAIN_NAME;" >> /etc/nginx/sites-available/$GIT_DOMAIN_NAME echo " server_name $GIT_DOMAIN_NAME;" >> /etc/nginx/sites-available/$GIT_DOMAIN_NAME
echo ' access_log off;' >> /etc/nginx/sites-available/$GIT_DOMAIN_NAME echo ' access_log off;' >> /etc/nginx/sites-available/$GIT_DOMAIN_NAME
echo " error_log /var/log/nginx/${GIT_DOMAIN_NAME}_error.log $WEBSERVER_LOG_LEVEL;" >> /etc/nginx/sites-available/$GIT_DOMAIN_NAME echo " error_log /var/log/nginx/${GIT_DOMAIN_NAME}_error.log $WEBSERVER_LOG_LEVEL;" >> /etc/nginx/sites-available/$GIT_DOMAIN_NAME
echo '' >> /etc/nginx/sites-available/$GIT_DOMAIN_NAME echo '' >> /etc/nginx/sites-available/$GIT_DOMAIN_NAME
function_check nginx_limits function_check nginx_limits
nginx_limits $GIT_DOMAIN_NAME '10G' nginx_limits $GIT_DOMAIN_NAME '10G'
function_check nginx_ssl function_check nginx_ssl
nginx_ssl $GIT_DOMAIN_NAME nginx_ssl $GIT_DOMAIN_NAME
function_check nginx_disable_sniffing function_check nginx_disable_sniffing
nginx_disable_sniffing $GIT_DOMAIN_NAME nginx_disable_sniffing $GIT_DOMAIN_NAME
echo ' add_header Strict-Transport-Security max-age=0;' >> /etc/nginx/sites-available/$GIT_DOMAIN_NAME echo ' add_header Strict-Transport-Security max-age=0;' >> /etc/nginx/sites-available/$GIT_DOMAIN_NAME
echo '' >> /etc/nginx/sites-available/$GIT_DOMAIN_NAME echo '' >> /etc/nginx/sites-available/$GIT_DOMAIN_NAME
echo ' location / {' >> /etc/nginx/sites-available/$GIT_DOMAIN_NAME echo ' location / {' >> /etc/nginx/sites-available/$GIT_DOMAIN_NAME
echo ' proxy_pass http://localhost:3000;' >> /etc/nginx/sites-available/$GIT_DOMAIN_NAME echo ' proxy_pass http://localhost:3000;' >> /etc/nginx/sites-available/$GIT_DOMAIN_NAME
echo ' }' >> /etc/nginx/sites-available/$GIT_DOMAIN_NAME echo ' }' >> /etc/nginx/sites-available/$GIT_DOMAIN_NAME
echo '' >> /etc/nginx/sites-available/$GIT_DOMAIN_NAME echo '' >> /etc/nginx/sites-available/$GIT_DOMAIN_NAME
echo ' fastcgi_buffers 64 4K;' >> /etc/nginx/sites-available/$GIT_DOMAIN_NAME echo ' fastcgi_buffers 64 4K;' >> /etc/nginx/sites-available/$GIT_DOMAIN_NAME
echo '' >> /etc/nginx/sites-available/$GIT_DOMAIN_NAME echo '' >> /etc/nginx/sites-available/$GIT_DOMAIN_NAME
echo ' error_page 403 /core/templates/403.php;' >> /etc/nginx/sites-available/$GIT_DOMAIN_NAME echo ' error_page 403 /core/templates/403.php;' >> /etc/nginx/sites-available/$GIT_DOMAIN_NAME
echo ' error_page 404 /core/templates/404.php;' >> /etc/nginx/sites-available/$GIT_DOMAIN_NAME echo ' error_page 404 /core/templates/404.php;' >> /etc/nginx/sites-available/$GIT_DOMAIN_NAME
echo '' >> /etc/nginx/sites-available/$GIT_DOMAIN_NAME echo '' >> /etc/nginx/sites-available/$GIT_DOMAIN_NAME
echo ' location = /robots.txt {' >> /etc/nginx/sites-available/$GIT_DOMAIN_NAME echo ' location = /robots.txt {' >> /etc/nginx/sites-available/$GIT_DOMAIN_NAME
echo ' allow all;' >> /etc/nginx/sites-available/$GIT_DOMAIN_NAME echo ' allow all;' >> /etc/nginx/sites-available/$GIT_DOMAIN_NAME
echo ' log_not_found off;' >> /etc/nginx/sites-available/$GIT_DOMAIN_NAME echo ' log_not_found off;' >> /etc/nginx/sites-available/$GIT_DOMAIN_NAME
echo ' access_log off;' >> /etc/nginx/sites-available/$GIT_DOMAIN_NAME echo ' access_log off;' >> /etc/nginx/sites-available/$GIT_DOMAIN_NAME
echo ' }' >> /etc/nginx/sites-available/$GIT_DOMAIN_NAME echo ' }' >> /etc/nginx/sites-available/$GIT_DOMAIN_NAME
echo '}' >> /etc/nginx/sites-available/$GIT_DOMAIN_NAME echo '}' >> /etc/nginx/sites-available/$GIT_DOMAIN_NAME
echo '' >> /etc/nginx/sites-available/$GIT_DOMAIN_NAME echo '' >> /etc/nginx/sites-available/$GIT_DOMAIN_NAME
else else
echo -n '' > /etc/nginx/sites-available/$GIT_DOMAIN_NAME echo -n '' > /etc/nginx/sites-available/$GIT_DOMAIN_NAME
fi fi
echo 'server {' >> /etc/nginx/sites-available/$GIT_DOMAIN_NAME echo 'server {' >> /etc/nginx/sites-available/$GIT_DOMAIN_NAME
echo " listen 127.0.0.1:${GIT_ONION_PORT} default_server;" >> /etc/nginx/sites-available/$GIT_DOMAIN_NAME echo " listen 127.0.0.1:${GIT_ONION_PORT} default_server;" >> /etc/nginx/sites-available/$GIT_DOMAIN_NAME
echo " root /var/www/$GIT_DOMAIN_NAME/htdocs;" >> /etc/nginx/sites-available/$GIT_DOMAIN_NAME echo " root /var/www/$GIT_DOMAIN_NAME/htdocs;" >> /etc/nginx/sites-available/$GIT_DOMAIN_NAME
echo " server_name $GIT_DOMAIN_NAME;" >> /etc/nginx/sites-available/$GIT_DOMAIN_NAME echo " server_name $GIT_DOMAIN_NAME;" >> /etc/nginx/sites-available/$GIT_DOMAIN_NAME
echo ' access_log off;' >> /etc/nginx/sites-available/$GIT_DOMAIN_NAME echo ' access_log off;' >> /etc/nginx/sites-available/$GIT_DOMAIN_NAME
echo " error_log /var/log/nginx/${GIT_DOMAIN_NAME}_error.log $WEBSERVER_LOG_LEVEL;" >> /etc/nginx/sites-available/$GIT_DOMAIN_NAME echo " error_log /var/log/nginx/${GIT_DOMAIN_NAME}_error.log $WEBSERVER_LOG_LEVEL;" >> /etc/nginx/sites-available/$GIT_DOMAIN_NAME
echo '' >> /etc/nginx/sites-available/$GIT_DOMAIN_NAME echo '' >> /etc/nginx/sites-available/$GIT_DOMAIN_NAME
function_check nginx_limits function_check nginx_limits
nginx_limits $GIT_DOMAIN_NAME '10G' nginx_limits $GIT_DOMAIN_NAME '10G'
function_check nginx_disable_sniffing function_check nginx_disable_sniffing
nginx_disable_sniffing $GIT_DOMAIN_NAME nginx_disable_sniffing $GIT_DOMAIN_NAME
echo ' add_header Strict-Transport-Security max-age=0;' >> /etc/nginx/sites-available/$GIT_DOMAIN_NAME echo ' add_header Strict-Transport-Security max-age=0;' >> /etc/nginx/sites-available/$GIT_DOMAIN_NAME
echo '' >> /etc/nginx/sites-available/$GIT_DOMAIN_NAME echo '' >> /etc/nginx/sites-available/$GIT_DOMAIN_NAME
echo ' location / {' >> /etc/nginx/sites-available/$GIT_DOMAIN_NAME echo ' location / {' >> /etc/nginx/sites-available/$GIT_DOMAIN_NAME
echo ' proxy_pass http://localhost:3000;' >> /etc/nginx/sites-available/$GIT_DOMAIN_NAME echo ' proxy_pass http://localhost:3000;' >> /etc/nginx/sites-available/$GIT_DOMAIN_NAME
echo ' }' >> /etc/nginx/sites-available/$GIT_DOMAIN_NAME echo ' }' >> /etc/nginx/sites-available/$GIT_DOMAIN_NAME
echo '' >> /etc/nginx/sites-available/$GIT_DOMAIN_NAME echo '' >> /etc/nginx/sites-available/$GIT_DOMAIN_NAME
echo ' fastcgi_buffers 64 4K;' >> /etc/nginx/sites-available/$GIT_DOMAIN_NAME echo ' fastcgi_buffers 64 4K;' >> /etc/nginx/sites-available/$GIT_DOMAIN_NAME
echo '' >> /etc/nginx/sites-available/$GIT_DOMAIN_NAME echo '' >> /etc/nginx/sites-available/$GIT_DOMAIN_NAME
echo ' error_page 403 /core/templates/403.php;' >> /etc/nginx/sites-available/$GIT_DOMAIN_NAME echo ' error_page 403 /core/templates/403.php;' >> /etc/nginx/sites-available/$GIT_DOMAIN_NAME
echo ' error_page 404 /core/templates/404.php;' >> /etc/nginx/sites-available/$GIT_DOMAIN_NAME echo ' error_page 404 /core/templates/404.php;' >> /etc/nginx/sites-available/$GIT_DOMAIN_NAME
echo '' >> /etc/nginx/sites-available/$GIT_DOMAIN_NAME echo '' >> /etc/nginx/sites-available/$GIT_DOMAIN_NAME
echo ' location = /robots.txt {' >> /etc/nginx/sites-available/$GIT_DOMAIN_NAME echo ' location = /robots.txt {' >> /etc/nginx/sites-available/$GIT_DOMAIN_NAME
echo ' allow all;' >> /etc/nginx/sites-available/$GIT_DOMAIN_NAME echo ' allow all;' >> /etc/nginx/sites-available/$GIT_DOMAIN_NAME
echo ' log_not_found off;' >> /etc/nginx/sites-available/$GIT_DOMAIN_NAME echo ' log_not_found off;' >> /etc/nginx/sites-available/$GIT_DOMAIN_NAME
echo ' access_log off;' >> /etc/nginx/sites-available/$GIT_DOMAIN_NAME echo ' access_log off;' >> /etc/nginx/sites-available/$GIT_DOMAIN_NAME
echo ' }' >> /etc/nginx/sites-available/$GIT_DOMAIN_NAME echo ' }' >> /etc/nginx/sites-available/$GIT_DOMAIN_NAME
echo '}' >> /etc/nginx/sites-available/$GIT_DOMAIN_NAME echo '}' >> /etc/nginx/sites-available/$GIT_DOMAIN_NAME
function_check configure_php function_check configure_php
configure_php configure_php
function_check create_site_certificate function_check create_site_certificate
create_site_certificate $GIT_DOMAIN_NAME 'yes' create_site_certificate $GIT_DOMAIN_NAME 'yes'
nginx_ensite $GIT_DOMAIN_NAME nginx_ensite $GIT_DOMAIN_NAME
if [ ! -d /var/lib/tor ]; then if [ ! -d /var/lib/tor ]; then
echo $'No Tor installation found. Gogs onion site cannot be configured.' echo $'No Tor installation found. Gogs onion site cannot be configured.'
exit 877367 exit 877367
fi fi
if ! grep -q "hidden_service_gogs" /etc/tor/torrc; then if ! grep -q "hidden_service_gogs" /etc/tor/torrc; then
echo 'HiddenServiceDir /var/lib/tor/hidden_service_gogs/' >> /etc/tor/torrc echo 'HiddenServiceDir /var/lib/tor/hidden_service_gogs/' >> /etc/tor/torrc
echo "HiddenServicePort 80 127.0.0.1:${GIT_ONION_PORT}" >> /etc/tor/torrc echo "HiddenServicePort 80 127.0.0.1:${GIT_ONION_PORT}" >> /etc/tor/torrc
echo "HiddenServicePort 9418 127.0.0.1:9418" >> /etc/tor/torrc echo "HiddenServicePort 9418 127.0.0.1:9418" >> /etc/tor/torrc
echo $'Added onion site for Gogs' echo $'Added onion site for Gogs'
fi fi
systemctl restart tor systemctl restart tor
function_check wait_for_onion_service function_check wait_for_onion_service
wait_for_onion_service 'gogs' wait_for_onion_service 'gogs'
GIT_ONION_HOSTNAME=$(cat /var/lib/tor/hidden_service_gogs/hostname) GIT_ONION_HOSTNAME=$(cat /var/lib/tor/hidden_service_gogs/hostname)
systemctl restart php5-fpm systemctl restart php5-fpm
systemctl restart nginx systemctl restart nginx
if ! grep -q "Gogs onion domain" /home/$MY_USERNAME/README; then if ! grep -q "Gogs onion domain" /home/$MY_USERNAME/README; then
echo "Gogs onion domain: ${GIT_ONION_HOSTNAME}" >> /home/$MY_USERNAME/README echo "Gogs onion domain: ${GIT_ONION_HOSTNAME}" >> /home/$MY_USERNAME/README
echo '' >> /home/$MY_USERNAME/README echo '' >> /home/$MY_USERNAME/README
chown $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/README chown $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/README
chmod 600 /home/$MY_USERNAME/README chmod 600 /home/$MY_USERNAME/README
fi fi
if ! grep -q "Gogs onion domain" $COMPLETION_FILE; then if ! grep -q "Gogs onion domain" $COMPLETION_FILE; then
echo "Gogs onion domain:${GIT_ONION_HOSTNAME}" >> $COMPLETION_FILE echo "Gogs onion domain:${GIT_ONION_HOSTNAME}" >> $COMPLETION_FILE
fi fi
function_check add_ddns_domain function_check add_ddns_domain
add_ddns_domain $GIT_DOMAIN_NAME add_ddns_domain $GIT_DOMAIN_NAME
# obtain the secret key # obtain the secret key
GOGS_SECRET_KEY= GOGS_SECRET_KEY=
if grep -q "Gogs secret key:" /home/$MY_USERNAME/README; then if grep -q "Gogs secret key:" /home/$MY_USERNAME/README; then
GOGS_SECRET_KEY=$(cat /home/$MY_USERNAME/README | grep "Gogs secret key:" | awk -F ':' '{print $2}' | sed 's/^ *//') GOGS_SECRET_KEY=$(cat /home/$MY_USERNAME/README | grep "Gogs secret key:" | awk -F ':' '{print $2}' | sed 's/^ *//')
else else
GOGS_SECRET_KEY="$(create_password ${MINIMUM_PASSWORD_LENGTH})" GOGS_SECRET_KEY="$(create_password ${MINIMUM_PASSWORD_LENGTH})"
echo "Gogs secret key:$GOGS_SECRET_KEY" >> /home/$MY_USERNAME/README echo "Gogs secret key:$GOGS_SECRET_KEY" >> /home/$MY_USERNAME/README
chown $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/README chown $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/README
fi fi
# create the configuration # create the configuration
GOGS_CONFIG_PATH=/home/git/gvm/pkgsets/go${GO_VERSION}/global/src/github.com/gogits/gogs/custom/conf GOGS_CONFIG_PATH=/home/git/gvm/pkgsets/go${GO_VERSION}/global/src/github.com/gogits/gogs/custom/conf
if [ ! -d $GOGS_CONFIG_PATH ]; then if [ ! -d $GOGS_CONFIG_PATH ]; then
mkdir -p $GOGS_CONFIG_PATH mkdir -p $GOGS_CONFIG_PATH
fi fi
GOGS_CONFIG_FILE=$GOGS_CONFIG_PATH/app.ini GOGS_CONFIG_FILE=$GOGS_CONFIG_PATH/app.ini
echo 'RUN_USER = git' > $GOGS_CONFIG_FILE echo 'RUN_USER = git' > $GOGS_CONFIG_FILE
echo 'RUN_MODE = prod' >> $GOGS_CONFIG_FILE echo 'RUN_MODE = prod' >> $GOGS_CONFIG_FILE
echo '' >> $GOGS_CONFIG_FILE echo '' >> $GOGS_CONFIG_FILE
echo '[database]' >> $GOGS_CONFIG_FILE echo '[database]' >> $GOGS_CONFIG_FILE
echo 'DB_TYPE = mysql' >> $GOGS_CONFIG_FILE echo 'DB_TYPE = mysql' >> $GOGS_CONFIG_FILE
echo 'HOST = 127.0.0.1:3306' >> $GOGS_CONFIG_FILE echo 'HOST = 127.0.0.1:3306' >> $GOGS_CONFIG_FILE
echo 'NAME = gogs' >> $GOGS_CONFIG_FILE echo 'NAME = gogs' >> $GOGS_CONFIG_FILE
echo 'USER = root' >> $GOGS_CONFIG_FILE echo 'USER = root' >> $GOGS_CONFIG_FILE
echo "PASSWD = $MARIADB_PASSWORD" >> $GOGS_CONFIG_FILE echo "PASSWD = $MARIADB_PASSWORD" >> $GOGS_CONFIG_FILE
echo 'SSL_MODE = disable' >> $GOGS_CONFIG_FILE echo 'SSL_MODE = disable' >> $GOGS_CONFIG_FILE
echo 'PATH = data/gogs.db' >> $GOGS_CONFIG_FILE echo 'PATH = data/gogs.db' >> $GOGS_CONFIG_FILE
echo '' >> $GOGS_CONFIG_FILE echo '' >> $GOGS_CONFIG_FILE
echo '[repository]' >> $GOGS_CONFIG_FILE echo '[repository]' >> $GOGS_CONFIG_FILE
echo 'ROOT = /home/git/gogs-repositories' >> $GOGS_CONFIG_FILE echo 'ROOT = /home/git/gogs-repositories' >> $GOGS_CONFIG_FILE
echo '' >> $GOGS_CONFIG_FILE echo '' >> $GOGS_CONFIG_FILE
echo '[server]' >> $GOGS_CONFIG_FILE echo '[server]' >> $GOGS_CONFIG_FILE
if [[ $ONION_ONLY == 'no' ]]; then if [[ $ONION_ONLY == 'no' ]]; then
echo "DOMAIN = ${GIT_DOMAIN_NAME}" >> $GOGS_CONFIG_FILE echo "DOMAIN = ${GIT_DOMAIN_NAME}" >> $GOGS_CONFIG_FILE
else else
echo "DOMAIN = ${GIT_ONION_HOSTNAME}" >> $GOGS_CONFIG_FILE echo "DOMAIN = ${GIT_ONION_HOSTNAME}" >> $GOGS_CONFIG_FILE
fi fi
echo 'HTTP_PORT = 3000' >> $GOGS_CONFIG_FILE echo 'HTTP_PORT = 3000' >> $GOGS_CONFIG_FILE
echo "ROOT_URL = http://$GIT_DOMAIN_NAME/" >> $GOGS_CONFIG_FILE echo "ROOT_URL = http://$GIT_DOMAIN_NAME/" >> $GOGS_CONFIG_FILE
echo "SSH_PORT = $SSH_PORT" >> $GOGS_CONFIG_FILE echo "SSH_PORT = $SSH_PORT" >> $GOGS_CONFIG_FILE
echo 'SSH_DOMAIN = %(DOMAIN)s' >> $GOGS_CONFIG_FILE echo 'SSH_DOMAIN = %(DOMAIN)s' >> $GOGS_CONFIG_FILE
echo "CERT_FILE = /etc/ssl/certs/${GIT_DOMAIN_NAME}.crt" >> $GOGS_CONFIG_FILE echo "CERT_FILE = /etc/ssl/certs/${GIT_DOMAIN_NAME}.crt" >> $GOGS_CONFIG_FILE
echo "KEY_FILE = /etc/ssl/private/${GIT_DOMAIN_NAME}.key" >> $GOGS_CONFIG_FILE echo "KEY_FILE = /etc/ssl/private/${GIT_DOMAIN_NAME}.key" >> $GOGS_CONFIG_FILE
echo 'DISABLE_ROUTER_LOG = true' >> $GOGS_CONFIG_FILE echo 'DISABLE_ROUTER_LOG = true' >> $GOGS_CONFIG_FILE
echo '' >> $GOGS_CONFIG_FILE echo '' >> $GOGS_CONFIG_FILE
echo '[session]' >> $GOGS_CONFIG_FILE echo '[session]' >> $GOGS_CONFIG_FILE
echo 'PROVIDER = file' >> $GOGS_CONFIG_FILE echo 'PROVIDER = file' >> $GOGS_CONFIG_FILE
echo '' >> $GOGS_CONFIG_FILE echo '' >> $GOGS_CONFIG_FILE
echo '[log]' >> $GOGS_CONFIG_FILE echo '[log]' >> $GOGS_CONFIG_FILE
echo 'MODE = file' >> $GOGS_CONFIG_FILE echo 'MODE = file' >> $GOGS_CONFIG_FILE
echo 'LEVEL = Info' >> $GOGS_CONFIG_FILE echo 'LEVEL = Info' >> $GOGS_CONFIG_FILE
echo '' >> $GOGS_CONFIG_FILE echo '' >> $GOGS_CONFIG_FILE
echo '[security]' >> $GOGS_CONFIG_FILE echo '[security]' >> $GOGS_CONFIG_FILE
echo 'INSTALL_LOCK = true' >> $GOGS_CONFIG_FILE echo 'INSTALL_LOCK = true' >> $GOGS_CONFIG_FILE
echo "SECRET_KEY = $GOGS_SECRET_KEY" >> $GOGS_CONFIG_FILE echo "SECRET_KEY = $GOGS_SECRET_KEY" >> $GOGS_CONFIG_FILE
echo '' >> $GOGS_CONFIG_FILE echo '' >> $GOGS_CONFIG_FILE
echo '[service]' >> $GOGS_CONFIG_FILE echo '[service]' >> $GOGS_CONFIG_FILE
echo 'DISABLE_REGISTRATION = false' >> $GOGS_CONFIG_FILE echo 'DISABLE_REGISTRATION = false' >> $GOGS_CONFIG_FILE
echo 'SHOW_REGISTRATION_BUTTON = true' >> $GOGS_CONFIG_FILE echo 'SHOW_REGISTRATION_BUTTON = true' >> $GOGS_CONFIG_FILE
echo 'REQUIRE_SIGNIN_VIEW = false' >> $GOGS_CONFIG_FILE echo 'REQUIRE_SIGNIN_VIEW = false' >> $GOGS_CONFIG_FILE
echo 'ENABLE_CAPTCHA = false' >> $GOGS_CONFIG_FILE echo 'ENABLE_CAPTCHA = false' >> $GOGS_CONFIG_FILE
echo '' >> $GOGS_CONFIG_FILE echo '' >> $GOGS_CONFIG_FILE
echo '[other]' >> $GOGS_CONFIG_FILE echo '[other]' >> $GOGS_CONFIG_FILE
echo 'SHOW_FOOTER_BRANDING = false' >> $GOGS_CONFIG_FILE echo 'SHOW_FOOTER_BRANDING = false' >> $GOGS_CONFIG_FILE
echo 'SHOW_FOOTER_VERSION = false' >> $GOGS_CONFIG_FILE echo 'SHOW_FOOTER_VERSION = false' >> $GOGS_CONFIG_FILE
chmod 750 $GOGS_CONFIG_FILE chmod 750 $GOGS_CONFIG_FILE
chown -R git:git /home/git chown -R git:git /home/git
systemctl restart gogs systemctl restart gogs
if ! grep -q "Gogs domain:" $COMPLETION_FILE; then if ! grep -q "Gogs domain:" $COMPLETION_FILE; then
echo "Gogs domain:$GIT_DOMAIN_NAME" >> $COMPLETION_FILE echo "Gogs domain:$GIT_DOMAIN_NAME" >> $COMPLETION_FILE
fi fi
function_check configure_firewall_for_git function_check configure_firewall_for_git
configure_firewall_for_git configure_firewall_for_git
echo 'install_gogs' >> $COMPLETION_FILE echo 'install_gogs' >> $COMPLETION_FILE
} }
# NOTE: deliberately no exit 0 # NOTE: deliberately no exit 0
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment