File: functions

package info (click to toggle)
crosshurd 1.7.51
  • links: PTS
  • area: main
  • in suites: stretch
  • size: 172 kB
  • sloc: sh: 426; makefile: 2
file content (209 lines) | stat: -rw-r--r-- 6,192 bytes parent folder | download | duplicates (3)
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209

case $DEB_TARGET_GNU_SYSTEM in
  linux-gnu) DEB_TARGET_GNU_TYPE="$DEB_TARGET_GNU_CPU-linux" ;;
  *) DEB_TARGET_GNU_TYPE="$DEB_TARGET_GNU_CPU-$DEB_TARGET_GNU_SYSTEM" ;;
esac
DEB_TARGET_ARCH=`dpkg-architecture -t$DEB_TARGET_GNU_TYPE -qDEB_HOST_ARCH`

apt_options="--option Dir::Etc::SourceList=/etc/crosshurd/sources.list/$DEB_TARGET_GNU_SYSTEM --option Dir::State::Lists=$TARGET/var/cache/apt/lists --option Debug::Nolocking=true --option APT::Architecture=$DEB_TARGET_ARCH --option APT::Architectures=$DEB_TARGET_ARCH --option Dir::Cache::archives=$TARGET/var/cache/apt/archives --option APT::Get::Force-Yes=true --option APT::Get::Download-Only=true --option Dir::State::status=$TARGET/var/lib/dpkg/status --option Dir::Etc::Preferences=/etc/crosshurd/preferences --option debug::pkgproblemresolver=1 --option Dir::Etc::Sourceparts=/nonexistant"

DEBFOR=apt_debfor

target_setup () {
  mkdir -p $TARGET/var/lib/dpkg
  : >"$TARGET/var/lib/dpkg/status"
  : >"$TARGET/var/lib/dpkg/available"

  mkdir -p "$TARGET/var/cache/apt/lists/partial"
  mkdir -p "$TARGET/var/cache/apt/archives/partial"

  rm "$TARGET/var/lib/dpkg/status"
  touch "$TARGET/var/lib/dpkg/status"

}

apt_setup () {

  apt-get $apt_options update
  retval=$?
  sync

}

apt_fetch_deb () {
  apt-get $apt_options --download-only -y install $@
  retval=$?
  sync
}

extract () { (
  cd "$TARGET"
  local p=0
  for pkg in $(debfor "$@"); do
    p="$(($p + 1))"
    progress "$p" "$#" "Extracting packages"
    info "Extracting $pkg..."
    dpkg-deb --extract ./$pkg .
  done
  sync
); }

debfor () {
    "$DEBFOR" "$@"
}
                                                                                
apt_debfor () {
  for p in "$@"; do (
    cd "$TARGET/var/cache/apt/archives"
    local chk=0
    for x in ${p}_*_*.deb; do
      if [ -e "$x" ]; then
        echo "/var/cache/apt/archives/$x"
        chk=1
      fi
    done
    if [ "$chk" = 0 ]; then return 1; fi
  ); done
}

x_feign_install () {
        local pkg="$1"
        local deb="$(debfor $pkg)"
        local ver="$(dpkg-deb --field "$TARGET/$deb" Version)"
 
        mkdir -p "$TARGET/var/lib/dpkg/info"
 
        echo \
"Package: $pkg
Version: $ver
Status: install ok installed
" >> "$TARGET/var/lib/dpkg/status"
                                                                                
        touch "$TARGET/var/lib/dpkg/info/${pkg}.list"
}
 
progress () {
  if [ "$USE_BOOTFLOPPIES_INTERACTION" ]; then
    PROGRESS_NOW="$1"
    PROGRESS_END="$2"
    PROGRESS_WHAT="$3"
    PROGRESS_NEXT=""
    echo "P: $1 $2 $3" >&3
  fi
}

info () {
  if [ "$USE_BOOTFLOPPIES_INTERACTION" ]; then
    echo "I: $1" >&3
  else
    echo "I: $1"
  fi
}

setup_etc () {
  mkdir -p "$TARGET/etc"

  echo 'nameserver 127.0.0.1' > $TARGET/etc/resolv.conf
  echo debian > $TARGET/etc/hostname

  mkdir -p "$TARGET/etc/apt/"

  #FIXME This shouldn't overwrite an existing sources.list
  #but conditional_cp doesn't handle the change of pathname
  cp /etc/crosshurd/sources.list/$DEB_TARGET_GNU_SYSTEM "$TARGET/etc/apt/sources.list"
}

conditional_cp () {
  if [ ! -e "$2/$1" -a -e "$1" ]; then cp -a "$1" "$2/$1"; fi
}

