Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/src/scripts/ensure_ssh_access.py
Views: 687
#!/usr/bin/python1###############################################################################2#3# CoCalc: Collaborative Calculation4#5# Copyright (C) 2016, Sagemath Inc.6#7# This program is free software: you can redistribute it and/or modify8# it under the terms of the GNU General Public License as published by9# the Free Software Foundation, either version 3 of the License, or10# (at your option) any later version.11#12# This program is distributed in the hope that it will be useful,13# but WITHOUT ANY WARRANTY; without even the implied warranty of14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the15# GNU General Public License for more details.16#17# You should have received a copy of the GNU General Public License18# along with this program. If not, see <http://www.gnu.org/licenses/>.19#20###############################################################################2122import os, sys2324path = sys.argv[1]25if not os.path.exists(path):26raise RuntimeError("no such directory -- %s" % path)2728dot_ssh = os.path.join(path, '.ssh')2930if os.path.exists(dot_ssh) and not os.path.isdir(dot_ssh):31os.unlink(dot_ssh)3233if not os.path.exists(dot_ssh):34os.makedirs(dot_ssh)3536target = os.path.join(dot_ssh, 'authorized_keys')37authorized_keys = '\n' + open(sys.argv[2]).read() + '\n'3839if not os.path.exists(target) or authorized_keys not in open(target).read():40open(target, 'w').write(authorized_keys)4142s = os.stat(path)4344if os.system('chown -R %s:%s %s' % (s.st_uid, s.st_gid, dot_ssh)):45raise RuntimeError("failed to chown")4647if os.system('chmod og-rwx -R %s' % dot_ssh):48raise RuntimeError("failed to chmod")495051