aboutsummaryrefslogtreecommitdiff
path: root/tasks/initial-user-setup
blob: fb402bbf958d72e70992cbec0ba0d74941fbb0ab (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/bin/bash

function task_exec() {
	source /etc/os-release
	case $ID in
		arch)
			pacman -Sy
			INSTALL_CMD="pacman --noconfirm -S";;
		debian)
			apt update
			INSTALL_CMD="apt-get install -y"
	esac

	PACKAGES="sudo vim git"
	[ ! -z "$INSTALL_CMD" ] && $INSTALL_CMD $PACKAGES

	groupadd sudo
	useradd -s /bin/bash -d /home/server -m -U -G sudo server

	tee /etc/sudoers.d/autosetup_sudoconf << EOF
# Configured by lTask
%sudo ALL=(ALL) NOPASSWD: ALL
EOF
	su server << EOF
cd
mkdir .ssh; cd .ssh
touch authorized_keys
EOF

	cat id_user.pub >> /home/server/.ssh/authorized_keys
	cat id_jenkins.pub >> /home/server/.ssh/authorized_keys

	echo > /etc/motd
}

function task_setup() {
	# Available environment variables
	# $ASSET_DIR
	# $TOOL_DIR
	
	SSH_USER=root
	#SSH_IDENTITY_FILE=$ASSET_DIR/id_jenkins

	FILES+=("$ASSET_DIR/id_user.pub" "$ASSET_DIR/id_jenkins.pub")

	TASK_ISSET="yes"
}

if [ -z $HOSTMODE ]; then
	task_exec
else
	task_setup
fi