@@ -88,13 +88,25 @@ def handle_command(command: str, description: str, logger: logging.Logger) -> No
88
88
89
89
def setup_git (logger : logging .Logger ) -> None :
90
90
"""Sets up the 'git' user with appropriate shell settings, .ssh directory, and git-shell as login shell."""
91
+ handle_command (
92
+ 'sudo adduser --disabled-password --gecos "" git' , "adds git user" , logger
93
+ )
94
+
95
+ # Get git user's home directory dynamically
96
+ git_home_command = "getent passwd git | cut -d: -f6"
97
+ stdout , stderr , exit_code = run_command (git_home_command )
98
+ if exit_code != 0 :
99
+ raise RuntimeError (f"Error getting git user's home directory: { stderr } " )
100
+ git_home = stdout .strip () # Extract and trim the home directory
101
+
102
+ # Commands to be executed
91
103
commands = [
92
- (' sudo adduser --disabled-password --gecos "" git' , "adds git user " ),
104
+ (f" sudo chmod 755 { git_home } " , "make home of git viewable by others " ),
93
105
(
94
- "sudo -u git bash -c 'mkdir -p ~ /.ssh && chmod 700 ~ /.ssh && touch ~ /.ssh/authorized_keys && chmod 666 ~ /.ssh/authorized_keys'" ,
106
+ f "sudo sh -c 'mkdir -p { git_home } /.ssh && chmod 755 { git_home } /.ssh && touch { git_home } /.ssh/authorized_keys && chmod 666 { git_home } /.ssh/authorized_keys'" ,
95
107
"sets up .ssh directory for git" ,
96
108
),
97
- ("sudo touch /etc/shells" , "creates /etc/shells if it doesn't exists yet" ),
109
+ ("sudo touch /etc/shells" , "creates /etc/shells if it doesn't exist yet" ),
98
110
("cat /etc/shells" , "views available shells" ),
99
111
(
100
112
"sudo sh -c 'which git-shell >> /etc/shells'" ,
@@ -106,6 +118,7 @@ def setup_git(logger: logging.Logger) -> None:
106
118
),
107
119
]
108
120
121
+ # Execute each command
109
122
for command , description in commands :
110
123
handle_command (command , description , logger )
111
124
0 commit comments