@@ -7,8 +7,24 @@ import (
7
7
"os"
8
8
"os/exec"
9
9
"strings"
10
+ "net/http"
11
+ "path/filepath"
10
12
)
11
13
14
+ // GLOBAL PLATFORM PRO VERSION V20.01.23
15
+
16
+ const gpJarURL = "https://github.com/martinpaljak/GlobalPlatformPro/releases/download/v20.01.23/gp.jar"
17
+
18
+ func installKeycard () error {
19
+ cmd := exec .Command ("./keycard-linux-amd64" , "install" )
20
+ output , err := cmd .CombinedOutput ()
21
+ if err != nil {
22
+ return fmt .Errorf ("error executing keycard-linux-amd64 install: %v, output: %s" , err , output )
23
+ }
24
+ fmt .Printf ("Output: %s\n " , output )
25
+ return nil
26
+ }
27
+
12
28
// GetKeycardPublicKey retrieves the public key from the keycard.
13
29
func GetKeycardPublicKey () (string , error ) {
14
30
// Command to execute
@@ -55,3 +71,132 @@ func ReadPassphrase() (string, error) {
55
71
}
56
72
return strings .TrimSpace (passphrase ), nil
57
73
}
74
+
75
+
76
+
77
+
78
+ func JavaDependency () {
79
+ // Check if Java is installed
80
+ if err := exec .Command ("java" , "-version" ).Run (); err == nil {
81
+ fmt .Println ("Java is already installed." )
82
+ return
83
+ }
84
+
85
+ // Determine the operating system
86
+ switch os := runtime .GOOS ; os {
87
+ case "linux" :
88
+ // Identify Linux distribution
89
+ out , err := exec .Command ("sh" , "-c" , "cat /etc/os-release" ).Output ()
90
+ if err != nil {
91
+ fmt .Printf ("Failed to execute command: %s\n " , err )
92
+ return
93
+ }
94
+
95
+ // Parse /etc/os-release
96
+ osRelease := string (out )
97
+ if strings .Contains (osRelease , "ID=arch" ) || strings .Contains (osRelease , "ID_LIKE=arch" ) {
98
+ // Install Java for Arch-based systems
99
+ fmt .Println ("Installing Java using pacman..." )
100
+ exec .Command ("sudo" , "pacman" , "-Sy" , "--noconfirm" , "jdk-openjdk" ).Run ()
101
+
102
+ // Install pcscd and pcsc-tools using pacman
103
+ fmt .Println ("Installing pcscd and pcsc-tools using pacman..." )
104
+ exec .Command ("sudo" , "pacman" , "-Syu" , "--noconfirm" , "ccid" , "libnfc" , "acsccid" , "pcsclite" , "pcsc-tools" ).Run ()
105
+ exec .Command ("sudo" , "systemctl" , "enable" , "--now" , "pcscd" ).Run ()
106
+ } else if strings .Contains (osRelease , "ID=debian" ) || strings .Contains (osRelease , "ID=ubuntu" ) {
107
+ // Install Java for Debian-based systems
108
+ fmt .Println ("Installing Java using apt..." )
109
+ exec .Command ("sudo" , "apt" , "update" ).Run ()
110
+ exec .Command ("sudo" , "apt" , "install" , "-y" , "default-jdk" ).Run ()
111
+
112
+ // Install pcscd and pcsc-tools using apt
113
+ fmt .Println ("Installing pcscd and pcsc-tools using apt..." )
114
+ exec .Command ("sudo" , "apt-get" , "update" ).Run ()
115
+ exec .Command ("sudo" , "apt-get" , "install" , "-y" , "pcsc-lite" , "pcsc-tools" ).Run ()
116
+ exec .Command ("sudo" , "systemctl" , "enable" , "pcscd" ).Run ()
117
+ exec .Command ("sudo" , "systemctl" , "start" , "pcscd" ).Run ()
118
+ } else {
119
+ fmt .Println ("Unsupported Linux distribution" )
120
+ }
121
+ default :
122
+ fmt .Printf ("%s is not supported by this script\n " , os )
123
+ }
124
+ }
125
+
126
+ func GlobalPlatformDependency () {
127
+ // Define paths to search
128
+ paths := []string {"../" , os .Getenv ("HOME" ) + "/Downloads/" }
129
+
130
+ found := false
131
+ for _ , path := range paths {
132
+ found = searchFile (path , "gp.jar" )
133
+ if found {
134
+ fmt .Println ("gp.jar found in:" , path )
135
+ break
136
+ }
137
+ }
138
+
139
+ // If not found, download the file
140
+ if ! found {
141
+ fmt .Println ("gp.jar not found. Downloading..." )
142
+ err := downloadFile ("gp.jar" , gpJarURL )
143
+ if err != nil {
144
+ fmt .Println ("Error downloading gp.jar:" , err )
145
+ return
146
+ }
147
+ fmt .Println ("Downloaded gp.jar successfully." )
148
+ }
149
+ }
150
+
151
+ func searchFile (dir , filename string ) bool {
152
+ found := false
153
+ filepath .Walk (dir , func (path string , info os.FileInfo , err error ) error {
154
+ if err != nil {
155
+ return err
156
+ }
157
+ if info .Name () == filename {
158
+ found = true
159
+ }
160
+ return nil
161
+ })
162
+ return found
163
+ }
164
+
165
+
166
+
167
+
168
+
169
+ func downloadFile (filepath string , url string ) error {
170
+ // Get the data
171
+ resp , err := http .Get (url )
172
+ if err != nil {
173
+ return err
174
+ }
175
+ defer resp .Body .Close ()
176
+
177
+ // Create the file
178
+ out , err := os .Create (filepath )
179
+ if err != nil {
180
+ return err
181
+ }
182
+ defer out .Close ()
183
+
184
+ buf := make ([]byte , 1024 ) // buffer size
185
+ for {
186
+ n , err := resp .Body .Read (buf )
187
+ if err != nil && err != io .EOF {
188
+ return err
189
+ }
190
+ if n == 0 {
191
+ break
192
+ }
193
+
194
+ if _ , writeErr := out .Write (buf [:n ]); writeErr != nil {
195
+ return writeErr
196
+ }
197
+ }
198
+
199
+ return nil
200
+ }
201
+
202
+
0 commit comments