@@ -162,7 +162,7 @@ func New(opts *Options) *Handler {
162
162
163
163
handler .installScript , err = parseInstallScript (opts .SiteFS , opts .BuildInfo )
164
164
if err != nil {
165
- panic ( "failed to parse install script" )
165
+ _ = fmt . Errorf ( "install.sh will be unavailabe: %w" , err )
166
166
}
167
167
168
168
return handler
@@ -225,6 +225,10 @@ func (h *Handler) ServeHTTP(rw http.ResponseWriter, r *http.Request) {
225
225
// If requesting the install.sh script, fill in the template with the
226
226
// appropriate hostname and version info.
227
227
case reqFile == "install.sh" :
228
+ if h .installScript == nil {
229
+ http .NotFound (rw , r )
230
+ return
231
+ }
228
232
rw .Header ().Add ("Content-Type" , "text/plain; charset=utf-8" )
229
233
http .ServeContent (rw , r , reqFile , time.Time {}, bytes .NewReader (h .installScript ))
230
234
return
@@ -552,22 +556,22 @@ type installScriptState struct {
552
556
func parseInstallScript (files fs.FS , buildInfo codersdk.BuildInfoResponse ) ([]byte , error ) {
553
557
scriptFile , err := fs .ReadFile (files , "install.sh" )
554
558
if err != nil {
555
- return [] byte {} , err
559
+ return nil , err
556
560
}
557
561
558
562
script , err := template .New ("install.sh" ).Parse (string (scriptFile ))
559
563
if err != nil {
560
- return [] byte {} , err
564
+ return nil , err
561
565
}
562
566
563
567
var buf bytes.Buffer
564
568
state := installScriptState {Origin : buildInfo .DashboardURL , Version : buildInfo .Version }
565
569
err = script .Execute (& buf , state )
566
570
if err != nil {
567
- return [] byte {} , err
571
+ return nil , err
568
572
}
569
573
570
- return buf .Bytes (), err
574
+ return buf .Bytes (), nil
571
575
}
572
576
573
577
// ExtractOrReadBinFS checks the provided fs for compressed coder binaries and
0 commit comments