Browse Source

First commit

master
Ron Nnn 8 months ago
commit
cf8bfdec6e
7 changed files with 188 additions and 0 deletions
  1. +7
    -0
      .gitignore
  2. +19
    -0
      LICENSE
  3. +79
    -0
      README.md
  4. +10
    -0
      example-macros.m4
  5. +25
    -0
      generate-macros.rb
  6. +27
    -0
      generate-macros.sh
  7. +21
    -0
      update-gitea.m4

+ 7
- 0
.gitignore View File

@@ -0,0 +1,7 @@
# Ignore emacs backup and auto-save files
*~
\#*\#

# Ignore generated files
update-gitea.sh
macros.m4

+ 19
- 0
LICENSE View File

@@ -0,0 +1,19 @@
Copyright (c) 2019 Noisytoot

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

+ 79
- 0
README.md View File

@@ -0,0 +1,79 @@
# Gitea updater script
A script to update Gitea, generated from m4 macros

## Explanation of files
generate-macros.rb
: Ruby script to generate macros.m4, uses Readline
generate-macros.sh
: Shell script to generate macros.m4, does not use Readline
macros.m4
: File with various macros used by update-gitea.m4
update-gitea.m4
: File with template for update-gitea.sh
example-macros.m4
: Example macros.m4 file
update-gitea.sh
: Generated script for updating gitea

The difference between generate-macros.rb, and generate-macros.sh is that the Ruby version uses Readline,
and the shell script version does not

## Generate script
1. Generate macros.m4
There are 2 methods: using generate-macros.rb/generate-macros.sh, or manually
* Using generate-macros.rb/generate-macros.sh
Use generate-macros.rb (recommended) or generate-macros.sh to generate macros.m4:
Run
```sh
./generate-macros.rb
```
or
```sh
./generate-macros.sh
```
and answer the questions
* Manually
Write a file like this:
```m4
dnl -*- mode: m4 -*-
dnl Example macro definitions
changequote([, ])dnl
define(start_gitea, [systemctl start gitea.service])dnl Command to start Gitea
define(stop_gitea, [systemctl stop gitea.service])dnl Command to stop Gitea
define(user, [git])dnl User with write access to directory containing Gitea binary
define(do_as_user, [sudo -u])dnl Command to run as user
define(gitea_binary_dir, [~git/gitea])dnl Directory containing Gitea binary
define(os, linux)dnl Operating System (must be one of "darwin", "linux", or "windows-4.0")
define(arch, amd64)dnl CPU Architechture (must be one of "386", "amd64", "arm-5", "arm-6", "mips", "mips64le", or "mipsle")

```
to macros.m4
2. Process update-gitea.m4 to generate update-gitea.sh
Run
```sh
m4 update-gitea.m4 > update-gitea.sh
```
## Usage
Note: all commands must be run as root
### Download required version of Gitea
Run
```sh
./update-gitea.sh get <gitea-version>
```
where `<gitea-version>` is the version of gitea you want, to download the version of gitea you want
### Update Gitea
Run
```sh
./update-gitea
```
to update Gitea, this leaves a gitea-old file in gitea\_binary\_dir, this is the old Gitea binary,
it can be used to roll-back to a previous version
### Cleanup
Run
```sh
./update-gitea cleanup
```
to delete gitea\_binary\_dir/gitea-old

# License
update-gitea is licensed under the MIT/Expat license

+ 10
- 0
example-macros.m4 View File

@@ -0,0 +1,10 @@
dnl -*- mode: m4 -*-
dnl Example macro definitions
changequote([, ])dnl
define(start_gitea, [systemctl start gitea.service])dnl Command to start Gitea
define(stop_gitea, [systemctl stop gitea.service])dnl Command to stop Gitea
define(user, git)dnl User with write access to directory containing Gitea binary
define(do_as_user, [sudo -u])dnl Command to run as user
define(gitea_binary_dir, ~git/gitea)dnl Directory containing Gitea binary
define(os, linux)dnl Operating System (must be one of "darwin", "linux", or "windows-4.0")
define(arch, amd64)dnl CPU Architechture (must be one of "386", "amd64", "arm-5", "arm-6", "mips", "mips64le", or "mipsle")