x_core_install () {
  for pkg in $@; do
    smallyes '' | (cd "$TARGET" && /usr/share/crosshurd/dpkg-hurd --unpack "$TARGET"/$(debfor "$pkg"))
  done
}

smallyes() {
  YES="${1-y}"
  while echo "$YES" ; do : ; done
}

gnu_set_server () {
  SERVER=$1
  OWNER=$2
  PERMS=$3
  VALUE=$4
  cd $TARGET/servers
  if [ ! -e $SERVER ] ; then
    touch $SERVER
    chown $OWNER:$OWNER $SERVER
    chmod $PERMS $SERVER
    setfattr -n gnu.translator -v "$VALUE" $SERVER
  fi
}
    
gnu_set_dev () {
  DEV_NODE=$1
  OWNER=$2
  PERMS=$3
  VALUE=$4 
  cd $TARGET/dev
  if [ ! -e $DEV_NODE ] ; then
    touch $DEV_NODE
    chown $OWNER:$OWNER $DEV_NODE
    chmod $PERMS $DEV_NODE
    setfattr -n gnu.translator -v "$VALUE" $DEV_NODE
    if [ $DEV_NODE = "fd" ] ; then
      ln -f -s fd/0 stdin
      ln -f -s fd/1 stdout
      ln -f -s fd/2 stderr
    fi
  fi  
}
  
gnu_setup_passive_translators () {
  if [ ! -e $TARGET/servers/exec ] ; then
    return 2
  else
    setfattr -n gnu.translator -v "/hurd/exec\0" $TARGET/servers/exec 2> /dev/null || return 1
  fi
  info "Setting up passive translators..."
  gnu_set_server socket/1 root 666 "/hurd/pflocal\0"
  gnu_set_server socket/2 root 666 "/hurd/pfinet\0"
  gnu_set_server crash-suspend root 666 "/hurd/crash\0--suspend\0"
  gnu_set_server crash-dump-core root 666 "/hurd/crash\0--dump-core\0"
  gnu_set_server crash-kill root 666 "/hurd/crash\0--kill\0"
  gnu_set_server password root 666 "/hurd/password\0"
  gnu_set_server default-pager root 666 "/hurd/proxy-defpager\0"
  if [ ! -e $TARGET/servers/crash ] ; then
    ln -s crash-suspend $TARGET/servers/crash
  fi
  if [ ! -e $TARGET/servers/socket/local ] ; then
    ln -s 1 $TARGET/servers/socket/local
  fi
  if [ ! -e $TARGET/servers/socket/inet ] ; then
    ln -s 2 $TARGET/servers/socket/inet
  fi
  gnu_set_dev fd root 666 "/hurd/magic\0--directory\0fd\0"
  gnu_set_dev console root 600 "/hurd/term\0/dev/console\0device\0console\0"
  gnu_set_dev tty root 666 "/hurd/magic\0tty\0"
  gnu_set_dev null root 666 "/hurd/null\0"
  gnu_set_dev zero root 666 "/hurd/storeio\0-Tzero\0"
  gnu_set_dev full root 666 "/hurd/null\0--full\0"
  gnu_set_dev time root 644 "/hurd/storeio\0--no-cache\0time\0"
  gnu_set_dev mem root 660 "/hurd/storeio\0--no-cache\0mem\0"
  gnu_set_dev klog root 660 "/hurd/streamio\0kmsg\0"
  gnu_set_dev shm root 644 "/hurd/tmpfs\0--mode=1777\00050%\0"
  for J in 0 1 2 3 4 5 6 7 8 9 a b c d e f g h i j k l m n o p q r s t u v; do
    gnu_set_dev ptyp$J root 666 "/hurd/term\0/dev/ptyp$J\0pty-master\0/dev/ttyp$J\0"
    gnu_set_dev ttyp$J root 666 "/hurd/term\0/dev/ttyp$J\0pty-slave\0/dev/ptyp$J\0"
  done
  for J in 0 1 2 3 4 5 6 7 8 9 a b c d e f g h i j k l m n o p q r s t u v; do
    gnu_set_dev ptyq$J root 666 "/hurd/term\0/dev/ptyq$J\0pty-master\0/dev/ttyq$J\0"
    gnu_set_dev ttyq$J root 666 "/hurd/term\0/dev/ttyq$J\0pty-slave\0/dev/ptyq$J\0"
  done
  gnu_set_dev vcs root 600 "/hurd/console\0"
  for I in 1 2 3 4 5 6; do
    gnu_set_dev tty$I root 600 "/hurd/term\0/dev/tty$I\0hurdio\0/dev/vcs/$I/console\0"
  done
}