Commit 42b66170 authored by Markus Seidl's avatar Markus Seidl

* Moved scripts to /scripts

* Added upgrade functionality
* Enhanced /disk_free command
parent 76a0e8d7
......@@ -6,6 +6,7 @@ import (
"io/ioutil"
"log"
"os"
"os/exec"
"rgifbot/config"
"strings"
"syscall"
......@@ -47,10 +48,34 @@ func CCTelegramLoop(handler func(message Message) (timestamp time.Time, err erro
registerExitCommand(b)
registerPasswordCommand(b)
registerDiskFreeCommand(b)
registerUpgradeCommand(b)
b.Start()
}
func registerUpgradeCommand(b *tb.Bot) {
b.Handle("/upgrade", func(m *tb.Message) {
if !isAllowed(b, m) {
return
}
_, _ = b.Send(m.Sender, fmt.Sprintf("Upgrade started..."))
app := "./scripts/upgrade.sh"
cmd := &exec.Cmd{
Path: app,
Args: []string{},
}
log.Printf("Executing: %s", app)
temp, err := cmd.CombinedOutput()
log.Print(err)
log.Print(string(temp))
_, _ = b.Send(m.Sender, fmt.Sprintf("... upgraded. Please restart."))
})
}
func registerDiskFreeCommand(b *tb.Bot) {
b.Handle("/disk_free", func(m *tb.Message) {
if !isAllowed(b, m) {
......@@ -72,11 +97,21 @@ func registerDiskFreeCommand(b *tb.Bot) {
avail := float32(stat.Bavail * uint64(stat.Bsize))
unit := "Bytes"
if avail < 1024 {
if avail > 1024 {
avail = avail / 1024
unit = "KB"
if avail > 1024 {
avail = avail / 1024
unit = "MB"
if avail > 1024 {
avail = avail / 1024
unit = "GB"
}
}
}
_, _ = b.Send(m.Sender, fmt.Sprintf("Disk free %g %s", avail, unit))
_, _ = b.Send(m.Sender, fmt.Sprintf("Disk free %4f %s", avail, unit))
})
}
......
......@@ -7,9 +7,11 @@ import (
"os/exec"
)
const ffmpegLocation = "./ffmpeg.sh"
const ffmpegLocation = "./scripts/ffmpeg.sh"
func Convert(infile *os.File) (outfile *os.File) {
log.Fatalln("Unsupported and doesn't work currently ...")
_ = infile.Sync() // make sure everything is on disk
// we are making a switch, so the infile is supposed to be closed outside, but we close it in this function
......@@ -20,10 +22,11 @@ func Convert(infile *os.File) (outfile *os.File) {
log.Printf("Error while creating tempfile <%s>", err.Error())
}
args := []string{infile.Name(), outfile.Name(), "test"}
// THIS IS WHY IT DOESN'T WORK: somehow go removes outfile.Name() from the call and the script doesn't pick it up
// When using ffmpeg directly, it can't parse "-loop 1" or "-loop", "1" :/
args := []string{infile.Name(), outfile.Name()}
// ffmpeg -loop 1 -i koala.png -c:v libx264 -t 5 -pix_fmt yuv420p -vf scale=1920:1080 out.mp4
// args = append(args, infile.Name(), outfile.Name(), "test")
app := ffmpegLocation
cmd := &exec.Cmd{
......
#!/bin/bash -xe
GIT=/usr/bin/git
GO=/usr/local/go
git pull --rebase
go build
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment