summaryrefslogtreecommitdiffstats
path: root/initrd/initrd-stuff/etc/vmware-prep
blob: 8f2f037ea3f2474987733864bab02166b5bfa034 (plain) (blame)
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#!/bin/sh
#
# Description:  Adaptation of a generic runlevel script file for use with
#               Diskless X Stations (v4.0) - script prepares vmware
#               environment
#
# Author(s):    Michael Janczyk <mj0@uni-freiburg.de>, 23-03-2006
#               Dirk von Suchodoletz <dirk@goe.net>, 08-03-2006
# Copyright:    (c) 2003, 2006 - RZ Universitaet Freiburg
#
# Version:      0.1a
################################################################################



### VERBOSE? ###################################################################
# set verbose mode (set -x(v))
#set -xv



### CONFIGURATION ##############################################################
# read configuration information
. /etc/machine-setup



### VARIABLES SECTION ##########################################################
# Declaration of default variables
vmdir="/var/lib/vmware"
path="/var/X11R6/bin"
part44=
sessions=
session_name=



### FUNCTIONS SECTION ##########################################################
# mount scratch on server, but only if no 44 partition mounted
mount_scratch () {
  part44=$(grep -i "/tmp.*ext2" /etc/fstab)
  if [ -n "${scratch}" -a -z "${part44}" ]; then
    mkdir -p /tmp/scratch >/dev/null 2>&1
    mount -t nfs -o rw,nolock,intr,nodev,soft,timeo=2,nosuid ${scratch} \
      /tmp/scratch >/dev/null 2>&1 
    mkdir -p /tmp/scratch/${clientip} >/dev/null 2>&1
    mount -t nfs -o rw,nolock,intr,nodev,soft,timeo=2,nosuid \
      ${scratch}/${clientip} /tmp >/dev/null 2>&1 &
    chmod 1777 /tmp 2>&1
  fi
}


# loop file for exchanging information between linux and vmware
mount_loop () {
  mkdir -p /media/loop0
  cp ${vmdir}/templ/fd0.img /tmp/scratch/${clientip}-fd0.img
  chmod a+rw /tmp/scratch/${clientip}-fd0.img
  mount -t msdos -o loop,umask=000 /tmp/scratch/${clientip}-fd0.img \
    /media/loop0
}


# device creation - the module does not trigger udev properly
vmnet () {
  for i in 0 1 2 3 4 5 6 7 8 9; do
    [ -c /dev/vmnet${i} ] || mknod /dev/vmnet${i} c 119 ${i};
  done
  chmod 0700 /dev/vmnet*
}


# special start script for vmware with predefined image
Xpath () {
  if test -w /usr/X11R6/bin ; then
    path="/usr/X11R6/bin"
    cp ${vmdir}/import/templ/runvmware \
       /usr/X11R6/bin
  else
    path="/var/X11R6/bin"
    test -d /var/X11R6/bin || mkdir -p /var/X11R6/bin
    cp ${vmdir}/import/templ/runvmware \
       /var/X11R6/bin
  fi
}


# blabla sessiondinens
desktop_session () {
  echo -e "#!/bin/sh\n#\n# file generated by\n#\t${0}:\n#\t${date}\n
  os=\$(echo \$0 | sed -e \"s,-, ,\" -e \"s,.*/,,\" | awk '{print \$1}')
  spec=\$(echo \$0 | sed -e \"s,-, ,\" -e \"s,.*/,,\" | awk '{print \$2}')\n
  options=\"-o \${os} \${spec:+\"-s \${spec}\"}\"\n

  xterm -bg black -fg white -geometry 170x30+0-0 +sb \
    -e \"${path}/runvmware \${options} ${debug}\"\n" \
  > ${path}/desktop-session
}


# copy nach blabla
vmsession2desktop_session () {
  sessions=$(ls ${vmdir}/vmsessions/*.desktop)
  if [ -n "${sessions}" ]; then
    for i in ${vmdir}/vmsessions/*.desktop; do
      session_name=$(cat ${vmdir}/vmsessions/${i} | grep -iw "exec" \
        | awk -F "=" '{print $2}')
      cp ${path}/desktop-session ${path}/${session_name}
    done
  fi
}



### START SCRIPT ###############################################################

echo -n "Starting preparation of vmware environment"

# create vmdir
mkdir -p /var/lib/vmware 2>&1

# mount von zeugs
mount -t nfs -o ro,nolock,intr,nodev,soft,timeo=2,nosuid ${imgsrv} ${vmdir} &
mount_scratch

# device creation - the module does not trigger udev properly
vmnet

# special start script for vmware with predefined image
Xpath

# loop file for exchanging information between linux and vmware
mount_loop

# blabla sessiondinens
desktop_session

# copy nach blabla
vmsession2desktop_session



exit 0