linebook 0.7.0 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/History +8 -0
- data/HowTo/Setup/Debian +75 -0
- data/HowTo/Setup/SLES +87 -0
- data/HowTo/Setup/Ubuntu +71 -0
- data/HowTo/Setup/openSUSE +75 -0
- data/HowTo/Switch Users +73 -0
- data/lib/linebook/os/linux.rb +24 -199
- data/lib/linebook/os/linux/utilities.rb +226 -0
- data/lib/linebook/os/posix.rb +268 -78
- data/lib/linebook/os/posix/utilities.rb +726 -0
- data/lib/linebook/os/posix/variable.rb +91 -0
- data/lib/linebook/os/ubuntu.rb +1 -1
- data/lib/linebook/shell.rb +3 -3
- data/lib/linebook/version.rb +1 -1
- metadata +24 -12
- data/lib/linebook/os/unix.rb +0 -462
data/History
CHANGED
@@ -1,3 +1,11 @@
|
|
1
|
+
== 0.8.0 2011/05/23
|
2
|
+
|
3
|
+
Updated to linecook-1.2.0. Added many utility commands for Posix/Linux, and
|
4
|
+
wrapped Unix into Posix module. Standardized the behavior of the commands.
|
5
|
+
Added definition of functions and variables.
|
6
|
+
|
7
|
+
Very likely breaks most of what was in use in 0.7.0.
|
8
|
+
|
1
9
|
== 0.7.0 2011/04/26
|
2
10
|
|
3
11
|
Updated to linecook-1.0.0
|
data/HowTo/Setup/Debian
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
= Debian
|
2
|
+
|
3
|
+
<em>Note these instructions are for building a dev box only. In particular
|
4
|
+
they allow the linecook user to sudo without a password, which may not be in
|
5
|
+
you best production interests.</em>
|
6
|
+
|
7
|
+
Build an Debian base box using the following:
|
8
|
+
|
9
|
+
* http://www.debian.org/distrib/netinst
|
10
|
+
- name: debian
|
11
|
+
- Debian
|
12
|
+
- 384 MB memory
|
13
|
+
- 8 GB dynamically resizing drive
|
14
|
+
|
15
|
+
Add the iso to the cd/dvd device under Settings > Storage. Now start the
|
16
|
+
server and install (use default settings unless specified):
|
17
|
+
|
18
|
+
- root password: linecook
|
19
|
+
- user/password: linecook
|
20
|
+
- select 'SSH server' and 'Standard system utilities' as software to install
|
21
|
+
|
22
|
+
When the server has rebooted and is ready at the login screen, remove the
|
23
|
+
install iso, take a snapshot and setup port forwarding.
|
24
|
+
|
25
|
+
(Devices > CD/DVD Devices > Remove disk from virtual drive)
|
26
|
+
VBoxManage snapshot debian take RAW
|
27
|
+
VBoxManage controlvm debian poweroff
|
28
|
+
# wait to fully power off
|
29
|
+
VBoxManage modifyvm debian --natpf1 'debian-ssh,tcp,,2222,,22'
|
30
|
+
VBoxManage -q snapshot debian restore RAW
|
31
|
+
VBoxManage startvm debian
|
32
|
+
|
33
|
+
Transfer your ssh key to the vm. Help to generate ssh keys can be found on
|
34
|
+
{GitHub}[http://help.github.com/key-setup-redirect]:
|
35
|
+
|
36
|
+
scp -P 2222 -o UserKnownHostsFile=/dev/null ~/.ssh/id_rsa.pub linecook@localhost:id_rsa.pub
|
37
|
+
|
38
|
+
Login as root and setup su for the linecook user:
|
39
|
+
|
40
|
+
vm: vi /etc/pam.d/su
|
41
|
+
|
42
|
+
# uncomment:
|
43
|
+
#
|
44
|
+
# # Uncomment this if you want wheel members to be able to
|
45
|
+
# # su without a password.
|
46
|
+
# auth sufficient pam_wheel.so trust
|
47
|
+
#
|
48
|
+
|
49
|
+
vm: groupadd wheel
|
50
|
+
vm: usermod -a -G wheel linecook
|
51
|
+
|
52
|
+
Setup SSH for the linecook user:
|
53
|
+
|
54
|
+
vm: su -l linecook
|
55
|
+
vm: mkdir .ssh
|
56
|
+
vm: mv id_rsa.pub .ssh/authorized_keys
|
57
|
+
vm: chmod 0700 .ssh
|
58
|
+
vm: chmod 0600 .ssh/authorized_keys
|
59
|
+
vm: exit
|
60
|
+
|
61
|
+
Remove the login banner and exit:
|
62
|
+
|
63
|
+
vm: rm /etc/motd
|
64
|
+
vm: exit
|
65
|
+
|
66
|
+
Now take the standard snapshots:
|
67
|
+
|
68
|
+
VBoxManage snapshot debian take BASE
|
69
|
+
VBoxManage snapshot debian take CURRENT
|
70
|
+
VBoxManage controlvm debian poweroff
|
71
|
+
|
72
|
+
To cleanup the port forwarding (run later, if ever):
|
73
|
+
|
74
|
+
VBoxManage modifyvm debian --natpf1 delete 'debian-ssh'
|
75
|
+
|
data/HowTo/Setup/SLES
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
= SLES
|
2
|
+
|
3
|
+
<em>Note these instructions are for building a dev box only. In particular
|
4
|
+
they allow the linecook user to sudo without a password and disable the
|
5
|
+
firewall, which may not be in you best production interests.</em>
|
6
|
+
|
7
|
+
Build a SLES11 base box using the following:
|
8
|
+
|
9
|
+
- name: sles
|
10
|
+
- Linux/Linux 2.6
|
11
|
+
- 256 MB memory
|
12
|
+
- 8 GB dynamically resizing drive
|
13
|
+
|
14
|
+
Add the netinst.iso to the cd/dvd device under Settings > Storage. Now start
|
15
|
+
the server and install (use default settings unless specified):
|
16
|
+
|
17
|
+
- Server Base Scenario: Virtual Machine (middle option)
|
18
|
+
- Installation (1.2 GB):
|
19
|
+
Base System
|
20
|
+
Novell AppArmor
|
21
|
+
Minimal System
|
22
|
+
c/c++ Compiler and Tools
|
23
|
+
- root password: linecook
|
24
|
+
- network settings:
|
25
|
+
hostname: sles
|
26
|
+
domain: pinnacol.com
|
27
|
+
[ ] change hostname via DHCP
|
28
|
+
[x] write hostname to /etc/hosts
|
29
|
+
(Change > Network Interfaces > Hostname/DNS)
|
30
|
+
Name Server 1: 10.2.24.11
|
31
|
+
Name Server 2: 65.125.146.66
|
32
|
+
(Change > Firewall > Disable Firewall Automatic Starting)
|
33
|
+
- configure novell customer stuff later
|
34
|
+
- user/password: linecook
|
35
|
+
|
36
|
+
When the server has rebooted and is ready at the login screen, remove the
|
37
|
+
install iso, take a snapshot and setup port forwarding.
|
38
|
+
|
39
|
+
(Devices > CD/DVD Devices > Remove disk from virtual drive)
|
40
|
+
VBoxManage snapshot sles take RAW
|
41
|
+
VBoxManage controlvm sles poweroff
|
42
|
+
# wait to fully power off
|
43
|
+
VBoxManage modifyvm sles --natpf1 'sles-ssh,tcp,,2223,,22'
|
44
|
+
VBoxManage -q snapshot sles restore RAW
|
45
|
+
VBoxManage startvm sles
|
46
|
+
|
47
|
+
Transfer your ssh key to the vm. Help to generate ssh keys can be found on
|
48
|
+
GitHub (http://help.github.com/key-setup-redirect):
|
49
|
+
|
50
|
+
scp -P 2223 -o UserKnownHostsFile=/dev/null ~/.ssh/id_rsa.pub linecook@localhost:id_rsa.pub
|
51
|
+
|
52
|
+
Login as root and setup su for the linecook user:
|
53
|
+
|
54
|
+
vm: vi /etc/pam.d/su
|
55
|
+
|
56
|
+
# insert:
|
57
|
+
# auth sufficient pam_wheel.so trust
|
58
|
+
|
59
|
+
vm: vi /etc/pam.d/su-l
|
60
|
+
|
61
|
+
# insert:
|
62
|
+
# auth sufficient pam_wheel.so trust
|
63
|
+
|
64
|
+
vm: p=$(id -gn linecook)
|
65
|
+
vm: g=$(id -Gn linecook | sed "s/$p //" | sed "s/ /,/g")
|
66
|
+
vm: groupadd linecook
|
67
|
+
vm: usermod -g linecook -G "wheel,$g" linecook
|
68
|
+
|
69
|
+
Setup SSH for the linecook user:
|
70
|
+
|
71
|
+
vm: su -l linecook
|
72
|
+
vm: mkdir .ssh
|
73
|
+
vm: mv id_rsa.pub .ssh/authorized_keys
|
74
|
+
vm: chmod 0700 .ssh
|
75
|
+
vm: chmod 0600 .ssh/authorized_keys
|
76
|
+
vm: exit
|
77
|
+
vm: exit
|
78
|
+
|
79
|
+
Now take the standard snapshots:
|
80
|
+
|
81
|
+
VBoxManage snapshot sles take BASE
|
82
|
+
VBoxManage snapshot sles take CURRENT
|
83
|
+
VBoxManage controlvm sles poweroff
|
84
|
+
|
85
|
+
To cleanup the port forwarding (run later, if ever):
|
86
|
+
|
87
|
+
VBoxManage modifyvm sles --natpf1 delete 'sles-ssh'
|
data/HowTo/Setup/Ubuntu
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
== Ubuntu
|
2
|
+
|
3
|
+
<em>Note these instructions are for building a dev box only. In particular
|
4
|
+
they allow the linecook user to sudo without a password, which may not be in
|
5
|
+
you best production interests.</em>
|
6
|
+
|
7
|
+
Build a Ubuntu base box using the following:
|
8
|
+
|
9
|
+
- name: ubuntu
|
10
|
+
- Linux/Ubuntu
|
11
|
+
- 512 MB memory
|
12
|
+
- 8 GB dynamically resizing drive
|
13
|
+
|
14
|
+
Add the iso to the cd/dvd device under Settings > Storage. Now start the
|
15
|
+
server and install ubuntu (use default settings unless specified):
|
16
|
+
|
17
|
+
- user/password: linecook
|
18
|
+
- select 'OpenSSH server' in packages to install
|
19
|
+
|
20
|
+
When the server has rebooted and is ready at the login screen, remove the
|
21
|
+
install iso, take a snapshot and setup port forwarding.
|
22
|
+
|
23
|
+
(Devices > CD/DVD Devices > Remove disk from virtual drive)
|
24
|
+
VBoxManage snapshot ubuntu take RAW
|
25
|
+
VBoxManage controlvm ubuntu poweroff
|
26
|
+
# wait to fully power off
|
27
|
+
VBoxManage modifyvm ubuntu --natpf1 'ubuntu-ssh,tcp,,2220,,22'
|
28
|
+
VBoxManage -q snapshot ubuntu restore RAW
|
29
|
+
VBoxManage startvm ubuntu
|
30
|
+
|
31
|
+
Transfer your ssh key to the vm. Help to generate ssh keys can be found on
|
32
|
+
{GitHub}[http://help.github.com/key-setup-redirect]:
|
33
|
+
|
34
|
+
scp -P 2220 -o UserKnownHostsFile=/dev/null ~/.ssh/id_rsa.pub linecook@localhost:id_rsa.pub
|
35
|
+
|
36
|
+
Login as linecook and setup su permissions for the linecook user:
|
37
|
+
|
38
|
+
vm: sudo vi /etc/pam.d/su
|
39
|
+
|
40
|
+
# uncomment:
|
41
|
+
#
|
42
|
+
# # Uncomment this if you want wheel members to be able to
|
43
|
+
# # su without a password.
|
44
|
+
# auth sufficient pam_wheel.so trust
|
45
|
+
#
|
46
|
+
|
47
|
+
vm: sudo groupadd wheel
|
48
|
+
vm: sudo usermod -a -G wheel linecook
|
49
|
+
|
50
|
+
Setup SSH:
|
51
|
+
|
52
|
+
vm: mkdir .ssh
|
53
|
+
vm: mv id_rsa.pub .ssh/authorized_keys
|
54
|
+
vm: chmod 0700 .ssh
|
55
|
+
vm: chmod 0600 .ssh/authorized_keys
|
56
|
+
|
57
|
+
Remove the login banner and exit:
|
58
|
+
|
59
|
+
vm: sudo rm /etc/motd
|
60
|
+
vm: exit
|
61
|
+
|
62
|
+
Now take some standard snapshots:
|
63
|
+
|
64
|
+
VBoxManage snapshot ubuntu take BASE
|
65
|
+
VBoxManage snapshot ubuntu take CURRENT
|
66
|
+
VBoxManage controlvm ubuntu poweroff
|
67
|
+
|
68
|
+
To cleanup the port forwarding (run later, if ever):
|
69
|
+
|
70
|
+
VBoxManage modifyvm ubuntu --natpf1 delete 'ubuntu-ssh'
|
71
|
+
|
@@ -0,0 +1,75 @@
|
|
1
|
+
= openSUSE
|
2
|
+
|
3
|
+
<em>Note these instructions are for building a dev box only. In particular
|
4
|
+
they allow the linecook user to sudo without a password and turn off the
|
5
|
+
firewall, which may not be in you best production interests.</em>
|
6
|
+
|
7
|
+
Build an openSUSE base box using the following:
|
8
|
+
|
9
|
+
* http://software.opensuse.org/113/en
|
10
|
+
- name: opensuse
|
11
|
+
- openSUSE
|
12
|
+
- 512 MB memory
|
13
|
+
- 8 GB dynamically resizing drive
|
14
|
+
|
15
|
+
Add the iso to the cd/dvd device under Settings > Storage. Now start the
|
16
|
+
server and install (use default settings unless specified):
|
17
|
+
|
18
|
+
- Desktop Selection: Other > Minimal Server Selection
|
19
|
+
- user/password: linecook
|
20
|
+
- deselect automatic login
|
21
|
+
|
22
|
+
When the server has rebooted and is ready at the login screen, remove the
|
23
|
+
install iso, take a snapshot and setup port forwarding.
|
24
|
+
|
25
|
+
(Devices > CD/DVD Devices > Remove disk from virtual drive)
|
26
|
+
VBoxManage snapshot opensuse take RAW
|
27
|
+
VBoxManage controlvm opensuse poweroff
|
28
|
+
# wait to fully power off
|
29
|
+
VBoxManage modifyvm opensuse --natpf1 'opensuse-ssh,tcp,,2221,,22'
|
30
|
+
VBoxManage -q snapshot opensuse restore RAW
|
31
|
+
VBoxManage startvm opensuse
|
32
|
+
|
33
|
+
Login as root, start sshd, stop the firewall, and setup su for the linecook user:
|
34
|
+
|
35
|
+
vm: /etc/init.d/sshd start
|
36
|
+
vm: rcSuSEfirewall2 stop
|
37
|
+
vm: vi /etc/pam.d/su
|
38
|
+
|
39
|
+
# insert:
|
40
|
+
# auth sufficient pam_wheel.so trust
|
41
|
+
|
42
|
+
vm: vi /etc/pam.d/su-l
|
43
|
+
|
44
|
+
# insert:
|
45
|
+
# auth sufficient pam_wheel.so trust
|
46
|
+
|
47
|
+
vm: groupadd linecook
|
48
|
+
vm: usermod -g linecook -A wheel linecook
|
49
|
+
|
50
|
+
Transfer your ssh key to the vm. Help to generate ssh keys can be found on
|
51
|
+
{GitHub}[http://help.github.com/key-setup-redirect]:
|
52
|
+
|
53
|
+
scp -P 2221 -o UserKnownHostsFile=/dev/null ~/.ssh/id_rsa.pub linecook@localhost:id_rsa.pub
|
54
|
+
|
55
|
+
Setup SSH for linecook and exit:
|
56
|
+
|
57
|
+
vm: su -l linecook
|
58
|
+
vm: mkdir .ssh
|
59
|
+
vm: mv id_rsa.pub .ssh/authorized_keys
|
60
|
+
vm: chmod 0700 .ssh
|
61
|
+
vm: chmod 0600 .ssh/authorized_keys
|
62
|
+
vm: exit
|
63
|
+
vm: exit
|
64
|
+
|
65
|
+
Now take the standard snapshots:
|
66
|
+
|
67
|
+
VBoxManage snapshot opensuse take BASE
|
68
|
+
VBoxManage snapshot opensuse take CURRENT
|
69
|
+
VBoxManage controlvm opensuse poweroff
|
70
|
+
|
71
|
+
To cleanup the port forwarding (run later, if ever):
|
72
|
+
|
73
|
+
VBoxManage modifyvm opensuse --natpf1 delete 'opensuse-ssh'
|
74
|
+
|
75
|
+
https://bugzilla.novell.com/show_bug.cgi?id=556077#c7
|
data/HowTo/Switch Users
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
= Switch Users
|
2
|
+
|
3
|
+
The login and su methods in the Linebook::Os::Linux module both provide a way
|
4
|
+
to switch users. Login simulates a login and therefore you end up in the user
|
5
|
+
home directory with the ENV as setup during login. By contrast su switches
|
6
|
+
users such that it preserves exported ENV variables, including the pwd.
|
7
|
+
|
8
|
+
Say you were the linecook user:
|
9
|
+
|
10
|
+
cd
|
11
|
+
export 'A', 'a'
|
12
|
+
variable 'B', 'b'
|
13
|
+
echo "$(whoami):$(pwd):$A:$B" # => linecook:/home/linecook:a:b
|
14
|
+
login { echo "$(whoami):$(pwd):$A:$B" } # => root:/root::
|
15
|
+
su { echo "$(whoami):$(pwd):$A:$B" } # => root:/home/linecook:a:
|
16
|
+
|
17
|
+
User-management methods in this module assume root privileges (useradd,
|
18
|
+
groupadd, etc) so unless you are already root, you need to wrap them in login
|
19
|
+
or su. In this case login is more reliable than su because some systems leave
|
20
|
+
the user management commands off the non-root PATH; using login ensures PATH
|
21
|
+
will be set for root during the block.
|
22
|
+
|
23
|
+
For example use:
|
24
|
+
|
25
|
+
login { useradd 'username' }
|
26
|
+
|
27
|
+
Rather than:
|
28
|
+
|
29
|
+
su { useradd 'username' } # may give 'useradd: command not found'
|
30
|
+
|
31
|
+
== Permissions
|
32
|
+
|
33
|
+
The user running the package needs the ability to su without a password,
|
34
|
+
otherwise login/su will choke and fail when run by 'linecook run'. How this is
|
35
|
+
accomplished is a matter of policy; something each user needs to decide for
|
36
|
+
themselves.
|
37
|
+
|
38
|
+
First you could run the package as root.
|
39
|
+
|
40
|
+
Second you can grant the running user (ex 'linecook') su privileges. This can
|
41
|
+
be accomplished by adding the user to the 'wheel' group and modifiying the PAM
|
42
|
+
config files. Afterwards all wheel users can su without a password. To do so
|
43
|
+
(repeat for '/etc/pam.d/su-l' if it exists):
|
44
|
+
|
45
|
+
vi /etc/pam.d/su
|
46
|
+
# insert:
|
47
|
+
# auth sufficient pam_wheel.so trust
|
48
|
+
|
49
|
+
This is the default strategy and it works in a portable way because the {linux
|
50
|
+
spec}[http://refspecs.linuxfoundation.org/LSB_4.1.0/LSB-Core-generic/LSB-Core-generic/su.html]
|
51
|
+
requires su exists and has the necessary options.
|
52
|
+
|
53
|
+
Third you can chuck the default login/su, re-implement them with sudo, and
|
54
|
+
give the user (ex 'linecook') sudo privileges. This can be accomplished by
|
55
|
+
adding the user to a group (ex 'linecook') and modifying the sudo config via
|
56
|
+
visudo. Afterwards all the linecook users can sudo without a password.
|
57
|
+
|
58
|
+
visudo
|
59
|
+
# insert:
|
60
|
+
# # Members of the linecook group may sudo without a password
|
61
|
+
# %linecook ALL=NOPASSWD: ALL
|
62
|
+
|
63
|
+
See an old version of the {linebook
|
64
|
+
source}[https://github.com/pinnacol/linebook/tree/b786e1e63c68f5ddf3be15851d
|
65
|
+
9b423bc05e5345/helpers/linebook/os/linux] for hints on how login/su could be
|
66
|
+
reimplemented with sudo. This strategy was abandoned because sudo is not
|
67
|
+
required by the linux spec and is does not come installed in many cases (ex
|
68
|
+
Debian). Moreover the options needed to make this strategy work don't exist in
|
69
|
+
sudo < 1.7, so even systems that come with sudo could need an upgrade.
|
70
|
+
|
71
|
+
Lastly you can chuck all of these strategies and figure out your own way.
|
72
|
+
Surely they exist, for example by running scripts manually and entering in
|
73
|
+
passwords as prompted.
|
data/lib/linebook/os/linux.rb
CHANGED
@@ -2,82 +2,30 @@
|
|
2
2
|
|
3
3
|
module Linebook
|
4
4
|
module Os
|
5
|
-
#
|
6
|
-
#
|
7
|
-
#
|
8
|
-
#
|
9
|
-
#
|
10
|
-
#
|
11
|
-
#
|
12
|
-
#
|
13
|
-
#
|
14
|
-
#
|
15
|
-
#
|
16
|
-
# variable 'B', 'b'
|
17
|
-
# echo "$(whoami):$(pwd):$A:$B" # => linecook:/home/linecook:a:b
|
18
|
-
# login { echo "$(whoami):$(pwd):$A:$B" } # => root:/root::
|
19
|
-
# su { echo "$(whoami):$(pwd):$A:$B" } # => root:/home/linecook:a:
|
20
|
-
#
|
21
|
-
# User-management methods in this module assume root privileges (useradd,
|
22
|
-
# groupadd, etc) so unless you are already root, you need to wrap them in
|
23
|
-
# login or su. In this case login is more reliable than su because some
|
24
|
-
# systems leave the user management commands off the non-root PATH; using
|
25
|
-
# login ensures PATH will be set for root during the block.
|
26
|
-
#
|
27
|
-
# For example use:
|
28
|
-
#
|
29
|
-
# login { useradd 'username' }
|
30
|
-
#
|
31
|
-
# Rather than:
|
32
|
-
#
|
33
|
-
# su { useradd 'username' } # => may give 'useradd: command not found'
|
34
|
-
#
|
35
|
-
# == Permissions
|
36
|
-
#
|
37
|
-
# The user running the package needs the ability to su without a password,
|
38
|
-
# otherwise login/su will choke and fail when run by 'linecook run'. How this
|
39
|
-
# is accomplished is a matter of policy; something each user needs to decide
|
40
|
-
# for themselves.
|
41
|
-
#
|
42
|
-
# First you could run the package as root.
|
43
|
-
#
|
44
|
-
# Second you can grant the running user (ex 'linecook') su privileges. This
|
45
|
-
# can be accomplished by adding the user to the 'wheel' group and modifiying
|
46
|
-
# the PAM config files. Afterwards all wheel users can su without a password.
|
47
|
-
# To do so (repeat for '/etc/pam.d/su-l' if it exists):
|
48
|
-
#
|
49
|
-
# vi /etc/pam.d/su
|
50
|
-
# # insert:
|
51
|
-
# # auth sufficient pam_wheel.so trust
|
52
|
-
#
|
53
|
-
# This is the default strategy and it works in a portable way because the
|
54
|
-
# {linux spec}[http://refspecs.linuxfoundation.org/LSB_4.1.0/LSB-Core-generic/LSB-Core-generic/cmdbehav.html]
|
55
|
-
# requires su exists and has the necessary options.
|
56
|
-
#
|
57
|
-
# Third you can chuck the default login/su, reimplement them with sudo, and
|
58
|
-
# give the user (ex 'linecook') sudo privileges. This can be accomplished by
|
59
|
-
# adding the user to a group (ex 'linecook') and modifying the sudo config via
|
60
|
-
# visudo. Afterwards all the linecook users can sudo without a password.
|
61
|
-
#
|
62
|
-
# visudo
|
63
|
-
# # insert:
|
64
|
-
# # # Members of the linecook group may sudo without a password
|
65
|
-
# # %linecook ALL=NOPASSWD: ALL
|
66
|
-
#
|
67
|
-
# See an old version of the {linebook source}[https://github.com/pinnacol/linebook/tree/b786e1e63c68f5ddf3be15851d9b423bc05e5345/helpers/linebook/os/linux]
|
68
|
-
# for hints on how login/su could be reimplemented with sudo. This strategy
|
69
|
-
# was abandonded as the default because sudo is not required by the linux spec
|
70
|
-
# and is does not come installed in many cases (ex Debian). Moreover the
|
71
|
-
# options needed to make this strategy work don't exist in sudo < 1.7, so even
|
72
|
-
# systems that come with sudo could need an upgrade.
|
73
|
-
#
|
74
|
-
# Lastly you can chuck all of these strategies and figure out your own way.
|
75
|
-
# Surely they exist, for example by running the packages manually and entering
|
76
|
-
# in passwords as prompted.
|
77
|
-
#
|
5
|
+
# Defines Linux-compliant functionality, based on the {Linux Standard Base
|
6
|
+
# Core Specification 4.1 }[http://refspecs.linuxfoundation.org/lsb.shtml]. See
|
7
|
+
# the online documentation for:
|
8
|
+
#
|
9
|
+
# * {Commands and Utilities
|
10
|
+
# }[http://refspecs.linuxfoundation.org/LSB_4.1.0/LSB-Core-generic/LSB-Core-generic/cmdbehav.html]
|
11
|
+
# * {Single Unix Specification V2
|
12
|
+
# }[http://pubs.opengroup.org/onlinepubs/007908799/xcuix.html]
|
13
|
+
# Posix does not specify commands for user management, but Linux does. Now
|
14
|
+
# that users are overtly in the mix, see {How to Switch
|
15
|
+
# Users}[link:files/HowTo/Switch%20Users.html] for picking a su policy.
|
78
16
|
module Linux
|
79
|
-
require 'linebook/os/
|
80
|
-
include
|
17
|
+
require 'linebook/os/posix'
|
18
|
+
include Posix
|
19
|
+
|
20
|
+
require 'linebook/os/linux/utilities'
|
21
|
+
include Utilities
|
22
|
+
|
23
|
+
def guess_target_name(source_name)
|
24
|
+
target_dir = File.dirname(target_name)
|
25
|
+
name = File.basename(source_name)
|
26
|
+
|
27
|
+
_package_.next_target_name(target_dir == '.' ? name : File.join(target_dir, name))
|
28
|
+
end
|
81
29
|
|
82
30
|
def capture_script(options={})
|
83
31
|
unless options.kind_of?(Hash)
|
@@ -97,76 +45,12 @@ module Linebook
|
|
97
45
|
path
|
98
46
|
end
|
99
47
|
|
100
|
-
# Returns true if the group exists as determined by checking /etc/group.
|
101
|
-
def group?(name)
|
102
|
-
# grep "^<%= name %>:" /etc/group >/dev/null 2>&1
|
103
|
-
write "grep \"^"; write(( name ).to_s); write ":\" /etc/group >/dev/null 2>&1"
|
104
|
-
chain_proxy
|
105
|
-
end
|
106
|
-
|
107
|
-
def _group?(*args, &block) # :nodoc:
|
108
|
-
str = capture_str { group?(*args, &block) }
|
109
|
-
str.strip!
|
110
|
-
str
|
111
|
-
end
|
112
|
-
|
113
|
-
# Adds the group.
|
114
|
-
def groupadd(name, options={})
|
115
|
-
execute 'groupadd', name, options
|
116
|
-
chain_proxy
|
117
|
-
end
|
118
|
-
|
119
|
-
def _groupadd(*args, &block) # :nodoc:
|
120
|
-
str = capture_str { groupadd(*args, &block) }
|
121
|
-
str.strip!
|
122
|
-
str
|
123
|
-
end
|
124
|
-
|
125
|
-
# Removes the group.
|
126
|
-
def groupdel(name, options={})
|
127
|
-
execute 'groupdel', name, options
|
128
|
-
chain_proxy
|
129
|
-
end
|
130
|
-
|
131
|
-
def _groupdel(*args, &block) # :nodoc:
|
132
|
-
str = capture_str { groupdel(*args, &block) }
|
133
|
-
str.strip!
|
134
|
-
str
|
135
|
-
end
|
136
|
-
|
137
|
-
def groups(user, options={})
|
138
|
-
# id -Gn <%= quote(user) %>
|
139
|
-
#
|
140
|
-
#
|
141
|
-
write "id -Gn "; write(( quote(user) ).to_s); write "\n"
|
142
|
-
write "\n"
|
143
|
-
|
144
|
-
chain_proxy
|
145
|
-
end
|
146
|
-
|
147
|
-
def _groups(*args, &block) # :nodoc:
|
148
|
-
str = capture_str { groups(*args, &block) }
|
149
|
-
str.strip!
|
150
|
-
str
|
151
|
-
end
|
152
|
-
|
153
|
-
def install(source, target, options={})
|
154
|
-
execute 'install', source, target, options
|
155
|
-
chain_proxy
|
156
|
-
end
|
157
|
-
|
158
|
-
def _install(*args, &block) # :nodoc:
|
159
|
-
str = capture_str { install(*args, &block) }
|
160
|
-
str.strip!
|
161
|
-
str
|
162
|
-
end
|
163
|
-
|
164
48
|
# Logs in as the specified user for the duration of a block (the current ENV
|
165
49
|
# and pwd are reset as during a normal login).
|
166
50
|
def login(user='root', options={})
|
167
51
|
current = functions
|
168
52
|
begin
|
169
|
-
@functions =
|
53
|
+
@functions = nil
|
170
54
|
|
171
55
|
path = capture_script(options) { yield }
|
172
56
|
execute 'su', user, path, :l => true
|
@@ -181,65 +65,6 @@ module Linebook
|
|
181
65
|
str.strip!
|
182
66
|
str
|
183
67
|
end
|
184
|
-
|
185
|
-
# Switches to the specified user for the duration of a block. The current ENV
|
186
|
-
# and pwd are preserved.
|
187
|
-
def su(user='root', options={})
|
188
|
-
path = capture_script(options) do
|
189
|
-
functions.each do |function|
|
190
|
-
writeln function
|
191
|
-
end
|
192
|
-
yield
|
193
|
-
end
|
194
|
-
execute 'su', user, path, :m => true
|
195
|
-
chain_proxy
|
196
|
-
end
|
197
|
-
|
198
|
-
def _su(*args, &block) # :nodoc:
|
199
|
-
str = capture_str { su(*args, &block) }
|
200
|
-
str.strip!
|
201
|
-
str
|
202
|
-
end
|
203
|
-
|
204
|
-
# Returns true if the user exists as determined by id.
|
205
|
-
def user?(name)
|
206
|
-
# id <%= quote(name) %> >/dev/null 2>&1
|
207
|
-
write "id "; write(( quote(name) ).to_s); write " >/dev/null 2>&1"
|
208
|
-
chain_proxy
|
209
|
-
end
|
210
|
-
|
211
|
-
def _user?(*args, &block) # :nodoc:
|
212
|
-
str = capture_str { user?(*args, &block) }
|
213
|
-
str.strip!
|
214
|
-
str
|
215
|
-
end
|
216
|
-
|
217
|
-
# Adds the user.
|
218
|
-
def useradd(name, options={})
|
219
|
-
execute 'useradd', name, options
|
220
|
-
chain_proxy
|
221
|
-
end
|
222
|
-
|
223
|
-
def _useradd(*args, &block) # :nodoc:
|
224
|
-
str = capture_str { useradd(*args, &block) }
|
225
|
-
str.strip!
|
226
|
-
str
|
227
|
-
end
|
228
|
-
|
229
|
-
# Removes the user.
|
230
|
-
def userdel(name, options={})
|
231
|
-
# TODO - look into other things that might need to happen before:
|
232
|
-
# * kill processes belonging to user
|
233
|
-
# * remove at/cron/print jobs etc.
|
234
|
-
execute 'userdel', name, options
|
235
|
-
chain_proxy
|
236
|
-
end
|
237
|
-
|
238
|
-
def _userdel(*args, &block) # :nodoc:
|
239
|
-
str = capture_str { userdel(*args, &block) }
|
240
|
-
str.strip!
|
241
|
-
str
|
242
|
-
end
|
243
68
|
end
|
244
69
|
end
|
245
70
|
end
|