Compare commits

..

12 Commits

Author SHA1 Message Date
6b2118b53f Update extra/product.mk
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/promote/syncbuild Build is passing
continuous-integration/drone Build is passing
2024-11-11 06:25:50 -07:00
a09647cbaf go 1.23 isn't even out yet!
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone Build is passing
2024-06-28 12:00:56 -06:00
9b3302dcf3 move from deadbeef.codes to code.stevenpolley.net
Some checks failed
continuous-integration/drone/push Build is failing
2024-06-28 11:55:35 -06:00
fb5b9864d9 Update README.md
Some checks failed
continuous-integration/drone/push Build is passing
continuous-integration/drone Build is failing
2023-09-11 17:38:31 +00:00
f72a33148d Update README.md
All checks were successful
continuous-integration/drone/push Build is passing
2023-09-11 17:37:53 +00:00
5bdda0259a Add configurable baseURL (required for multi-device support)
All checks were successful
continuous-integration/drone/push Build is passing
2023-08-21 19:47:49 -06:00
0b5eb36b5a Update docker compose example for device specific folder
All checks were successful
continuous-integration/drone/push Build is passing
2023-08-19 21:58:25 -06:00
2921f5a76f update readme for device-specific ota URLs
All checks were successful
continuous-integration/drone/push Build is passing
2023-08-19 21:52:24 -06:00
1f3209f55e fix string formatting bug causing mangled id's
All checks were successful
continuous-integration/drone/push Build is passing
2023-07-10 18:08:34 -06:00
238dab70fe more appropriate function name
All checks were successful
continuous-integration/drone/push Build is passing
2023-06-30 20:14:34 -06:00
75668ad531 use simple type conversion instead fmt package 2023-06-30 20:12:44 -06:00
f308e4351a update comments 2023-06-30 20:11:49 -06:00
5 changed files with 29 additions and 26 deletions

View File

@ -3,7 +3,7 @@ name: default
workspace:
base: /go
path: src/deadbeef.codes/steven/lineageos-ota-server
path: src/code.stevenpolley.net/steven/lineageos-ota-server
steps:
@ -22,4 +22,4 @@ steps:
- name: package in docker container
image: plugins/docker
settings:
repo: registry.deadbeef.codes/lineageos-ota-server
repo: registry.stevenpolley.net/lineageos-ota-server

View File

@ -24,7 +24,7 @@ version: '3.8'
- "8080"
volumes:
- /data/android/lineage/out/target/product/sunfish:/out
- /data/android/public:/public
- /data/android/public/sunfish:/public
```
@ -34,21 +34,17 @@ The recommended way is to include the configuration inside your build of the ROM
Create new file /data/android/lineage/vendor/lineage/build/core/deadbeef-ota.mk
```makefile
# deadbeef.codes LineageOS OTA update server - replace with your own URL
ADDITIONAL_SYSTEM_PROPERTIES += \
lineage.updater.uri=https://lineageos-ota.deadbeef.codes
```
Edit /data/android/lineage/vendor/lineage/build/core/main.mk to include deadbeef-ota.mk
Edit (create if not exist) /data/android/lineage/vendor/extra/product.mk
```makefile
# Include LineageOS versions
include $(TOPDIR)vendor/lineage/build/core/main_version.mk
# Include deadbeef.codes OTA server
include $(TOPDIR)vendor/lineage/build/core/deadbeef-ota.mk
PRODUCT_SYSTEM_DEFAULT_PROPERTIES += \
lineage.updater.uri=https://lineageos-ota-{device}.stevenpolley.net
# Default ADB shell
PRODUCT_SYSTEM_DEFAULT_PROPERTIES += \
persist.sys.adb.shell=/system_ext/bin/bash
```

2
go.mod
View File

@ -1,3 +1,3 @@
module deadbeef.codes/steven/lineageos-ota-server
go 1.20
go 1.22

21
main.go
View File

@ -36,16 +36,21 @@ type ROMCache struct {
const (
romDirectory = "public" // directory where ROMs are available for download
buildOutDirectory = "out" // directory from build system containing artifacts which we can move to romDirectory
cacheFile = "public/romcache.json"
cacheFile = "public/romcache.json" // persistence between server restarts so we don't have to rehash all the ROM files each time the program starts
)
var ( // evil global variable
var ( // evil global variables
romCache ROMCache
baseURL string
)
func init() {
// intialize and load ROMCache from file - so we don't have to rehash all the big files again
romCache = ROMCache{}
baseURL = os.Getenv("baseurl")
if len(baseURL) < 1 {
log.Fatalf("required environment variable 'baseurl' is not set.")
}
romCacheJson, err := os.ReadFile(cacheFile)
if err != nil {
@ -67,7 +72,7 @@ func init() {
log.Printf("loaded cached file: %s", rom.Filename)
}
// Check if any new build artifacts and preload the romCache
// Check if any new build artifacts and load any new files into the romCache
moveBuildArtifacts()
go updateROMCache()
}
@ -106,7 +111,7 @@ func updateROMCache() {
for i, v := range files {
isLineageROM, splitName := isLineageROMZip(v)
isLineageROM, splitName := parseROMFileName(v)
if !isLineageROM {
continue
}
@ -140,7 +145,7 @@ func updateROMCache() {
ID: fileHash,
Romtype: splitName[3], // UNOFFICIAL
Size: int(fInfo.Size()),
URL: fmt.Sprintf("https://lineageos-ota.deadbeef.codes/public/%s", v.Name()),
URL: fmt.Sprintf("%s/public/%s", baseURL, v.Name()),
Version: splitName[1],
}
@ -179,9 +184,11 @@ func updateROMCache() {
}
// http - GET /
// Writes JSON response for the updater app to know what versions are available to download
// The LineageOS updater app needs a JSON array of type LineageOSROM
// Marshal's romCache.ROMs to JSON to serve as the response body
func lineageOSROMListHandler(w http.ResponseWriter, r *http.Request) {
go func() {
go func() { // Also checks for new builds - TBD need a better method as the first request will return no new updates. inotify?
newBuilds := moveBuildArtifacts()
if newBuilds {
updateROMCache()

View File

@ -30,7 +30,7 @@ func moveBuildArtifacts() bool {
var newROMs bool
for _, v := range files {
if isLineageROM, _ := isLineageROMZip(v); !isLineageROM { // skip files that aren't LineageOS ROMs
if isLineageROM, _ := parseROMFileName(v); !isLineageROM { // skip files that aren't LineageOS ROMs
continue
}
@ -68,7 +68,7 @@ func hashFile(filename string) (string, error) {
// no formal validation is performed - only file naming convention is checked
// also returns a lineage ROM's filename sliced and delimited by -'s
// Example filename: lineage-20.0-20230604-UNOFFICIAL-sunfish.zip
func isLineageROMZip(v fs.DirEntry) (bool, []string) {
func parseROMFileName(v fs.DirEntry) (bool, []string) {
// skip directories, non .zip files and files that don't begin with lineage-
if v.Type().IsDir() || !strings.HasSuffix(v.Name(), ".zip") || !strings.HasPrefix(v.Name(), "lineage-") {