Section 100. A railroad corporation may raise or lower a public way to permit its railroad to pass over or under the same; but before proceeding to cross or to alter or excavate for the purpose of crossing the way, it shall obtain from the county commissioners a decree prescribing what alterations may be made in the way, and what structures erected at the crossing, and the manner and time of making or erecting the same; and before entering upon, excavating or altering the way, it shall give to the city or town where the crossing is situated security, satisfactory to the commissioners, that it will faithfully comply with the requirements of the decree to their acceptance, and will indemnify the city or town against all damages and charges by reason of a failure so to do.
If, upon the petition of the board of aldermen or selectmen, it appears that such corporation has excavated or altered a public way without obtaining the decree and giving the security required by this section, or has neglected for fifteen days to give security as required by section one hundred and six, the supreme judicial court may enjoin it from entering upon, altering, excavating or crossing the way until such decree has been obtained or such security given.