@@ -25,6 +25,7 @@ import (
2525var englishTxt embed.FS
2626
2727
28+
2829func main () {
2930 if ! checkKeycardBinaryExists () {
3031 fmt .Println ("Keycard binary not found. Downloading..." )
@@ -78,6 +79,12 @@ func main() {
7879 fmt .Println ("Exiting..." )
7980 os .Exit (0 )
8081
82+
83+ case "5" :
84+ cid := "bafkreie7ohywtosou76tasm7j63yigtzxe7d5zqus4zu3j6oltvgtibeom" // Replace with actual CID
85+ runIPFSTestWithViu (cid )
86+
87+
8188 default :
8289 fmt .Println ("Invalid option, please try again." )
8390 }
@@ -124,10 +131,94 @@ func menu() (string, error) {
124131 fmt .Println ("2. Decrypt / pull file with CID." )
125132 fmt .Println ("3. Print CID Log to QR code." )
126133 fmt .Println ("4. Exit." )
134+ fmt .Println ("5. Run IPFS Connection test." )
127135 fmt .Println ("=============================================" )
128136 return generalAskUser ("Enter your choice: " )
129137}
130138
139+ // runIPFSTestWithViu encapsulates the entire process.
140+ func runIPFSTestWithViu (cid string ) {
141+ if err := checkAndInstallViu (); err != nil {
142+ fmt .Println ("Error installing 'viu':" , err )
143+ fmt .Println ("IPFS Check failed tests... :(" )
144+ return
145+ }
146+
147+ if err := fetchFromIPFS (cid ); err != nil {
148+ fmt .Println ("Error fetching file from IPFS:" , err )
149+ fmt .Println ("IPFS Check failed tests... :(" )
150+ return
151+ }
152+
153+ if err := displayImage (cid ); err != nil {
154+ fmt .Println ("Error displaying image:" , err )
155+ fmt .Println ("IPFS Check failed tests... :(" )
156+ return
157+ }
158+
159+ if err := performBasicIPFSTests (); err != nil {
160+ fmt .Println ("Error performing basic IPFS tests:" , err )
161+ fmt .Println ("IPFS Check failed tests... :(" )
162+ return
163+ }
164+
165+ fmt .Println ("IPFS tests completed successfully." )
166+ }
167+
168+ // checkAndInstallViu checks if 'viu' is installed and installs it if not.
169+ func checkAndInstallViu () error {
170+ _ , err := exec .LookPath ("viu" )
171+ if err != nil {
172+ fmt .Println ("Installing 'viu'..." )
173+ cmd := exec .Command ("sudo" , "apt-get" , "install" , "viu" , "-y" )
174+ cmd .Stdout = os .Stdout
175+ cmd .Stderr = os .Stderr
176+ return cmd .Run ()
177+ }
178+ return nil
179+ }
180+
181+ // fetchFromIPFS fetches a file from IPFS.
182+ func fetchFromIPFS (cid string ) error {
183+ fmt .Println ("Fetching from IPFS..." )
184+ cmd := exec .Command ("ipfs" , "get" , cid )
185+ cmd .Stdout = os .Stdout
186+ cmd .Stderr = os .Stderr
187+ return cmd .Run ()
188+ }
189+
190+ // displayImage displays the image using 'viu'.
191+ func displayImage (filename string ) error {
192+ fmt .Println ("Displaying image..." )
193+ cmd := exec .Command ("viu" , filename )
194+ cmd .Stdout = os .Stdout
195+ cmd .Stderr = os .Stderr
196+ return cmd .Run ()
197+ }
198+
199+ // performBasicIPFSTests runs basic IPFS tests including 'ipfs diag sys' and 'ipfs id'.
200+ func performBasicIPFSTests () error {
201+ fmt .Println ("Performing basic IPFS tests..." )
202+ os .Remove ("bafkreie7ohywtosou76tasm7j63yigtzxe7d5zqus4zu3j6oltvgtibeom" )
203+
204+ // Test 'ipfs diag sys'
205+ if err := executeIPFSCommand ("diag" , "sys" ); err != nil {
206+ return fmt .Errorf ("IPFS diag sys test failed: %w" , err )
207+ }
208+
209+
210+ fmt .Println ("All basic IPFS tests passed successfully." )
211+ return nil
212+ }
213+
214+ // executeIPFSCommand executes an IPFS command and returns any errors.
215+ func executeIPFSCommand (args ... string ) error {
216+ cmd := exec .Command ("ipfs" , args ... )
217+ cmd .Stdout = os .Stdout
218+ cmd .Stderr = os .Stderr
219+ return cmd .Run ()
220+ }
221+
131222func downloadKeycardBinary () error {
132223 url := "https://github.com/status-im/keycard-cli/releases/download/0.7.0/keycard-linux-amd64"
133224 response , err := http .Get (url )
0 commit comments