forked from keybase/client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall_unix.go
182 lines (149 loc) · 4.99 KB
/
install_unix.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
// Copyright 2015 Keybase, Inc. All rights reserved. Use of
// this source code is governed by the included BSD license.
// +build linux freebsd netbsd openbsd
package install
import (
"fmt"
"io/ioutil"
"os"
"path"
"time"
"github.com/keybase/client/go/libkb"
keybase1 "github.com/keybase/client/go/protocol/keybase1"
)
// Similar to the Brew install on OSX, the Unix install happens in two steps.
// First, the system package manager installs all the binaries as root. Second,
// an autostart file needs to be written to the user's home dir, so that
// Keybase launches when that user logs in. The second step is done the first
// time the user starts Keybase.
//
// ".desktop" files and the ~/.config/autostart directory are part of the
// freedesktop.org set of standards, which the popular desktop environments
// like Gnome and KDE all support. See
// http://standards.freedesktop.org/desktop-entry-spec/latest/.
const backtick = "`"
const autostartFileText = `# This file is generated by Keybase, along with a sentinel
# file at ~/.config/keybase/autostart_created. As long as the sentinel exists,
# this file won't be changed automatically, so you can edit it or delete it
# as you like.
# To toggle autostart on, run
# ` + backtick + `keybase ctl autostart --enable` + backtick + `
# or to toggle off,
# ` + backtick + `keybase ctl autostart --disable` + backtick + `.
# Note that this will overwrite any changes you have made.
[Desktop Entry]
Name=Keybase
Comment=Keybase Filesystem Service and GUI
Type=Application
Exec=env KEYBASE_AUTOSTART=1 run_keybase
`
const disabledAutostartFileText = autostartFileText + `
Hidden=true
X-GNOME-Autostart-enabled=false
`
const sentinelFileText = `This file is created the first time Keybase starts, along with
~/.config/autostart/keybase_autostart.desktop. As long as this
file exists, the autostart file won't be automatically recreated.
`
func autostartDir(context Context) string {
// strip off the "keybase" folder on the end of the config dir
return path.Join(context.GetConfigDir(), "..", "autostart")
}
func autostartFilePath(context Context) string {
return path.Join(autostartDir(context), "keybase_autostart.desktop")
}
func sentinelFilePath(context Context) string {
return path.Join(context.GetConfigDir(), "autostart_created")
}
func ToggleAutostart(context Context, on bool, forAutoinstall bool) error {
if forAutoinstall {
_, err := os.Stat(sentinelFilePath(context))
if err == nil {
// The sentinel exists. Don't recreate the autostart file.
return nil
} else if !os.IsNotExist(err) {
// The error is something unexpected. Return it.
return err
}
// The sentinel doesn't exist. Create the autostart file, and then create
// the sentinel. This might stomp on old user edits one time, but we need
// to do that to add in the KEYBASE_AUTOSTART variable.
}
err := os.MkdirAll(autostartDir(context), 0755)
if err != nil {
return err
}
var text string
if on {
text = autostartFileText
} else {
text = disabledAutostartFileText
}
if forAutoinstall {
fmt.Println(`Installing autostart file. Manage autostart settings with ` + backtick + `keybase ctl autostart` + backtick + `.`)
}
err = ioutil.WriteFile(autostartFilePath(context), []byte(text), 0644)
if err != nil {
return err
}
if forAutoinstall {
err = ioutil.WriteFile(sentinelFilePath(context), []byte(sentinelFileText), 0644)
if err != nil {
return err
}
}
return nil
}
func GetAutostart(context Context) keybase1.OnLoginStartupStatus {
bs, _ := ioutil.ReadFile(autostartFilePath(context))
switch string(bs) {
case autostartFileText:
return keybase1.OnLoginStartupStatus_ENABLED
case disabledAutostartFileText:
return keybase1.OnLoginStartupStatus_DISABLED
}
return keybase1.OnLoginStartupStatus_UNKNOWN
}
// AutoInstall installs auto start on unix
func AutoInstall(context Context, _ string, _ bool, timeout time.Duration, log Log) (newProc bool, err error) {
err = os.MkdirAll(context.GetConfigDir(), 0755)
if err != nil {
return false, err
}
err = ToggleAutostart(context, true, true)
if err != nil {
// Ignore if we couldn't write to autostart
log.Errorf("Autoinstall failed: %s.", err)
}
return false, nil
}
// CheckIfValidLocation is not used on unix
func CheckIfValidLocation() error {
return nil
}
// KBFSBinPath returns the path to the KBFS executable
func KBFSBinPath(runMode libkb.RunMode, binPath string) (string, error) {
return kbfsBinPathDefault(runMode, binPath)
}
// kbfsBinName returns the name for the KBFS executable
func kbfsBinName() string {
return "kbfsfuse"
}
func updaterBinName() (string, error) {
return "", fmt.Errorf("Updater isn't supported on unix")
}
// RunApp starts the app
func RunApp(context Context, log Log) error {
// TODO: Start app, see run_keybase: /opt/keybase/Keybase
return nil
}
func InstallLogPath() (string, error) {
return "", nil
}
// WatchdogLogPath doesn't exist on linux as an independent log file
func WatchdogLogPath(string) (string, error) {
return "", nil
}
func SystemLogPath() string {
return ""
}