Matching Metrics of Gravitational Collapse in Weinberg's Gravitation and Cosmology
We have $R(r,t)=a(t)r$, $\therefore$ $\mathrm{d}s^2$ in outer region becomes $$-\bigg(1-\frac{2GM}{ar}\bigg)\mathrm{d}T^2+\bigg(1-\frac{2GM}{ar}\bigg)^{-1}(\dot{a}r\hspace{2pt}\mathrm{d}t+a\mathrm{d}r)^2$$ where dot over a means differentiating with respect to $t$. Now substituting T as a function of $(t,r)$ substituting it in above equation collecting the like terms together we'll get something like $$(...)\hspace{2pt}\mathrm{d}t^2+(...)\hspace{2pt}\mathrm{d}r^2+(...)\hspace{2pt}\mathrm{d}t\hspace{1pt}\mathrm{d}r$$ Now you can go ahead and use the integrating factor technique but algebra will be messy since you have to figure out two functions $T(t,r)$ and $\eta(t,r)$ and all are related by PDE.
There is a reason why we were easily able to deduce the relation $R=a(t)r$ by comparing last term of the line elements? It's because when we do the above calculation in thin shell formalism the condition $[h_{ab}]=0$ doesn't affect/change the $d\Omega^2$ term. If you're confused by what I just said I'm simply referring you to another way to do the above problem which is called thin shell formalism. You can find this method here. This one needs only half a page calculation.
There is another way to doing the problem which is how Oppenheimer found the solution.
I was finally able to work it out. There were multiple confusing aspects. First of all, it turns out that if we ignore the matching conditions on the interior metric, Weinberg's $T(r,t)$ is just one choice. The integrand is completely arbitrary. It is only after the matching condition is imposed that the particular function is chosen. Since Weinberg did the matching later in this section, it seemed that his choice was somehow special and independent of the matching conditions.
Secondly, even though we are looking for $T(r,t)$, we must actually start with the interior metric in comoving coordinates $(t,r)$. The usual process of plugging in a generic function $T(r,t)$ into the exterior metric and working out the differential equations, which aitfel suggested and I also would normally have used, does not seem to work.
First, we note that $$dR = a \, dr + \dot{a} r \, dt \implies dr = \frac{1}{a}\,dR - \frac{\dot{a}}{a} r \,dt = \frac{1}{a}\,dR + \sqrt{\frac{k(1-a)}{a^5}} R \,dt,$$ so the interior metric in the coordinates $(t,R)$ is \begin{align*} ds^2 &= -dt^2 + a^2 \left(\frac{1}{1-kR^2/a^2}\left(\frac{1}{a}\,dR + \sqrt{\frac{k(1-a)}{a^5}} R \,dt\right)^2 + \frac{R^2}{a^2}\, d\Omega^2\right)\\ &= -\frac{1-kR^2/a^3}{1-kR^2/a^2} \, dt^2 + \frac{2R}{1-kR^2/a^2}\sqrt{\frac{k(1-a)}{a^3}} \,dt\,dR + \frac{dR^2}{1-kR^2/a^2} + R^2\, d\Omega^2\\ &= -C(R,t) \, dt^2 + 2E(R,t)\,dt\,dR + D(R,t)\,dR^2 + R^2\, d\Omega^2, \end{align*} where we define $$C(R,t) = \frac{1-kR^2/a^3}{1-kR^2/a^2},\quad E(R,t) = \frac{R}{1-kR^2/a^2}\sqrt{\frac{k(1-a)}{a^3}}, \quad D(R,t) = \frac{1}{1-kR^2/a^2},$$ using the notation of section 11.7. To remove the $dt \, dR$ term, we first complete the square on $dt$: $$ds^2 = -C \left(dt - \frac{E}{C} \,dR\right)^2 + \left(D + \frac{E^2}{C}\right)\,dR^2 + R^2\, d\Omega^2.$$ We then define a new time: $$dT = \eta \left(C\, dt - E \,dR\right),$$ where $\eta(R,t)$ is an integrating factor which ensures that $dT$ is a proper differential by satisfying $$\frac{\partial}{\partial R}\left(\eta C\right) = -\frac{\partial}{\partial t}\left(\eta E\right).$$ With this new time, the metric becomes \begin{align*} ds^2 &= -C^{-1} \eta^{-2} dT^2 + \left(D + E^2 C^{-1}\right)\,dR^2 + R^2\, d\Omega^2\\ &= -\frac{1-kR^2/a^2}{1-kR^2/a^3}\eta^{-2} \, dT^2 + \frac{dR^2}{1-kR^2/a^3} + R^2\, d\Omega^2, \end{align*} where now all functions of $t$ are functions of $T$ through the coordinate transformation. To find this coordinate transformation, we must find $\eta(R,t)$. The differential equation it satisfies is \begin{align*} 0 &= \frac{\partial}{\partial R}\left(\eta C\right) + \frac{\partial}{\partial t}\left(\eta E\right)\\ &= \frac{\partial}{\partial R}\left(\eta(R,t) \frac{1-kR^2/a^3}{1-kR^2/a^2}\right) + \frac{\partial}{\partial t}\left(\eta(R,t) \frac{R}{1-kR^2/a^2}\sqrt{\frac{k(1-a)}{a^3}}\right)\\ &= \frac{1}{1-kR^2/a^2} \left( \frac{(2a-1)k R}{2a^3}\eta(R,t) + \left(1-\frac{kR^2}{a^3}\right)\eta'(R,t) + \sqrt{\frac{k(1-a)}{a^3}}R \dot{\eta}(R,t)\right) \end{align*} Since $t$ only appears inside $a(t)$, we can use $\dot{a} = -\sqrt{k(1-a)/a}$ to rewrite this as $$0 = \frac{(2a-1)k R}{2a^3}\eta(R,a) + \left(1-\frac{kR^2}{a^3}\right)\frac{d\eta(R,a)}{dR} - \frac{k(1-a)}{a^2}R \frac{d\eta(R,a)}{da}.$$ This is a linear first-order partial differential equation, so we can use the method of characteristics. We first solve the equation $$\frac{dR}{da} = -\frac{a^2\left(1-kR^2/a^3\right)}{kR(1-a)} \implies R(a) = \frac{a}{1-a}\sqrt{(1-a)^2 - C_1}.$$ This equation gives the characteristic curves of the differential equation. Solving for the constant $C_1$ yields $$C_1 = (1-a)^2\left(1-\frac{kR^2}{a^2}\right).$$ We then define new coordinates $x$ and $y$: $$x = a, \quad y = (1-a)^2\left(1-\frac{kR^2}{a^2}\right).$$ We then rewrite the differential equation in these variables, $$0 = \frac{\sqrt{k}}{2x^2} \sqrt{1-\frac{y}{(x-1)^2}} \left((2 x-1) \eta(x,y) - 2 (1-x) x \frac{\partial\eta(x,y)}{\partial x}\right).$$ The solution to this simpler differential equation is $$\eta(x,y) = \frac{f(y)}{\sqrt{x(1-x)}},$$ where $f(y)$ is an arbitrary function. We note that we can write $y$ as $$y = \left(1-kr_0^2\right) \left(1-S(R,a)\right)^2,$$ where $$S(R,a) = 1 - \sqrt{\frac{1-kR^2/a^2}{1-kr_0^2}} \left(1-a\right).$$ Here $r_0$ is an arbitrary constant that will eventually be taken to be the radius of the star. Thus we can write the solution as $$\eta(R,a) = \frac{f(S)}{\sqrt{a(1-a)}}.$$ We note that since the final $(T,T)$ component of the metric is $\eta^{-2} C^{-1}$, and we do not expect the interior metric to be singular in this coordinate system at $t=0$ (and thus at $a=1$), it must be the case that $f(S)$ goes to zero at least as fast as $\sqrt{1-a}$ does as $a$ goes to $1$ (and $S$ goes to 1). For convenience, we define a new function $g(S)$ and rewrite $\eta$ as $$\eta(R,a) = \frac{\sqrt{1-a}\left(1-kR^2/a^2\right)^{1/4} g(S)}{\sqrt{a(1-a)}} = \frac{\left(1-kr_0\right)^{1/4} \sqrt{1-S} g(S)}{\sqrt{a(1-a)}},$$ where $g(S)$ does not vanish as $S$ goes to 1.
We now compute the following quantities, which will be useful later. \begin{align*} \frac{dS}{da} &= \frac{1-k R^2/a^3} {\sqrt{1-k r_0^2} \sqrt{1-k R^2/a^2}}\\ &= \frac{(1-a) \left(1-kR^2/a^3\right)} {(1-S) \left(1-kr_0^2\right)}\\ \frac{dS}{dR} &= \frac{kR(1-a)} {a^2 \sqrt{1-kr_0^2} \sqrt{1-k R^2/a^2}}\\ &= \frac{k R (1-a)^2}{ \left(1-kr_0^2\right)a^2 (1-S)}. \end{align*} We then return to the infinitesimal coordinate transformation: \begin{align*} dT &= \eta C \, dt - \eta E \, dr\\ &= \left(\frac{\left(1-kr_0\right)^{1/4} \sqrt{1-S}}{\sqrt{a(1-a)}}\frac{1-kR^2/a^3}{1-kR^2/a^2} g(S)\right)dt - \left( \frac{\sqrt{k}R\left(1-kr_0\right)^{1/4} \sqrt{1-S}}{a^2\left(1-kR^2/a^2\right)}g(S) \right)dr\\ &= \left( \frac{\left(1-kR^2/a^3\right)(1-a)^{3/2}g(S)} {\sqrt{a}\left(1-kr_0^2\right)^{3/4}(1-S)^{3/2}} \right)dt - \left( \frac{\sqrt{k}R g(S)} {\left(1-kr_0^2\right)^{3/4} a^2(1-a)^2(1-S)^{3/2}} \right)dr\\ &= \left( \frac{\left(1-kr_0^2\right)^{1/4} \sqrt{1-a}}{\sqrt{a(1-S)}} g(S) \frac{dS}{da} \right)dt - \left( \frac{\left(1-kr_0^2\right)^{1/4}} {\sqrt{k(1-S)}}g(S) \frac{dS}{dR} \right)dr\\ &= \left(1-kr_0^2\right)^{1/4} \frac{g(S)}{\sqrt{k(1-S)}}\left( \frac{ \sqrt{k(1-a)}}{\sqrt{a}} \frac{dS}{da} \, dt - \frac{dS}{dR} \, dr\right)\\ &= -\left(1-kr_0^2\right)^{1/4} \frac{g(S)}{\sqrt{k(1-S)}}\left( \frac{dS}{da} \dot{a} \, dt + \frac{dS}{dR} \, dr\right). \end{align*} It follows that $T$ can be written as a function of $S$, namely $$T(R,a) = \frac{\left(1-kr_0^2\right)^{1/4}}{\sqrt{k}}\int_{S(R,a)}^1 \frac{g(x)}{\sqrt{1-x}} \, dx.$$ Without using the matching conditions, $g(x)$ is arbitrary. Matching the $(R,R)$ components of the interior and exterior metrics at the surface of the star ($r = r_0$, $R = a(t)r_0$) yields the condition $$\left(1-\frac{r_S}{a r_0}\right)^{-1} = \left(1-\frac{kR^2}{a^3}\right)^{-1}\bigg\vert_{r=r_0} = \left(1-\frac{kr_0^2}{a}\right)^{-1}.$$ Thus $$k = \frac{r_S}{r_0^3}.$$ Since $k = \frac{8\pi G}{3} \mu(0)$ and $r_S = 2GM$ this is equivalent to $$M = \frac{4}{3} \pi r_0^3 \mu(0),$$ which is no surprise.
The matching condition on the $(T,T)$ components is \begin{align*} -\left(1-\frac{r_S}{a(t)r_0}\right) &= -\eta^{-2}C^{-1} \big\vert_{r=r_0}\\ &= -\frac{a\sqrt{1-kR^2/a^2}} {\left(1-kR^2/a^3\right)g(S)^2}\bigg\vert_{r=r_0}\\ &= -\frac{a\sqrt{1-kr_0^2}} {\left(1-kr_0^2/a\right)g(a)^2}. \end{align*} Using $r_S = k r_0^3$ from the first matching condition, we find $$g(a) = \frac{\left(1-kr_0^2\right)^{1/4}\sqrt{a}}{1-kr_0^2/a}.$$ Thus we finally find $$T(r,t) = \sqrt{\frac{1-kr_0^2}{k}} \int_{S(r,t)}^1 \frac{dx}{1-kr_0^2/x} \sqrt{\frac{x}{1-x}},$$ in agreement with Weinberg.