summaryrefslogtreecommitdiffstats
path: root/build_tools/larch7/cachepacs
blob: 3e4a1fbc1c0070aedd1739b2f664f93d52c6c207 (plain)
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
#! /bin/bash
#
# cachepacs -  install pkgs to cache dir, but don't isntall
#
# Author: James Meyer  (based on inpacs)


# Working directory:
TMPDIR=/tmp/inpacs$$
# File containing (filtered) list of base packages + added packages
basepacks=${TMPDIR}/basepacks

APP="$( basename $0 )"

exitfunc () {
    # Remove temporary files
    rm -rf ${TMPDIR}
    exit $1
}

# Default pacman db path (this is a statement, not a configuration, so
# do not change it!)
DBPATH="/var/lib/pacman"

# Default package cache, on the target
TARGETCACHE="${CACHE}"
# A host or remote package cache:
HOSTCACHE=""
# Absolute /path/to/file containing list of packages for 2nd install phase:
ADDEDPACKS=""
# Source file for base package list:
BASEPACKSFILE=""
# Source file for list of vetoed base packages:
VETOFILE=""
# Source directory for pacman database directories:
DBDIR=""
# pacman executable:
PACMANX="pacman -f"
# pacman configuration file
PACMANK="/etc/pacman.conf"

checkfile ()
{
    f=$( readlink -m $1 )
    if ! [ -f "${f}" ]; then
        echo "ERROR: File doesn't exist: ${f}"
        exitfunc
    fi
}

checkdir ()
{
    f=$( readlink -m $1 )
    if ! [ -d "${f}" ]; then
        echo "ERROR: Directory doesn't exist: ${f}"
        exitfunc
    fi
}


while getopts ":k:a:c:b:x:y:P:" Option
do
  case ${Option} in
    k ) checkfile ${OPTARG}
        PACMANK=${f} ;;
    a ) checkfile ${OPTARG}
        CACHEPACKSFILE=${f} ;;
    y ) checkdir ${OPTARG}
        DBDIR=${f} ;;
    P ) checkfile ${OPTARG}
        PACMANX=${f} ;;
    #* ) usage ;;
  esac
done
shift $((${OPTIND} - 1))
INSTLDIR="$1"


# grep the cachedir out of the installed pacman.conf
PCCACHE=`grep CacheDir $INSTLDIR/etc/pacman.conf|cut -d= -f2|cut -d\/ -f2-`
CACHEDIR=${INSTLDIR}/$PCCACHE

echo "INSTLDIR=${INSTLDIR}"
echo "PACMANK=${PACMANK}"
echo "CACHEDIR=${CACHEDIR}"
echo "DBDIR=${DBDIR}"
echo "PACMANX=${PACMANX}"
echo


# test if the script is started by root user. If not, exit
if [ $UID -ne 0 ]; then
    echo "Only root can run ${APP}"; exitfunc 1
fi

echo "//"
echo "// downloading  packages to  ${CACHEDIR}"

PACMAN="${PACMANX} --config ${PACMANK} --noconfirm"

rm -rf ${TMPDIR}
mkdir -p ${TMPDIR}

# Helper function for installing a list of packages
doInstall() {
    mkdir -p ${INSTLDIR}/sys
    mkdir -p ${INSTLDIR}/proc
    mount --bind /sys ${INSTLDIR}/sys
    mount --bind /proc ${INSTLDIR}/proc
     ${PACMAN} -r ${INSTLDIR} -Sw  $1
     RET=$?
     echo $RET
    umount ${INSTLDIR}/proc
    umount ${INSTLDIR}/sys
    if [ ${RET} -ne 0 ]; then
        echo "//"
        echo "// cachepacks package $1 FAILED."
        echo "//"
        return 1
    fi
}


PACMAN="${PACMAN} --cachedir $CACHEDIR"

########## GET LIST OF CACHE PACKAGES
echo "//"
echo "// ** Getting cache package list ..."
if [ -n "${CACHEPACKSFILE}" ]; then
    echo "//    from: ${CACHEPACKSFILE}"
    CACHEPKGS=$( cat ${CACHEPACKSFILE} | grep -v "#" )
else
    echo " no cache package file found"
    exit 0
fi


doInstall "${CACHEPKGS}"
if [ $? -ne 0 ]; then exitfunc 1; fi
exitfunc