-
Notifications
You must be signed in to change notification settings - Fork 0
/
meta-start.sh
executable file
·104 lines (101 loc) · 2.91 KB
/
meta-start.sh
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#!/bin/bash
function setup_user ()
{
if [ "$1" = "root" ]; then
return 0;
elif [ $(id -u) = 0 ]; then
id $1 > /dev/null 2>&1;
if [ ! $? = 0 ]; then
[ "$2" = "" ] || U_ID="-u $2"
if [ -d "/home/$1" ]; then
useradd -M -s /bin/bash ${U_ID} -p "$1" "$1"
else
useradd -m -s /bin/bash ${U_ID} -p "$1" "$1"
fi
chown $1.$1 /home/$1
fi
if [ ! -d "/home/$1" -o ! -d "/home/$1/.ssh" ]; then
mkdir -p /home/$1
(cd /etc/skel; tar -cf - .) | (cd /home/"$1"; tar -xf -)
fi
if [ ! "$(/bin/ls -ld /home/$1/.ssh > /dev/null 2>&1)" = "drwx------" ]; then
chown $1.$1 /home/$1/
chown -R $1.$1 /home/$1/.[a-zA-Z]*
chmod 0700 /home/$1/.ssh
chmod 0600 /home/$1/.ssh/authorized_keys /home/$1/.ssh/id_rsa.do-not@use
echo "$1 ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers.d/1-users
fi
else
if [ ! -d "/home/$1" -o ! -d "/home/$1/.ssh" ]; then
mkdir -p /home/$1
(cd /etc/skel; tar -cf - .) | (cd /home/"$1"; tar -xf -)
fi
if [ ! "$(/bin/ls -ld /home/$1/.ssh > /dev/null 2>&1)" = "drwx------" ]; then
chown $1.$1 /home/$1/
chown -R $1.$1 /home/$1/.[a-zA-Z]*
chmod 0700 /home/$1/.ssh
chmod 0600 /home/$1/.ssh/authorized_keys /home/$1/.ssh/id_rsa.do-not@use
fi
fi
}
case "$1" in
"setup-skel") # internal command
grep -q PROMPT_DIRTRIM /etc/skel/.bashrc
if [ ! $? = 0 ]; then
echo "PROMPT_DIRTRIM=2;
if [ ! \"\$-\" = \"\${-/i/}\" ]; then
bind \"\\C-p\":history-search-backward;
bind '\"\\e[A\":history-search-backward';
bind \"\\C-n\":history-search-forward;
bind '\"\\e[B\":history-search-forward';
fi
" >> /etc/skel/.bashrc
echo "set noswapfile nobackup nowritebackup" >> /etc/skel/.vimrc
mkdir /etc/skel/.ssh
chmod 0755 /etc/skel/.ssh
ssh-keygen -t rsa -b 4096 -C "do-not@use" -q -N "" -f /etc/skel/.ssh/id_rsa.do-not@use
cp /etc/skel/.ssh/[email protected] /etc/skel/.ssh/authorized_keys
chmod 0644 /etc/skel/.ssh/*
(cd /etc/skel/.ssh; ln -sf id_rsa.do-not@use id_rsa)
fi
;;
"setup-user") # internal command
if [ $# -lt 2 ]; then
echo "Usage: meta-start.sh setup-user <user>"
exit 1
fi
setup_user $2 $3
;;
"build-image")
docker build -t metadium/bobthe:0.4 .
;;
"truffle")
shift
exec /usr/bin/nodejs /data/node_modules/.bin/truffle $*
;;
"npm")
shift
exec /usr/bin/npm $*
;;
"nodejs")
shift
exec /usr/bin/nodejs $*
;;
"solc")
shift
exec /usr/local/bin/solc $*
;;
"gmet"|"metadium")
shift
exec /opt/meta/bin/gmet $*
;;
"make")
shift
exec /usr/bin/make $*
;;
"sh"|"bash"|"shell"|*)
shift
exec /bin/bash $*
;;
esac
# EOF