2 The create account command creates a new user account on the specified robot. 4 Copyright 2015 Fetch Robotics Inc. 11 from copy
import deepcopy
12 from getpass
import getpass
13 from pipes
import quote
15 from ..util
import ssh, add_user, add_robot, add_workspace
17 name =
"create-account" 18 help_text =
"Create an account on a robot" 20 create_user_script =
""" 21 echo %(fetch_password)s | sudo -S adduser %(user)s --gecos '%(fullname)s,,,' --disabled-password && 22 echo '%(user)s:%(password)s' | sudo chpasswd && 23 sudo usermod -G adm,audio,cdrom,sudo,dip,plugdev,lpadmin,sambashare %(user)s 26 setup_user_script =
""" 27 export FETCH_WORKSPACE=%(remote_workspace)s 28 export ROS_DISTRO=%(ros_distro)s 29 echo source /opt/ros/%(ros_distro)s/setup.bash >> ~/.bashrc.d/40-ros-setup.sh 30 echo source %(remote_workspace)s/devel/setup.bash >> ~/.bashrc.d/40-ros-setup.sh 31 echo '%(password)s' | sudo -S echo granting root priveleges for installation 37 fullname = args.fullname
if args.fullname
is not None else args.user
38 print "Creating account %s@%s for %s" % (args.user, args.robot, fullname)
41 fetch_password = args.fetch_password[-1]
42 if fetch_password
is None:
43 fetch_password = getpass(prompt=
"Fetch password: ")
46 password = args.password
48 check_password =
"Not the same" 49 while password != check_password:
50 if password
is not None:
51 print "Passwords don't match, please try again." 52 password = getpass(prompt=
"Password: ")
53 check_password = getpass(prompt=
"Password (confirm): ")
57 "fetch_password": fetch_password,
61 "remote_workspace": args.remote_workspace,
62 "ros_distro": os.getenv(
"ROS_DISTRO"),
68 proc = subprocess.Popen([
"sshpass",
"-e",
69 "ssh",
"-o",
"StrictHostKeyChecking=no",
70 "fetch@" + args.robot,
"exit"],
71 env={
"SSHPASS": fetch_password})
73 if proc.returncode != 0:
74 print "ERROR: Could not add robot to known hosts" 78 if ssh(
"fetch", args.robot, create_user_script % env, fetch_password) != 0:
79 print "ERROR: Creating user failed" 84 dd = deepcopy(os.environ)
85 dd[
"SSHPASS"] = password
86 proc = subprocess.Popen([
"sshpass",
"-e",
87 "ssh-copy-id", args.user +
"@" + args.robot],
90 if proc.returncode != 0:
91 print "WARNING: Copying ID failed, continuing anyways" 92 print "To manually copy an ID, first create one " \
93 "https://help.github.com/articles/generating-ssh-keys/ " \
94 "and then run `ssh-copy-id " + args.user +
"@" + args.robot +
"`" 97 skeleton = args.skeleton
99 user_skeleton = os.getenv(
"HOME") +
"/.fetch/robot_skeleton" 100 if os.path.isdir(user_skeleton):
101 skeleton = user_skeleton
103 package_dir = subprocess.check_output([
"rospack",
105 "fetch_tools"]).strip()
106 skeleton = os.path.join(os.path.dirname(__file__),
107 package_dir +
"/resources/robot_skeleton")
108 proc = subprocess.Popen([
"scp",
"-r",
".", args.user +
"@" +
112 if proc.returncode != 0:
113 print "ERROR: Could not copy skeleton directory" 117 if ssh(args.user, args.robot, setup_user_script % env) != 0:
118 print "ERRROR: Setting up user failed" 127 "--fetch-password", nargs=
"?", action=
"append", default=[
"robotics"],
128 help=
"Password for the fetch account (or blank to prompt)" 130 parser.add_argument(
"--password", nargs=
"?", action=
"store",
131 help=
"Password for the new account")
132 parser.add_argument(
"--fullname", action=
"store", help=
"Users full name")
133 parser.add_argument(
"--skeleton", action=
"store",
134 help=
"Skeleton directory to setup account")