What you want to do is create a quad with texture coordinates along a line (v1,v2):

As the vertex shader creates exactly one vertex for each incoming vertex, you have to store a bit of additional information for each vertex of the quad:
You need the originating line-vertex (v1 or v2), the direction to the other line-vertex (v2 or v1) and a texture coordinate:
// encode other vertex-position normal
glNormal3fv( v2 );
glTexCoord2f(1,0); glVertex3fv( v1 );
glTexCoord2f(0,0); glVertex3fv( v1 );
glNormal3fv( v1 );
glTexCoord2f(0,1); glVertex3fv( v2 );
glTexCoord2f(1,1); glVertex3fv( v2 );
The vertex-shader can now extrude the quad along the perpendicular of (v2-v1) of the 2d-transformed vertices in camera space.
The orientation of the extrusion can be read from the texture-coordinates (which is either 0 or 1):
// vertex positions of the line in camera space
vec4 csPos1= gl_ModelViewProjectionMatrix * gl_Vertex;
vec4 csPos2= gl_ModelViewProjectionMatrix * vec4(gl_Normal, 1.0);
// 2d projected vertex positions
vec2 p1= csPos1.xy / csPos1.z;
vec2 p2= csPos2.xy / csPos2.z;
// normalized direction
vec2 left= normalize(p1 - p2);
// orthogonal
vec4 up= vec4(-left.y, left.x, 0.0, 0.0);
// depending on assigned texture coordinate, extrude to one side or the other
float x= (gl_MultiTexCoord0.x-0.5) * lineWidth;
gl_Position = csPos1 + up * x;
To incorporate the caps you can simply subdivide the quad into three segments.