Compare commits
12 Commits
120d61d1b6
...
main
Author | SHA1 | Date | |
---|---|---|---|
6b2118b53f | |||
a09647cbaf | |||
9b3302dcf3 | |||
fb5b9864d9 | |||
f72a33148d | |||
5bdda0259a | |||
0b5eb36b5a | |||
2921f5a76f | |||
1f3209f55e | |||
238dab70fe | |||
75668ad531 | |||
f308e4351a |
@ -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
|
||||
|
20
README.md
20
README.md
@ -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
|
||||
|
||||
```
|
21
main.go
21
main.go
@ -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()
|
||||
|
@ -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-") {
|
||||
|
Reference in New Issue
Block a user