post-install.sh 4.61 KB
Newer Older
1 2 3 4
#! /bin/bash
#
# When cygwin is installed, then call this script by Administrator:
#
5
#    /bin/bash/ --login -i post-install.sh PREFIX
6
#
7 8
# It will do:
#
9
#    * Set uid of Adminstrator to 0, and create root account
10
#
11
#    * Create .minttyrc and cygtty.bat, which used to start comand console
12
#
13
#    * Create autorebase.bat, it used to fix cygwin dll problem
14
#
15
#    * Change readme.txt to dos format
16
#
17 18
#    * Set prefix for this slapos node
#
19 20
function show_error_exit()
{
21
    echo Error: ${1-Run post-install script failed.}
22 23 24
    read -n 1 -p "Press any key to exit..."
    exit 1
}
25
readonly -f show_error_exit
26

27
declare -r cyghome=$(cygpath -w /)
28
declare -r slapos_prefix=$1
29

30 31 32 33 34
_filename=/etc/passwd
echo "Checking ${_filename} ..."
if [[ ! -f ${_filename} ]] ; then
    mkpasswd -l > ${_filename} || show_error_exit "Error: mkpasswd failed"
    echo "${_filename} has been generated."
35
else
36
    echo OK.
37 38
fi

39 40 41 42 43
_filename=/etc/group
echo "Checking ${_filename} ..."
if [[ ! -f ${_filename} ]] ; then
    mkgroup -l > ${_filename} || show_error_exit "Error: mkgroup failed"
    echo "${_filename} has been generated."
44
else
45
    echo OK.
46 47
fi

48
# grep -q "^root:" ${password_filename}
49
# if (( $? != 0 )) ; then
50
#     myaccount=$(grep "^Administrator:" ${password_filename} | \
51 52
#               sed -e "s/Administrator:unused:500:/root:unused:0:/g")
#     if [[ "${myaccount:0:4}" == root ]] ; then
53
#         echo $myaccount >> ${password_filename}
54 55 56 57
#     else
#         exit 1
#     fi
# fi
58

59
_charset=$(ipwin codepage) || _charset=""
60
echo "Windows OEM Codepage is ${_charset}"
61

62
_filename=".minttyrc"
63 64 65
echo Checking  ${_filename} ...
if [[ ! -f ${_filename} ]] ; then
    cat <<EOF > ${_filename}
66 67 68 69
BoldAsFont=no
Font=Courier New
FontHeight=16
Scrollbar=none
70
Locale=C
71
Charset=${_charset}
72
EOF
73
    echo "${_filename} has been generated."
74 75
else
    echo OK.
76 77
fi

78 79 80 81
_filename="/cygtty.bat"
echo Checking  ${_filename} ...
if [[ ! -x ${_filename} ]] ; then
    cat <<EOF > ${_filename}
82 83 84 85 86 87 88
@echo off

${cyghome:0:2}
chdir ${cyghome}\\bin

start mintty.exe -i /Cygwin-Terminal.ico -
EOF
89
    chmod +x ${_filename}
90
    echo "${_filename} has been generated."
91 92
else
    echo OK.
93 94
fi

95 96 97
_filename="/autorebase.bat"
echo Checking  ${_filename} ...
if [[ ! -f ${_filename} ]] ; then
98
    cat <<EOF > ${_filename}
99
@echo off
100 101
${cyghome}\bin\find /opt/slapos -name "*.dll" > ${cyghome}\myfile.list
IF EXIST ${cyghome}\opt\slapgrid. ${cyghome}\bin\find /opt/slapgrid -name "*.dll" >> ${cyghome}\myfile.list
102 103 104 105 106 107 108 109 110
TASKKILL /F /IM openvpn.exe
NET STOP re6stnet
NET STOP cygserver
NET STOP syslog-ng
NET STOP cron
NET STOP sshd
TASKKILL /F /IM python2.7.exe
${cyghome:0:2}
chdir ${cyghome}
111
path .\bin;%path%
112
dash /bin/rebaseall -T /myfile.list -v
113
EOF
114
    chmod +x ${_filename}
115
    echo "${_filename} has been generated."
116 117
else
    echo OK.
118 119
fi

120
# Change format of readme.txt
121 122
_filename=$(cygpath -u $(cygpath -m /)/../readme.txt)
if [[ -f ${_filename} ]] ; then
123
    echo "Changing $(cygpath -w ${_filename}) as dos format ..."
124
    unix2dos ${_filename} && echo OK.
125 126
fi

127
# Backup slap-runner.html
128 129
_filename=/etc/slapos/scripts/slap-runner.html
if [[ -r ${_filename} ]] ; then
130
    echo "Backuping ${_filename} as ${_filename}.orig"
131 132
    cp ${_filename}{,.orig} && echo OK.
else
133
    echo "Warning: missing ${_filename}"
134
fi
135

136
# Unzip slapos.tar.gz
137 138
_filename=/opt/downloads/slapos.tar.gz
if [[ -r ${_filename} ]] ; then
139
    echo "Extracting ${_filename} ..."
140 141 142
    (cd /opt ; tar xzf ${_filename} --no-same-owner) || show_error_exit
    echo OK.
elif [[ ! -d /opt/slapos ]] ; then
143
    echo "Warning: missing ${_filename}"
144 145
fi

146 147 148
# Patch cygport, so that we can specify package prefix by ourself.
_filename=/usr/bin/cygport
if [[ -f ${_filename} ]] ; then
149
    echo "Patching ${_filename} ..."
150 151 152
    sed -i -e 's/D="${workdir}\/inst"/D="${CYGCONF_PREFIX-${workdir}\/inst}"/g' ${_filename} &&
    echo OK.
fi
153 154
_filename=/usr/share/cygport/cygclass/autotools.cygclass
if [[ -f ${_filename} ]] ; then
155
    echo "Patching ${_filename} ..."
156 157 158 159 160
    sed -i -e 's/prefix=$(__host_prefix)/prefix=${CYGCONF_PREFIX-$(__host_prefix)}/g' ${_filename} &&
    echo OK.
fi
_filename=/usr/share/cygport/cygclass/cmake.cygclass
if [[ -f ${_filename} ]] ; then
161
    echo "Patching ${_filename} ..."
162 163 164 165
    sed -i -e 's/-DCMAKE_INSTALL_PREFIX=$(__host_prefix)/-DCMAKE_INSTALL_PREFIX=${CYGCONF_PREFIX-$(__host_prefix)}/g' ${_filename} &&
    echo OK.
fi

166 167 168 169 170 171 172
# Set prefix for slapos
if [[ -n ${slapos_prefix} ]] ; then
    echo "Set slapos prefix as ${slapos_prefix}"
    sed -i -e "s%slapos_prefix=.*\$%slapos_prefix=${slapos_prefix}" \
        /etc/slapos/scripts/pre-uninstall.sh /etc/slapos/scripts/slapos-include.sh
fi

173
echo
174
echo "Run post-install.sh script successfully."
175
echo
176
read -n 1 -t 60 -p "Press any key to exit..."
177
exit 0