39 lines
704 B
Go
39 lines
704 B
Go
package config
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
)
|
|
|
|
func panicIfErr(e error) {
|
|
if e != nil {
|
|
panic(e)
|
|
}
|
|
}
|
|
|
|
func touchFile(file string) {
|
|
fi, err := os.Stat(file)
|
|
if err != nil {
|
|
f, err := os.OpenFile(file, os.O_CREATE, 0644)
|
|
if err != nil {
|
|
panic(fmt.Errorf("unable to create file %s", file))
|
|
}
|
|
f.Close()
|
|
} else if fi.IsDir() {
|
|
panic(fmt.Errorf("%s is a directory", file))
|
|
} else if os.Geteuid() != 1001 {
|
|
// UID 1001 is the hardcoded uid for mirror
|
|
err := os.Chown(file, 1001, os.Getegid())
|
|
panicIfErr(err)
|
|
} else if fi.Mode().Perm() != 0644 {
|
|
err := os.Chmod(file, 0644)
|
|
panicIfErr(err)
|
|
}
|
|
}
|
|
|
|
func touchFiles(files ...string) {
|
|
for _, file := range files {
|
|
touchFile(file)
|
|
}
|
|
}
|