pulled upstream
Made script gentoo ready