mirror of https://github.com/curusarn/resh
- Setup and use Device ID and name - get rid of hostname use. - Use datadir - Add uuid go binary, remove script - Install-utils: migrations of config and history, device setup - Use nohup on Linux (consistency with Darwin) - Installl scriptpull/184/head
parent
b68519f50e
commit
1a584c78f6
@ -0,0 +1,26 @@ |
||||
package main |
||||
|
||||
import ( |
||||
"fmt" |
||||
"os" |
||||
|
||||
"github.com/google/uuid" |
||||
) |
||||
|
||||
// Small utility to generate UUID's using google/uuid golang package
|
||||
// Doesn't check arguments
|
||||
// Exits with status 1 on error
|
||||
func main() { |
||||
rnd, err := uuid.NewRandom() |
||||
if err != nil { |
||||
fmt.Fprintf(os.Stderr, "ERROR: could not get new random source: %v", err) |
||||
os.Exit(1) |
||||
} |
||||
id := rnd.String() |
||||
if id == "" { |
||||
fmt.Fprintf(os.Stderr, "ERROR: got invalid UUID from package") |
||||
os.Exit(1) |
||||
} |
||||
// No newline
|
||||
fmt.Print(id) |
||||
} |
||||
@ -0,0 +1,27 @@ |
||||
package main |
||||
|
||||
import ( |
||||
"fmt" |
||||
"os" |
||||
|
||||
"github.com/curusarn/resh/internal/datadir" |
||||
"github.com/curusarn/resh/internal/device" |
||||
) |
||||
|
||||
func setupDevice() { |
||||
dataDir, err := datadir.MakePath() |
||||
if err != nil { |
||||
fmt.Fprintf(os.Stderr, "ERROR: Failed to get/setup data directory: %v\n", err) |
||||
os.Exit(1) |
||||
} |
||||
err = device.SetupName(dataDir) |
||||
if err != nil { |
||||
fmt.Fprintf(os.Stderr, "ERROR: Failed to check/setup device name: %v\n", err) |
||||
os.Exit(1) |
||||
} |
||||
err = device.SetupID(dataDir) |
||||
if err != nil { |
||||
fmt.Fprintf(os.Stderr, "ERROR: Failed to check/setup device ID: %v\n", err) |
||||
os.Exit(1) |
||||
} |
||||
} |
||||
@ -0,0 +1,54 @@ |
||||
package futil |
||||
|
||||
import ( |
||||
"fmt" |
||||
"io" |
||||
"os" |
||||
) |
||||
|
||||
func CopyFile(source, dest string) error { |
||||
from, err := os.Open(source) |
||||
if err != nil { |
||||
return err |
||||
} |
||||
defer from.Close() |
||||
|
||||
// This is equivalent to: os.OpenFile(dest, os.O_RDWR|os.O_CREATE, 0666)
|
||||
to, err := os.Create(dest) |
||||
if err != nil { |
||||
return err |
||||
} |
||||
defer to.Close() |
||||
|
||||
_, err = io.Copy(to, from) |
||||
if err != nil { |
||||
return err |
||||
} |
||||
return nil |
||||
} |
||||
|
||||
func FileExists(fpath string) (bool, error) { |
||||
_, err := os.Stat(fpath) |
||||
if err == nil { |
||||
// File exists
|
||||
return true, nil |
||||
} |
||||
if os.IsNotExist(err) { |
||||
// File doesn't exist
|
||||
return false, nil |
||||
} |
||||
// Any other error
|
||||
return false, fmt.Errorf("could not stat file: %w", err) |
||||
} |
||||
|
||||
func CreateFile(fpath string) error { |
||||
ff, err := os.Create(fpath) |
||||
if err != nil { |
||||
return err |
||||
} |
||||
err = ff.Close() |
||||
if err != nil { |
||||
return err |
||||
} |
||||
return nil |
||||
} |
||||
@ -1,35 +0,0 @@ |
||||
#!/usr/bin/env bash |
||||
# https://gist.github.com/markusfisch/6110640 |
||||
|
||||
# Generate a pseudo UUID |
||||
uuid() |
||||
{ |
||||
local N B C='89ab' |
||||
|
||||
for (( N=0; N < 16; ++N )) |
||||
do |
||||
B=$(( $RANDOM%256 )) |
||||
|
||||
case $N in |
||||
6) |
||||
printf '4%x' $(( B%16 )) |
||||
;; |
||||
8) |
||||
printf '%c%x' ${C:$RANDOM%${#C}:1} $(( B%16 )) |
||||
;; |
||||
3 | 5 | 7 | 9) |
||||
printf '%02x-' $B |
||||
;; |
||||
*) |
||||
printf '%02x' $B |
||||
;; |
||||
esac |
||||
done |
||||
|
||||
echo |
||||
} |
||||
|
||||
if [ "$BASH_SOURCE" == "$0" ] |
||||
then |
||||
uuid |
||||
fi |
||||
Loading…
Reference in new issue