+ 25
- 0
generate-macros.rb View File

@@ -0,0 +1,25 @@
#!/usr/bin/env ruby
require 'readline'

start_gitea = Readline.readline "Command to start Gitea: ", true
stop_gitea = Readline.readline "Command to stop Gitea: ", true
user = Readline.readline "User with write access to directory containing Gitea binary: ", true
do_as_user = Readline.readline "Command to run as user: ", true
gitea_binary_dir = Readline.readline "Directory containing Gitea binary: ", true
os = Readline.readline 'Operating System (must be one of "darwin", "linux", or "windows-4.0"): ', true
arch = Readline.readline 'CPU Architechture (must be one of "386", "amd64", "arm-5", "arm-6", "mips", "mips64le", or "mipsle"): ', true

f = File::open 'macros.m4', 'w'
f.write <<EOF
dnl -*- mode: m4 -*-
dnl Macro definitions
changequote([, ])dnl
define(start_gitea, [#{start_gitea}])dnl Command to start Gitea
define(stop_gitea, [#{stop_gitea}])dnl Command to stop Gitea
define(user, [#{user}])dnl User with write access to directory containing Gitea binary
define(do_as_user, [#{do_as_user}])dnl Command to run as user
define(gitea_binary_dir, [#{gitea_binary_dir}])dnl Directory containing Gitea binary
define(os, [#{os}])dnl Operating System (must be one of "darwin", "linux", or "windows-4.0")
define(arch, [#{arch}])dnl CPU Architechture (must be one of "386", "amd64", "arm-5", "arm-6", "mips", "mips64le", or "mipsle")
EOF
f.close

+ 27
- 0
generate-macros.sh View File

@@ -0,0 +1,27 @@
#!/bin/sh
printf '%s: ' "Command to start Gitea"
read start_gitea
printf '%s: ' "Command to stop Gitea"
read stop_gitea
printf '%s: ' "User with write access to directory containing Gitea binary"
read user
printf '%s: ' "Command to run as user"
read do_as_user
printf '%s: ' "Directory containing Gitea binary"
read gitea_binary_dir
printf '%s: ' 'Operating System (must be one of "darwin", "linux", or "windows-4.0")'
read arch
printf '%s: ' 'CPU Architechture (must be one of "386", "amd64", "arm-5", "arm-6", "mips", "mips64le", or "mipsle")'

cat <<EOF > macros.m4
dnl -*- mode: m4 -*-
dnl Macro definitions
changequote([, ])dnl
define(start_gitea, [$start_gitea])dnl Command to start Gitea
define(stop_gitea, [$stop_gitea])dnl Command to stop Gitea
define(user, [$user])dnl User with write access to directory containing Gitea binary
define(do_as_user, [$do_as_user])dnl Command to run as user
define(gitea_binary_dir, [$gitea_binary_dir])dnl Directory containing Gitea binary
define(os, [$os])dnl Operating System (must be one of "darwin", "linux", or "windows-4.0")
define(arch, [$arch])dnl CPU Architechture (must be one of "386", "amd64", "arm-5", "arm-6", "mips", "mips64le", or "mipsle")
EOF

+ 21
- 0
update-gitea.m4 View File

@@ -0,0 +1,21 @@
#!/bin/sh
include(macros.m4)dnl
if [[ ! $(id -u) = $(0 + 0) ]]; then
echo "Error: must be run as root (UID 0)" > /dev/stderr
fi

if [[ "$1" = "cleanup" ]]; then
do_as_user user rm gitea_binary_dir/gitea-old
exit 0
fi

if [[ "$1" = "get" ]]; then
gitea_version="$2"
wget -O gitea_binary_dir/gitea-new "https://dl.gitea.io/gitea/$gitea_version/gitea-${gitea_version}-os-arch"
exit 0
fi

stop_gitea
do_as_user user cp gitea_binary_dir/gitea gitea_binary_dir/gitea-old
do_as_user user mv gitea_binary_dir/gitea-new gitea_binary_dir/gitea
start_gitea

Loading…
Cancel
Save