95 lines
2.3 KiB
Bash
Executable File
95 lines
2.3 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# mp-migrate | MatterLinux package migration script
|
|
# MatterLinux 2023-2024 (https://matterlinux.xyz)
|
|
|
|
# This program is free software: you can redistribute it and/or modify
|
|
# it under the terms of the GNU General Public License as published by
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
# (at your option) any later version.
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
# GNU General Public License for more details.
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
#############################
|
|
## import common functions ##
|
|
#############################
|
|
location="$(dirname "${0}")"
|
|
location="$(realpath "${location}")"
|
|
commonsh="$(echo "${location}" | sed 's/\/bin/\/lib/g')/mtsc-common.sh"
|
|
|
|
source "${commonsh}"
|
|
|
|
if [ "${?}" != "0" ]; then
|
|
echo "Failed to import mtsc-common"
|
|
exit 1
|
|
fi
|
|
|
|
#################
|
|
## main script ##
|
|
#################
|
|
if [ -z "$1" ]; then
|
|
error "Please specify a package directory"
|
|
exit 1
|
|
fi
|
|
|
|
if [ ! -d "$1" ]; then
|
|
error "Failed to access to the specified directory"
|
|
exit 1
|
|
fi
|
|
|
|
target="$(realpath "${1}")"
|
|
pkg_script="${target}/pkg.sh"
|
|
install_script="${target}/install.sh"
|
|
|
|
if [ ! -f "${pkg_script}" ]; then
|
|
error "Specified directory does not contain a package script (pkg.sh)"
|
|
exit 1
|
|
fi
|
|
|
|
info "Sourcing the package script"
|
|
source "${pkg_script}"
|
|
|
|
if [ -z "${VERSION}" ]; then
|
|
error "Required package variable \"\$VERSION\" is not set"
|
|
exit 1
|
|
fi
|
|
|
|
info "Auto generating the changes file"
|
|
cat > "${target}/changes.md" << EOF
|
|
# ${VERSION}
|
|
First version
|
|
EOF
|
|
|
|
info "Adding the gitignore file"
|
|
cat > "${target}/.gitignore" << EOF
|
|
.cache/
|
|
dist/
|
|
root/
|
|
EOF
|
|
|
|
sed -i 's/build() {/PACKAGE() {/' "${pkg_script}"
|
|
check_ret "Failed to update the build function"
|
|
|
|
if [ -f "${install_script}" ]; then
|
|
info "Migrating the install script"
|
|
echo >> "${pkg_script}"
|
|
echo "INSTALL(){" >> "${pkg_script}"
|
|
|
|
while read l; do
|
|
echo " ${l}" >> "${pkg_script}"
|
|
done < "${install_script}"
|
|
|
|
echo "}" >> "${pkg_script}"
|
|
|
|
rm "${install_script}"
|
|
check_ret "Failed to remove the install script"
|
|
fi
|
|
|
|
success "Migration is completed"
|