post-install.sh 3.15 KB
Newer Older
1 2 3 4 5
#! /bin/bash
#
# When cygwin is installed, then call this script by Administrator:
#
#    /bin/bash/ --login -i init-cygwin.sh
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 19 20 21 22 23
#
function show_error_exit()
{
    echo Error: $1
    read -n 1 -p "Press any key to exit..."
    exit 1
}

24 25 26 27
password_filename=/etc/passwd
echo Checking passwd file ...
if [[ ! -f $password_filename ]] ; then
    echo No passwd file found.
28
    mkpasswd -l > $password_filename || show_error_exit "mkpasswd failed"
29 30 31
    echo Generate passwd file OK.
else
    echo Check passwd file OK.
32 33
fi

34 35 36
echo Checking group file ...
if [[ ! -f /etc/group ]] ; then
    echo No group file found.
37
    mkgroup -l > /etc/group || show_error_exit "mkgroup failed"
38
    echo Generate group file OK.
39
else
40
    echo Check group file OK.
41 42
fi

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

54 55
DEFAULT_SYSTEM_CHARSET=$(python -c 'import sys; print sys.getfilesystemencoding()') ||
DEFAULT_SYSTEM_CHARSET=""
56
if [[ ! -f ~/.minttyrc ]] ; then
57
    echo Creating ~/.minttyrc
58 59 60 61 62
    cat <<EOF > ~/.minttyrc
BoldAsFont=no
Font=Courier New
FontHeight=16
Scrollbar=none
63 64
Locale=C
Charset=${DEFAULT_SYSTEM_CHARSET}
65
EOF
66
    echo File ~/.minttyrc created
67 68 69
fi

if [[ ! -f /cygtty.bat ]] ; then
70
    echo Creating /cygtty.bat
71 72 73 74 75 76 77 78 79 80
    cyghome=$(cygpath -w /)
    cat <<EOF > /cygtty.bat
@echo off

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

start mintty.exe -i /Cygwin-Terminal.ico -
EOF
    chmod +x /cygtty.bat
81
    echo File /cygtty.bat created.
82 83
fi

84
# Copy rebaseall.bat to /
85 86
if [[ ! -f /autorebase.bat ]] ; then
    echo Create /autorebase.bat
87
    cat <<EOF > /autorebase.bat
88 89 90 91 92 93 94 95
@echo off
rem Postinstall scripts are always started from the Cygwin root dir
rem so we can just call dash from here
path .\bin;%path%
dash /bin/rebaseall -p
EOF
    chmod +x /autorebase.bat
    echo /autorebase.bat created.
96 97
fi

98 99 100 101
# Change format of readme.txt
readme_filepath=$(cygpath -m /)/..
if [[ -f $readme_filepath/Readme.txt ]] ; then
    unix2dos $readme_filepath/Readme.txt
102
    echo Change readme.txt to dos format OK.
103 104
fi

105 106 107 108 109
# Remove cygwin services to be sure these services will be configured
# in this cygwin enviroments when there are many cygwin instances
# installed in this computer.
for x in $(cygrunsrv --list) ; do
    echo Removing cygservice $x
110
    cygrunsrv -R $x
111 112
done

113 114 115
# Backup slap-runner.html
cp /etc/slapos/scripts/slap-runner.html{,.orig}

116 117 118 119 120 121 122 123 124
# Unzip slapos.tar.gz
if [[ -r /opt/downloads/slapos.tar.gz ]] ; then
    echo Extracting slapos.tar.gz
    cd /opt
    tar xzf /opt/downloads/slapos.tar.gz --no-same-owner ||
    show_error_exit "Failed to untar slapos.tar.gz"
    echo Extracte slapos.tar.gz OK.
fi

125
echo Run post-install script successfully.
126
read -n 1 -t 60 -p "Press any key to exit..."
127
exit 0